Merge lp:~camptocamp/banking-addons/bank-statement-reconcile-70-pos_compat-afe into lp:banking-addons/bank-statement-reconcile-70

Proposed by Alexandre Fayolle - camptocamp
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 107
Merged at revision: 133
Proposed branch: lp:~camptocamp/banking-addons/bank-statement-reconcile-70-pos_compat-afe
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 221 lines (+192/-3)
4 files modified
account_statement_ext/statement.py (+4/-3)
account_statement_ext_point_of_sale/__init__.py (+22/-0)
account_statement_ext_point_of_sale/__openerp__.py (+43/-0)
account_statement_ext_point_of_sale/point_of_sale.py (+123/-0)
To merge this branch: bzr merge lp:~camptocamp/banking-addons/bank-statement-reconcile-70-pos_compat-afe
Reviewer Review Type Date Requested Status
Nicolas Bessi - Camptocamp (community) code review, no test Approve
Yannick Vaucher @ Camptocamp code review, no tests Approve
Review via email: mp+193807@code.launchpad.net

Description of the change

fix issue when creating empty statement (lp:1247876) and add a module which enables bank statement creation from the point of sale with the banking framework installed.

To post a comment you must log in.
104. By Alexandre Fayolle - camptocamp

[FIX] select the correct profile when creating the bank statement

105. By Nicolas Bessi - Camptocamp

[PEP8]

106. By Nicolas Bessi - Camptocamp

[MRG] from upstream, comment added

107. By Nicolas Bessi - Camptocamp

[IMP][PEP8] fixed + add a doc string to explicit fact _prepare_statement does not originally exist on base model

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Hello,

Thanks for the patch.

Fixed some PEP8 and add some comments

Have you tried to propose a patch to add a hook to prepare the statement on official branch. Generally Olivier is quite open to this kind of small enhancement.

Also I will add a explicit message error if no profile found that tells user there is no profile for current journal.

Regards

Nicolas

review: Needs Fixing (no test, code review)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Nicolas should we wait for the hook or can we proceed with this monkey patching?

Alexandre, Nicolas did we ask odony already for a hook in pos_session.create

IMHO as long the MP in addons(1) is not merged we can apply the fix and remove it later

(1)https://code.launchpad.net/~camptocamp/openobject-addons/7.0-fix-1245375-afe/+merge/192848
https://code.launchpad.net/~camptocamp/openobject-addons/trunk-fix-1245375-afe/+merge/192849

Otherwise LGTM

review: Approve (code review, no tests)
Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

I just asked odony and alesuisse for there opinion on lp:1245375 MPs.

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

> I just asked odony and alesuisse for there opinion on lp:1245375 MPs.

answer: not in stable.

