Merge lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-split-sale-lep into lp:banking-addons/bank-statement-reconcile-70

Proposed by Leonardo Pistone
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 112
Merged at revision: 110
Proposed branch: lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-split-sale-lep
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 344 lines (+227/-51)
8 files modified
account_statement_base_completion/__openerp__.py (+0/-1)
account_statement_base_completion/data.xml (+0/-6)
account_statement_base_completion/statement.py (+0/-44)
account_statement_so_completion/__init__.py (+25/-0)
account_statement_so_completion/__openerp__.py (+52/-0)
account_statement_so_completion/data.xml (+12/-0)
account_statement_so_completion/statement.py (+94/-0)
account_statement_so_completion/test/completion_so_test.yml (+44/-0)
To merge this branch: bzr merge lp:~camptocamp/banking-addons/bank-statement-reconcile-7.0-split-sale-lep
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no tests Approve
Joël Grand-Guillaume @ camptocamp code review, no tests Approve
Review via email: mp+197544@code.launchpad.net

Commit message

[mrg] split the module account_statement_base_completion to take out what depends on sale

Description of the change

Here I split the module account_statement_base_completion to take out what depends on sale.

To post a comment you must log in.
106. By Leonardo Pistone

auto_install account_statement_so_completion

Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi Leonardo,

Thanks for this extract, looks good to me !

Regards,

review: Approve (code review, no tests)
107. By Leonardo Pistone

[fix] selection value

108. By Leonardo Pistone

[mrg] upstream

109. By Leonardo Pistone

[mrg] upstream

110. By Leonardo Pistone

[add] account_statement_so_completion/test

111. By Leonardo Pistone

[fix] function in the wrong place

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks Joël for your review.

I added a YAML test and fixed a bug that the test showed.

The test passes if the following two MP are merged:

* https://code.launchpad.net/~camptocamp/banking-addons/bank-statement-reconcile-7.0-fix-onchange-lep/+merge/199518
* https://code.launchpad.net/~camptocamp/banking-addons/bank-statement-reconcile-7.0-fix-yaml-related-lep/+merge/199124

They are approved already, so that should be no problem.

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

in account_statement_so_completion/__openerp__.py

l169-172
Please use 'data' keyword

review: Needs Fixing (code review, no tests)
112. By Leonardo Pistone

[imp] manifest: data

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Fixed, thanks

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks

