Merge lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-bug-1313689-lmi into lp:banking-addons/bank-statement-reconcile-70

Proposed by Laurent Mignon (Acsone)
Status: Merged
Merged at revision: 146
Proposed branch: lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-bug-1313689-lmi
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 185 lines (+137/-11)
4 files modified
account_statement_base_import/data/statement.csv (+1/-1)
account_statement_base_import/statement.py (+4/-10)
account_statement_base_import/tests/__init__.py (+27/-0)
account_statement_base_import/tests/test_base_import.py (+105/-0)
To merge this branch: bzr merge lp:~acsone-openerp/banking-addons/bank-statement-reconcile-70-bug-1313689-lmi
Reviewer Review Type Date Requested Status
Joël Grand-Guillaume @ camptocamp code review + test Approve
Yannick Vaucher @ Camptocamp code review, no test Approve
Guewen Baconnier @ Camptocamp code review Approve
Review via email: mp+217467@code.launchpad.net

Description of the change

Remove the default value to False on account_id in account_statement_base_completion/statement.py since it breaks existing code.

I've the feeling that it's the responsibility of the parser to provide an blank/None account_id if the one provided by the base module 'account_statement_ext' does not apply to the expected behavior.

Regards,

lmi

To post a comment you must log in.
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM,
Thanks

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

LGTM

Thanks for the tests

As a side note for the next time you could use setUp() instead of calling each time prepare.

review: Approve (code review, no test)
Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

Thanks for the review

> As a side note for the next time you could use setUp() instead of calling each
> time prepare.

Definitely

lmi

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

Hi Laurent,

Thanks for this fix and moreover for the test that come with.. This is very much appreciated :)

Now, I see more trouble raised by this trouble. I suggest I already merge this work to move forward and continue discussing the solution in the already fulfill bug report.

Regards,

Joël