note that the code works even if the patch is applied.

Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Well not in stable so LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_statement_ext/statement.py'
2--- account_statement_ext/statement.py 2013-10-16 08:58:12 +0000
3+++ account_statement_ext/statement.py 2013-11-05 07:31:53 +0000
4@@ -31,9 +31,10 @@
5 I will do it when I have time."""
6 res = super(stat_mod.account_bank_statement, self).write(cr, uid, ids,
7 vals, context=context)
8- cr.execute("UPDATE account_bank_statement_line"
9- " SET sequence = account_bank_statement_line.id + 1"
10- " where statement_id in %s", (tuple(ids),))
11+ if ids: # will be false for an new empty bank statement
12+ cr.execute("UPDATE account_bank_statement_line"
13+ " SET sequence = account_bank_statement_line.id + 1"
14+ " where statement_id in %s", (tuple(ids),))
15 return res
16 stat_mod.account_bank_statement.write = fixed_write
17
18
19=== added directory 'account_statement_ext_point_of_sale'
20=== added file 'account_statement_ext_point_of_sale/__init__.py'
21--- account_statement_ext_point_of_sale/__init__.py 1970-01-01 00:00:00 +0000
22+++ account_statement_ext_point_of_sale/__init__.py 2013-11-05 07:31:53 +0000
23@@ -0,0 +1,22 @@
24+# -*- coding: utf-8 -*-
25+##############################################################################
26+#
27+# Author: Alexandre Fayolle
28+# Copyright 2013 Camptocamp SA
29+#
30+# This program is free software: you can redistribute it and/or modify
31+# it under the terms of the GNU Affero General Public License as
32+# published by the Free Software Foundation, either version 3 of the
33+# License, or (at your option) any later version.
34+#
35+# This program is distributed in the hope that it will be useful,
36+# but WITHOUT ANY WARRANTY; without even the implied warranty of
37+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
38+# GNU Affero General Public License for more details.
39+#
40+# You should have received a copy of the GNU Affero General Public License
41+# along with this program. If not, see <http://www.gnu.org/licenses/>.
42+#
43+##############################################################################
44+
45+from . import point_of_sale
46
47=== added file 'account_statement_ext_point_of_sale/__openerp__.py'
48--- account_statement_ext_point_of_sale/__openerp__.py 1970-01-01 00:00:00 +0000
49+++ account_statement_ext_point_of_sale/__openerp__.py 2013-11-05 07:31:53 +0000
50@@ -0,0 +1,43 @@
51+# -*- coding: utf-8 -*-
52+##############################################################################
53+#
54+# Author: Nicolas Bessi, Joel Grand-Guillaume
55+# Copyright 2011-2013 Camptocamp SA
56+#
57+# This program is free software: you can redistribute it and/or modify
58+# it under the terms of the GNU Affero General Public License as
59+# published by the Free Software Foundation, either version 3 of the
60+# License, or (at your option) any later version.
61+#
62+# This program is distributed in the hope that it will be useful,
63+# but WITHOUT ANY WARRANTY; without even the implied warranty of
64+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65+# GNU Affero General Public License for more details.
66+#
67+# You should have received a copy of the GNU Affero General Public License
68+# along with this program. If not, see <http://www.gnu.org/licenses/>.
69+#
70+##############################################################################
71+
72+{'name': "Bank statement extension and profiles for Point of Sale",
73+ 'version': '1.0.0',
74+ 'author': 'Camptocamp',
75+ 'maintainer': 'Camptocamp',
76+ 'category': 'Point Of Sale',
77+ 'complexity': 'normal',
78+ 'depends': ['point_of_sale',
79+ 'account_statement_ext',
80+ ],
81+ 'description': """
82+ Update the point of sale code to work with improved bank statements.
83+ """,
84+ 'website': 'http://www.camptocamp.com',
85+ 'data': [],
86+ 'demo': [],
87+ 'test': [],
88+ 'installable': True,
89+ 'images': [],
90+ 'auto_install': True,
91+ 'license': 'AGPL-3',
92+ 'active': False,
93+ }
94
95=== added file 'account_statement_ext_point_of_sale/point_of_sale.py'
96--- account_statement_ext_point_of_sale/point_of_sale.py 1970-01-01 00:00:00 +0000
97+++ account_statement_ext_point_of_sale/point_of_sale.py 2013-11-05 07:31:53 +0000
98@@ -0,0 +1,123 @@
99+# -*- coding: utf-8 -*-
100+##############################################################################
101+#
102+# Author: Alexandre Fayolle
103+# Copyright 2013 Camptocamp SA
104+#
105+# This program is free software: you can redistribute it and/or modify
106+# it under the terms of the GNU Affero General Public License as
107+# published by the Free Software Foundation, either version 3 of the
108+# License, or (at your option) any later version.
109+#
110+# This program is distributed in the hope that it will be useful,
111+# but WITHOUT ANY WARRANTY; without even the implied warranty of
112+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113+# GNU Affero General Public License for more details.
114+#
115+# You should have received a copy of the GNU Affero General Public License
116+# along with this program. If not, see <http://www.gnu.org/licenses/>.
117+#
118+##############################################################################
119+from openerp.addons.point_of_sale.point_of_sale import pos_session as std_pos_session
120+from openerp.osv import orm, osv
121+from openerp.tools.translate import _
122+
123+if not hasattr(std_pos_session, '_prepare_bank_statement'):
124+ # monkey patch to fix lp:1245375
125+ #
126+ # We replace pos_session.create with the implementation in
127+ # mp_create below which is essentially the same, only with a call
128+ # to self._prepare_bank_statement.
129+ #
130+ # The default implementation has been extracted in
131+ # mp_prepare_bank_statement below, and can be overridden in models
132+ # which _inherit pos.session
133+ #
134+ # This change has been proposed for merging to fix lp:125375
135+ def mp_prepare_bank_statement(self, cr, uid, pos_config, journal, context=None):
136+ bank_values = {
137+ 'journal_id' : journal.id,
138+ 'user_id' : uid,
139+ 'company_id' : pos_config.shop_id.company_id.id
140+ }
141+ return bank_values
142+
143+ def mp_create(self, cr, uid, values, context=None):
144+ context = context or {}
145+ config_id = values.get('config_id', False) or context.get('default_config_id', False)
146+ if not config_id:
147+ raise osv.except_osv( _('Error!'),
148+ _("You should assign a Point of Sale to your session."))
149+
150+ # journal_id is not required on the pos_config because it does not
151+ # exists at the installation. If nothing is configured at the
152+ # installation we do the minimal configuration. Impossible to do in
153+ # the .xml files as the CoA is not yet installed.
154+ jobj = self.pool.get('pos.config')
155+ pos_config = jobj.browse(cr, uid, config_id, context=context)
156+ context.update({'company_id': pos_config.shop_id.company_id.id})
157+ if not pos_config.journal_id:
158+ jid = jobj.default_get(cr, uid, ['journal_id'], context=context)['journal_id']
159+ if jid:
160+ jobj.write(cr, uid, [pos_config.id], {'journal_id': jid}, context=context)
161+ else:
162+ raise osv.except_osv( _('error!'),
163+ _("Unable to open the session. You have to assign a sale journal to your point of sale."))
164+
165+ # define some cash journal if no payment method exists
166+ if not pos_config.journal_ids:
167+ journal_proxy = self.pool.get('account.journal')
168+ cashids = journal_proxy.search(cr, uid, [('journal_user', '=', True), ('type','=','cash')], context=context)
169+ if not cashids:
170+ cashids = journal_proxy.search(cr, uid, [('type', '=', 'cash')], context=context)
171+ if not cashids:
172+ cashids = journal_proxy.search(cr, uid, [('journal_user','=',True)], context=context)
173+
174+ jobj.write(cr, uid, [pos_config.id], {'journal_ids': [(6,0, cashids)]})
175+
176+
177+ pos_config = jobj.browse(cr, uid, config_id, context=context)
178+ bank_statement_ids = []
179+ for journal in pos_config.journal_ids:
180+ bank_values = self._prepare_bank_statement(cr, uid, pos_config, journal, context)
181+ statement_id = self.pool.get('account.bank.statement').create(cr, uid, bank_values, context=context)
182+ bank_statement_ids.append(statement_id)
183+
184+ values.update({
185+ 'name' : pos_config.sequence_id._next(),
186+ 'statement_ids' : [(6, 0, bank_statement_ids)],
187+ 'config_id': config_id
188+ })
189+ return super(std_pos_session, self).create(cr, uid, values, context=context)
190+
191+ std_pos_session._prepare_bank_statement = mp_prepare_bank_statement
192+ std_pos_session.create = mp_create
193+
194+
195+class pos_session(orm.Model):
196+ _inherit = 'pos.session'
197+
198+ def _prepare_bank_statement(self, cr, uid, pos_config, journal, context=None):
199+ """ Override the function _mp_create. To add the bank profile to the statement
200+
201+ Function That was previously added to pos.session model using monkey patching
202+
203+ """
204+
205+ bank_values = super(pos_session, self)._prepare_bank_statement(cr, uid,
206+ pos_config,
207+ journal, context)
208+ user_obj = self.pool.get('res.users')
209+ profile_obj = self.pool.get('account.statement.profile')
210+ user = user_obj.browse(cr, uid, uid, context=context)
211+ defaults = self.pool['account.bank.statement'].default_get(cr, uid,
212+ ['profile_id', 'period_id'],
213+ context=context)
214+ profile_ids = profile_obj.search(cr, uid,
215+ [('company_id', '=', user.company_id.id),
216+ ('journal_id', '=', bank_values['journal_id'])],
217+ context=context)
218+ if profile_ids:
219+ defaults['profile_id'] = profile_ids[0]
220+ bank_values.update(defaults)
221+ return bank_values

Subscribers

People subscribed via source and target branches