review: Approve (code review, no tests)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_statement_base_completion/__openerp__.py'
2--- account_statement_base_completion/__openerp__.py 2013-04-05 07:52:53 +0000
3+++ account_statement_base_completion/__openerp__.py 2014-01-16 10:35:50 +0000
4@@ -35,7 +35,6 @@
5
6 1) Match from statement line label (based on partner field 'Bank Statement Label')
7 2) Match from statement line label (based on partner name)
8- 3) Match from statement line reference (based on SO number)
9 3) Match from statement line reference (based on Invoice number)
10
11 You can easily override this module and add your own rules in your own one. The basic rules only
12
13=== modified file 'account_statement_base_completion/data.xml'
14--- account_statement_base_completion/data.xml 2013-04-24 09:30:08 +0000
15+++ account_statement_base_completion/data.xml 2014-01-16 10:35:50 +0000
16@@ -14,12 +14,6 @@
17 <field name="function_to_call">get_from_label_and_partner_name</field>
18 </record>
19
20- <record id="bank_statement_completion_rule_1" model="account.statement.completion.rule">
21- <field name="name">Match from line reference (based on SO number)</field>
22- <field name="sequence">50</field>
23- <field name="function_to_call">get_from_ref_and_so</field>
24- </record>
25-
26 <record id="bank_statement_completion_rule_4" model="account.statement.completion.rule">
27 <field name="name">Match from line reference (based on Invoice number)</field>
28 <field name="sequence">40</field>
29
30=== modified file 'account_statement_base_completion/statement.py'
31--- account_statement_base_completion/statement.py 2013-10-16 08:58:12 +0000
32+++ account_statement_base_completion/statement.py 2014-01-16 10:35:50 +0000
33@@ -132,7 +132,6 @@
34 return [
35 ('get_from_ref_and_invoice', 'From line reference (based on customer invoice number)'),
36 ('get_from_ref_and_supplier_invoice', 'From line reference (based on supplier invoice number)'),
37- ('get_from_ref_and_so', 'From line reference (based on SO number)'),
38 ('get_from_label_and_partner_field', 'From line label (based on partner field)'),
39 ('get_from_label_and_partner_name', 'From line label (based on partner name)')]
40
41@@ -233,49 +232,6 @@
42 return self._from_invoice(cr, uid, line, 'customer', context=context)
43
44 # Should be private but data are initialised with no update XML
45- def get_from_ref_and_so(self, cr, uid, st_line, context=None):
46- """
47- Match the partner based on the SO number and the reference of the statement
48- line. Then, call the generic get_values_for_line method to complete other values.
49- If more than one partner matched, raise the ErrorTooManyPartner error.
50-
51- :param int/long st_line: read of the concerned account.bank.statement.line
52- :return:
53- A dict of value that can be passed directly to the write method of
54- the statement line or {}
55- {'partner_id': value,
56- 'account_id': value,
57-
58- ...}
59- """
60- st_obj = self.pool.get('account.bank.statement.line')
61- res = {}
62- if st_line:
63- so_obj = self.pool.get('sale.order')
64- so_id = so_obj.search(cr,
65- uid,
66- [('name', '=', st_line['ref'])],
67- context=context)
68- if so_id:
69- if so_id and len(so_id) == 1:
70- so = so_obj.browse(cr, uid, so_id[0], context=context)
71- res['partner_id'] = so.partner_id.id
72- elif so_id and len(so_id) > 1:
73- raise ErrorTooManyPartner(_('Line named "%s" (Ref:%s) was matched by more '
74- 'than one partner while looking on SO by ref.') %
75- (st_line['name'], st_line['ref']))
76- st_vals = st_obj.get_values_for_line(cr,
77- uid,
78- profile_id=st_line['profile_id'],
79- master_account_id=st_line['master_account_id'],
80- partner_id=res.get('partner_id', False),
81- line_type='customer',
82- amount=st_line['amount'] if st_line['amount'] else 0.0,
83- context=context)
84- res.update(st_vals)
85- return res
86-
87- # Should be private but data are initialised with no update XML
88 def get_from_label_and_partner_field(self, cr, uid, st_line, context=None):
89 """
90 Match the partner based on the label field of the statement line
91
92=== added directory 'account_statement_so_completion'
93=== added file 'account_statement_so_completion/__init__.py'
94--- account_statement_so_completion/__init__.py 1970-01-01 00:00:00 +0000
95+++ account_statement_so_completion/__init__.py 2014-01-16 10:35:50 +0000
96@@ -0,0 +1,25 @@
97+# -*- coding: utf-8 -*-
98+###############################################################################
99+# #
100+# Author: Joel Grand-Guillaume
101+# Copyright 2011-2012 Camptocamp SA
102+# #
103+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
104+# Copyright 2013 Camptocamp SA #
105+# #
106+# This program is free software: you can redistribute it and/or modify #
107+# it under the terms of the GNU Affero General Public License as #
108+# published by the Free Software Foundation, either version 3 of the #
109+# License, or (at your option) any later version. #
110+# #
111+# This program is distributed in the hope that it will be useful, #
112+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
113+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
114+# GNU Affero General Public License for more details. #
115+# #
116+# You should have received a copy of the GNU Affero General Public License #
117+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
118+# #
119+###############################################################################
120+
121+from . import statement
122
123=== added file 'account_statement_so_completion/__openerp__.py'
124--- account_statement_so_completion/__openerp__.py 1970-01-01 00:00:00 +0000
125+++ account_statement_so_completion/__openerp__.py 2014-01-16 10:35:50 +0000
126@@ -0,0 +1,52 @@
127+# -*- coding: utf-8 -*-
128+###############################################################################
129+# #
130+# Author: Joel Grand-Guillaume
131+# Copyright 2011-2012 Camptocamp SA
132+# #
133+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
134+# Copyright 2013 Camptocamp SA #
135+# #
136+# This program is free software: you can redistribute it and/or modify #
137+# it under the terms of the GNU Affero General Public License as #
138+# published by the Free Software Foundation, either version 3 of the #
139+# License, or (at your option) any later version. #
140+# #
141+# This program is distributed in the hope that it will be useful, #
142+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
143+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
144+# GNU Affero General Public License for more details. #
145+# #
146+# You should have received a copy of the GNU Affero General Public License #
147+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
148+# #
149+###############################################################################
150+
151+{'name': "Bank statement Sale Order completion",
152+ 'version': '0.1',
153+ 'author': 'Camptocamp',
154+ 'maintainer': 'Camptocamp',
155+ 'category': 'Finance',
156+ 'complexity': 'easy',
157+ 'depends': ['account_statement_base_completion', 'sale'],
158+ 'description': """
159+ This module improve the module account_statement_base_completion to add
160+ support for completion rules based on Sale Orders. This was initially part of
161+ the module account_statement_base_completion, but is now separate to keep
162+ dependencies separate.
163+
164+ This module provides the following rule:
165+
166+ 1) Match from statement line reference (based on SO number)
167+""",
168+ 'website': 'http://www.camptocamp.com',
169+ 'data': [
170+ 'data.xml',
171+ ],
172+ 'test': [
173+ 'test/completion_so_test.yml'],
174+ 'installable': True,
175+ 'images': [],
176+ 'auto_install': True,
177+ 'license': 'AGPL-3',
178+ }
179
180=== added file 'account_statement_so_completion/data.xml'
181--- account_statement_so_completion/data.xml 1970-01-01 00:00:00 +0000
182+++ account_statement_so_completion/data.xml 2014-01-16 10:35:50 +0000
183@@ -0,0 +1,12 @@
184+<?xml version="1.0" encoding="utf-8"?>
185+<openerp>
186+ <data noupdate="1">
187+
188+ <record id="bank_statement_completion_rule_1" model="account.statement.completion.rule">
189+ <field name="name">Match from line reference (based on SO number)</field>
190+ <field name="sequence">50</field>
191+ <field name="function_to_call">get_from_ref_and_so</field>
192+ </record>
193+
194+ </data>
195+</openerp>
196
197=== added file 'account_statement_so_completion/statement.py'
198--- account_statement_so_completion/statement.py 1970-01-01 00:00:00 +0000
199+++ account_statement_so_completion/statement.py 2014-01-16 10:35:50 +0000
200@@ -0,0 +1,94 @@
201+# -*- coding: utf-8 -*-
202+###############################################################################
203+# #
204+# Author: Joel Grand-Guillaume #
205+# Copyright 2011-2012 Camptocamp SA #
206+# #
207+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
208+# Copyright 2013 Camptocamp SA #
209+# #
210+# This program is free software: you can redistribute it and/or modify #
211+# it under the terms of the GNU Affero General Public License as #
212+# published by the Free Software Foundation, either version 3 of the #
213+# License, or (at your option) any later version. #
214+# #
215+# This program is distributed in the hope that it will be useful, #
216+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
217+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
218+# GNU Affero General Public License for more details. #
219+# #
220+# You should have received a copy of the GNU Affero General Public License #
221+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
222+# #
223+###############################################################################
224+
225+from openerp.osv import fields, orm
226+from tools.translate import _
227+
228+from openerp.addons.account_statement_base_completion.statement import ErrorTooManyPartner
229+
230+
231+class account_statement_completion_rule(orm.Model):
232+
233+ _name = "account.statement.completion.rule"
234+ _inherit = "account.statement.completion.rule"
235+
236+ def _get_functions(self, cr, uid, context=None):
237+ res = super(account_statement_completion_rule, self)._get_functions(
238+ cr, uid, context=context)
239+ res.append(
240+ ('get_from_ref_and_so', 'From line reference (based on SO number)')
241+ )
242+ return res
243+
244+ # Should be private but data are initialised with no update XML
245+ def get_from_ref_and_so(self, cr, uid, st_line, context=None):
246+ """
247+ Match the partner based on the SO number and the reference of the
248+ statement line. Then, call the generic get_values_for_line method to
249+ complete other values. If more than one partner matched, raise the
250+ ErrorTooManyPartner error.
251+
252+ :param int/long st_line: read of the concerned
253+ account.bank.statement.line
254+
255+ :return:
256+ A dict of value that can be passed directly to the write method of
257+ the statement line or {}
258+ {'partner_id': value,
259+ 'account_id': value,
260+
261+ ...}
262+ """
263+ st_obj = self.pool.get('account.bank.statement.line')
264+ res = {}
265+ if st_line:
266+ so_obj = self.pool.get('sale.order')
267+ so_id = so_obj.search(cr,
268+ uid,
269+ [('name', '=', st_line['ref'])],
270+ context=context)
271+ if so_id:
272+ if so_id and len(so_id) == 1:
273+ so = so_obj.browse(cr, uid, so_id[0], context=context)
274+ res['partner_id'] = so.partner_id.id
275+ elif so_id and len(so_id) > 1:
276+ raise ErrorTooManyPartner(
277+ _('Line named "%s" (Ref:%s) was matched by more '
278+ 'than one partner while looking on SO by ref.') %
279+ (st_line['name'], st_line['ref']))
280+ st_vals = st_obj.get_values_for_line(
281+ cr,
282+ uid,
283+ profile_id=st_line['profile_id'],
284+ master_account_id=st_line['master_account_id'],
285+ partner_id=res.get('partner_id', False),
286+ line_type='customer',
287+ amount=st_line['amount'] if st_line['amount'] else 0.0,
288+ context=context)
289+ res.update(st_vals)
290+ return res
291+
292+ _columns = {
293+ 'function_to_call': fields.selection(_get_functions, 'Method'),
294+ }
295
296=== added directory 'account_statement_so_completion/test'
297=== added file 'account_statement_so_completion/test/completion_so_test.yml'
298--- account_statement_so_completion/test/completion_so_test.yml 1970-01-01 00:00:00 +0000
299+++ account_statement_so_completion/test/completion_so_test.yml 2014-01-16 10:35:50 +0000
300@@ -0,0 +1,44 @@
301+-
302+ In order to test the banking framework for Sale Orders, I first need to
303+ create a profile
304+-
305+ !record {model: account.statement.profile, id: profile_test_so}:
306+ name: Bank EUR Profile for SO
307+ journal_id: account.bank_journal
308+ commission_account_id: account.a_expense
309+ company_id: base.main_company
310+ balance_check: True
311+ rule_ids:
312+ - account_statement_base_completion.bank_statement_completion_rule_4
313+ - account_statement_base_completion.bank_statement_completion_rule_5
314+ - account_statement_base_completion.bank_statement_completion_rule_2
315+ - account_statement_base_completion.bank_statement_completion_rule_3
316+ - bank_statement_completion_rule_1
317+-
318+ Now I create a statement. I create statment lines separately because I need
319+ to find each one by XML id
320+-
321+ !record {model: account.bank.statement, id: statement_test_sale1}:
322+ name: Statement for SO
323+ profile_id: profile_test_so
324+ company_id: base.main_company
325+-
326+ I create a statement line for a SO
327+-
328+ !record {model: account.bank.statement.line, id: statement_line_so}:
329+ name: Test autocompletion based on Sale Order Number
330+ statement_id: statement_test_sale1
331+ ref: SO007
332+ date: '2013-12-20'
333+ amount: 14981.0
334+-
335+ I run the auto complete
336+-
337+ !python {model: account.bank.statement}: |
338+ result = self.button_auto_completion(cr, uid, [ref("statement_test_sale1")])
339+-
340+ Now I can check that all is nice and shiny, line 1. I expect the Sale Order
341+ Number to be recognised.
342+-
343+ !assert {model: account.bank.statement.line, id: statement_line_so, string: Check completion by SO number}:
344+ - partner_id.name == u'Luminous Technologies'

Subscribers

People subscribed via source and target branches