review: Approve (code review + test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_statement_base_import/data/statement.csv'
2--- account_statement_base_import/data/statement.csv 2012-07-31 14:29:55 +0000
3+++ account_statement_base_import/data/statement.csv 2014-04-28 15:17:18 +0000
4@@ -1,4 +1,4 @@
5 "ref";"date";"amount";"commission_amount";"label"
6 50969286;2011-03-07 13:45:14;118.4;-11.84;"label a"
7-51065326;2011-03-05 13:45:14;189;-15.12;"label b"
8+51065326;2011-03-02 13:45:14;189;-15.12;"label b"
9 51179306;2011-03-02 17:45:14;189;-15.12;"label c"
10
11=== modified file 'account_statement_base_import/statement.py'
12--- account_statement_base_import/statement.py 2014-04-15 09:52:48 +0000
13+++ account_statement_base_import/statement.py 2014-04-28 15:17:18 +0000
14@@ -109,7 +109,6 @@
15 :param int/long statement_id: ID of the concerned account.bank.statement
16 :return: dict of vals that will be passed to create method of statement line.
17 """
18- statement_obj = self.pool.get('account.bank.statement')
19 statement_line_obj = self.pool['account.bank.statement.line']
20 values = parser_vals
21 values['statement_id'] = statement_id
22@@ -233,16 +232,11 @@
23 raise osv.except_osv(_("Statement import error"),
24 _("The statement cannot be created: %s") % st)
25 return statement_id
26-
27-
28+
29+
30 class AccountBankStatementLine(Model):
31 _inherit = "account.bank.statement.line"
32
33- _columns = {
34- 'account_id': fields.many2one('account.account','Account'),
35- }
36-
37- _defaults = {
38- 'account_id': False,
39+ _columns = {
40+ 'account_id': fields.many2one('account.account', 'Account'),
41 }
42-
43
44=== added directory 'account_statement_base_import/tests'
45=== added file 'account_statement_base_import/tests/__init__.py'
46--- account_statement_base_import/tests/__init__.py 1970-01-01 00:00:00 +0000
47+++ account_statement_base_import/tests/__init__.py 2014-04-28 15:17:18 +0000
48@@ -0,0 +1,27 @@
49+# -*- coding: utf-8 -*-
50+#
51+#
52+# Authors: Laurent Mignon
53+# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
54+# All Rights Reserved
55+#
56+# This program is free software: you can redistribute it and/or modify
57+# it under the terms of the GNU Affero General Public License as
58+# published by the Free Software Foundation, either version 3 of the
59+# License, or (at your option) any later version.
60+#
61+# This program is distributed in the hope that it will be useful,
62+# but WITHOUT ANY WARRANTY; without even the implied warranty of
63+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64+# GNU Affero General Public License for more details.
65+#
66+# You should have received a copy of the GNU Affero General Public License
67+# along with this program. If not, see <http://www.gnu.org/licenses/>.
68+#
69+#
70+
71+from . import test_base_import
72+
73+checks = [
74+ test_base_import
75+]
76
77=== added file 'account_statement_base_import/tests/test_base_import.py'
78--- account_statement_base_import/tests/test_base_import.py 1970-01-01 00:00:00 +0000
79+++ account_statement_base_import/tests/test_base_import.py 2014-04-28 15:17:18 +0000
80@@ -0,0 +1,105 @@
81+# -*- coding: utf-8 -*-
82+#
83+#
84+# Authors: Laurent Mignon
85+# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
86+# All Rights Reserved
87+#
88+# This program is free software: you can redistribute it and/or modify
89+# it under the terms of the GNU Affero General Public License as
90+# published by the Free Software Foundation, either version 3 of the
91+# License, or (at your option) any later version.
92+#
93+# This program is distributed in the hope that it will be useful,
94+# but WITHOUT ANY WARRANTY; without even the implied warranty of
95+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96+# GNU Affero General Public License for more details.
97+#
98+# You should have received a copy of the GNU Affero General Public License
99+# along with this program. If not, see <http://www.gnu.org/licenses/>.
100+#
101+#
102+import base64
103+import inspect
104+import os
105+
106+from openerp.tests import common
107+
108+
109+class test_coda_import(common.TransactionCase):
110+
111+ def prepare(self):
112+ self.company_a = self.browse_ref('base.main_company')
113+ self.profile_obj = self.registry("account.statement.profile")
114+ self.account_bank_statement_obj = self.registry("account.bank.statement")
115+ # create the 2009 fiscal year since imported coda file reference statement lines in 2009
116+ self.fiscalyear_id = self._create_fiscalyear("2011", self.company_a.id)
117+
118+ self.account_id = self.ref("account.a_recv")
119+ self.journal_id = self.ref("account.bank_journal")
120+ self.import_wizard_obj = self.registry('credit.statement.import')
121+ self.profile_id = self.profile_obj.create(self.cr, self.uid, {
122+ "name": "BASE_PROFILE",
123+ "commission_account_id": self.account_id,
124+ "journal_id": self.journal_id,
125+ "import_type": "generic_csvxls_so"})
126+
127+ def _create_fiscalyear(self, year, company_id):
128+ fiscalyear_obj = self.registry("account.fiscalyear")
129+ fiscalyear_id = fiscalyear_obj.create(self.cr, self.uid, {
130+ "name": year,
131+ "code": year,
132+ "date_start": year + "-01-01",
133+ "date_stop": year + "-12-31",
134+ "company_id": company_id
135+ })
136+ fiscalyear_obj.create_period3(self.cr, self.uid, [fiscalyear_id])
137+ return fiscalyear_id
138+
139+ def _filename_to_abs_filename(self, file_name):
140+ dir_name = os.path.dirname(inspect.getfile(self.__class__))
141+ return os.path.join(dir_name, file_name)
142+
143+ def _import_file(self, file_name):
144+ """ import a file using the wizard
145+ return the create account.bank.statement object
146+ """
147+ with open(file_name) as f:
148+ content = f.read()
149+ wizard_id = self.import_wizard_obj.create(self.cr, self.uid, {
150+ "profile_id": self.profile_id,
151+ 'input_statement': base64.b64encode(content),
152+ 'file_name': os.path.basename(file_name),
153+ })
154+ res = self.import_wizard_obj.import_statement(self.cr, self.uid, wizard_id)
155+ statement_id = self.account_bank_statement_obj.search(self.cr, self.uid, eval(res['domain']))
156+ return self.account_bank_statement_obj.browse(self.cr, self.uid, statement_id)[0]
157+
158+ def test_simple_xls(self):
159+ """Test import from xls
160+ """
161+ self.prepare()
162+ file_name = self._filename_to_abs_filename(os.path.join("..", "data", "statement.xls"))
163+ statement = self._import_file(file_name)
164+ self._validate_imported_satement(statement)
165+
166+ def test_simple_csv(self):
167+ """Test import from csv
168+ """
169+ self.prepare()
170+ file_name = self._filename_to_abs_filename(os.path.join("..", "data", "statement.csv"))
171+ statement = self._import_file(file_name)
172+ self._validate_imported_satement(statement)
173+
174+ def _validate_imported_satement(self, statement):
175+ self.assertEqual("/", statement.name)
176+ self.assertEqual(0.0, statement.balance_start)
177+ self.assertEqual(0.0, statement.balance_end_real)
178+ self.assertEqual(3, len(statement.line_ids))
179+ self.assertTrue(statement.account_id)
180+ st_line_obj = statement.line_ids[1]
181+ # common infos
182+ self.assertEqual(st_line_obj.ref, "51065326")
183+ self.assertEqual(st_line_obj.date, "2011-03-02")
184+ self.assertEqual(st_line_obj.amount, 189.0)
185+ self.assertEqual(st_line_obj.name, "label b")

Subscribers

People subscribed via source and target branches