Merge lp:~lmi/openobject-addons/7.0-bug1067541 into lp:openobject-addons/7.0

Proposed by Laurent Mignon (Acsone) on 2013-08-01
Status: Needs review
Proposed branch: lp:~lmi/openobject-addons/7.0-bug1067541
Merge into: lp:openobject-addons/7.0
Diff against target: 209 lines (+153/-7)
4 files modified
account/account_invoice_view.xml (+1/-1)
hr_timesheet_invoice/hr_timesheet_invoice.py (+12/-6)
hr_timesheet_invoice/tests/__init__.py (+26/-0)
hr_timesheet_invoice/tests/test_multi_company.py (+114/-0)
To merge this branch: bzr merge lp:~lmi/openobject-addons/7.0-bug1067541
Reviewer Review Type Date Requested Status
Stéphane Bidoul (Acsone) (community) code review and test Approve on 2013-10-29
OpenERP Core Team 2013-08-01 Pending
Review via email: mp+178026@code.launchpad.net
To post a comment you must log in.
Stéphane Bidoul (Acsone) (sbi) wrote :

The change is very simple: re-browse the partner in the context of the correct company so partner.property_account_receivable.id a bit farther in the code gives the proper receivable account.

review: Approve
9337. By Laurent Mignon (Acsone) on 2013-08-01

check for a valid partner_id on the analytic account before trying to access its attributes

9338. By Laurent Mignon (Acsone) on 2013-10-28

fixes bug in hr_timesheet_invoice.test_multi_company when the tests are run at the same time as the others tests

Stéphane Bidoul (Acsone) (sbi) wrote :

The test was working standalone bug failing in the context of the runbot full test suite. The test has been updated and is now working in both situations.

review: Approve (code review and test)
Stéphane Bidoul (Acsone) (sbi) wrote :

Moreover a potential bug was identified through the ocb review process and fixed back in august 2013.

Unmerged revisions

9338. By Laurent Mignon (Acsone) on 2013-10-28

fixes bug in hr_timesheet_invoice.test_multi_company when the tests are run at the same time as the others tests

9337. By Laurent Mignon (Acsone) on 2013-08-01

check for a valid partner_id on the analytic account before trying to access its attributes

9336. By Laurent Mignon (Acsone) on 2013-08-01

[FIX] #1067541 bill task work selects wrong receivable account in multi-company context
Cleaning of the initial code to take into account code moved since the original proposed patch (lp:~openerp-community-testers/openobject-addons/trunk-bug1067541)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_invoice_view.xml'
2--- account/account_invoice_view.xml 2013-09-20 09:50:26 +0000
3+++ account/account_invoice_view.xml 2013-10-28 16:55:49 +0000
4@@ -346,7 +346,7 @@
5 <field name="sent" invisible="1"/>
6 <notebook colspan="4">
7 <page string="Invoice Lines">
8- <field name="invoice_line" nolabel="1" widget="one2many_list" context="{'type': type}">
9+ <field name="invoice_line" nolabel="1" widget="one2many_list" context="{'type': type, 'company_id': company_id}">
10 <tree string="Invoice Lines" editable="bottom">
11 <field name="sequence" widget="handle"/>
12 <field name="product_id"
13
14=== modified file 'hr_timesheet_invoice/hr_timesheet_invoice.py'
15--- hr_timesheet_invoice/hr_timesheet_invoice.py 2013-07-25 10:04:02 +0000
16+++ hr_timesheet_invoice/hr_timesheet_invoice.py 2013-10-28 16:55:49 +0000
17@@ -167,6 +167,7 @@
18 fiscal_pos_obj = self.pool.get('account.fiscal.position')
19 product_uom_obj = self.pool.get('product.uom')
20 invoice_line_obj = self.pool.get('account.invoice.line')
21+ res_partner_obj = self.pool.get('res.partner')
22 invoices = []
23 if context is None:
24 context = {}
25@@ -183,9 +184,20 @@
26 for journal_type, account_ids in journal_types.items():
27 for account in analytic_account_obj.browse(cr, uid, list(account_ids), context=context):
28 partner = account.partner_id
29+
30 if (not partner) or not (account.pricelist_id):
31 raise osv.except_osv(_('Analytic Account Incomplete!'),
32 _('Contract incomplete. Please fill in the Customer and Pricelist fields.'))
33+ context2 = context.copy()
34+ context2['lang'] = account.partner_id.lang
35+ # set company_id in context, so the correct default journal will be selected
36+ # when creating the invoice
37+ context2['company_id'] = account.company_id.id
38+ # set force_company in context so the correct properties are selected
39+ # (eg. income account, receivable account)
40+ context2['force_company'] = account.company_id.id
41+
42+ partner = res_partner_obj.browse(cr, uid, account.partner_id.id, context=context2)
43
44 date_due = False
45 if partner.property_payment_term:
46@@ -207,12 +219,6 @@
47 'date_due': date_due,
48 'fiscal_position': account.partner_id.property_account_position.id
49 }
50- context2 = context.copy()
51- context2['lang'] = partner.lang
52- # set company_id in context, so the correct default journal will be selected
53- context2['force_company'] = curr_invoice['company_id']
54- # set force_company in context so the correct product properties are selected (eg. income account)
55- context2['company_id'] = curr_invoice['company_id']
56
57 last_invoice = invoice_obj.create(cr, uid, curr_invoice, context=context2)
58 invoices.append(last_invoice)
59
60=== added directory 'hr_timesheet_invoice/tests'
61=== added file 'hr_timesheet_invoice/tests/__init__.py'
62--- hr_timesheet_invoice/tests/__init__.py 1970-01-01 00:00:00 +0000
63+++ hr_timesheet_invoice/tests/__init__.py 2013-10-28 16:55:49 +0000
64@@ -0,0 +1,26 @@
65+# -*- coding: utf-8 -*-
66+##############################################################################
67+#
68+# OpenERP, Open Source Management Solution
69+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
70+#
71+# This program is free software: you can redistribute it and/or modify
72+# it under the terms of the GNU Affero General Public License as
73+# published by the Free Software Foundation, either version 3 of the
74+# License, or (at your option) any later version.
75+#
76+# This program is distributed in the hope that it will be useful,
77+# but WITHOUT ANY WARRANTY; without even the implied warranty of
78+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
79+# GNU Affero General Public License for more details.
80+#
81+# You should have received a copy of the GNU Affero General Public License
82+# along with this program. If not, see <http://www.gnu.org/licenses/>.
83+#
84+##############################################################################
85+from . import test_multi_company
86+
87+checks = [
88+ test_multi_company,
89+]
90+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
91
92=== added file 'hr_timesheet_invoice/tests/test_multi_company.py'
93--- hr_timesheet_invoice/tests/test_multi_company.py 1970-01-01 00:00:00 +0000
94+++ hr_timesheet_invoice/tests/test_multi_company.py 2013-10-28 16:55:49 +0000
95@@ -0,0 +1,114 @@
96+# -*- coding: utf-8 -*-
97+##############################################################################
98+#
99+# OpenERP, Open Source Management Solution
100+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
101+#
102+# This program is free software: you can redistribute it and/or modify
103+# it under the terms of the GNU Affero General Public License as
104+# published by the Free Software Foundation, either version 3 of the
105+# License, or (at your option) any later version.
106+#
107+# This program is distributed in the hope that it will be useful,
108+# but WITHOUT ANY WARRANTY; without even the implied warranty of
109+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
110+# GNU Affero General Public License for more details.
111+#
112+# You should have received a copy of the GNU Affero General Public License
113+# along with this program. If not, see <http://www.gnu.org/licenses/>.
114+#
115+##############################################################################
116+
117+from openerp.tests import common
118+
119+
120+class test_multi_company(common.TransactionCase):
121+
122+ QTY = 5.0
123+ PRICE = 75
124+
125+ def prepare(self):
126+ # super(test_multi_company, self).setUp()
127+
128+ self.company_obj = self.registry('res.company')
129+ self.analytic_account_obj = self.registry('account.analytic.account')
130+ self.analytic_line_obj = self.registry('account.analytic.line')
131+ self.invoice_obj = self.registry('account.invoice')
132+ self.product_obj = self.registry('product.product')
133+
134+ # load main company
135+ self.company_a = self.browse_ref('base.main_company')
136+ # create an analytic account
137+ self.aa_id = self.analytic_account_obj.create(self.cr, self.uid, {
138+ 'name': 'Project',
139+ 'company_id': self.company_a.id,
140+ 'partner_id': self.ref('base.res_partner_2'),
141+ 'pricelist_id': self.ref('product.list0'),
142+ })
143+ # set a known price on product
144+ self.product_obj.write(self.cr, self.uid, self.ref('product.product_product_consultant'), {
145+ 'list_price': self.PRICE,
146+ })
147+
148+ def create_invoice(self):
149+ # create an analytic line to invoice
150+ line_id = self.analytic_line_obj.create(self.cr, self.uid, {
151+ 'account_id': self.aa_id,
152+ 'amount': -1.0,
153+ 'general_account_id': self.ref('account.a_expense'),
154+ 'journal_id': self.ref('hr_timesheet.analytic_journal'),
155+ 'name': 'some work',
156+ 'product_id': self.ref('product.product_product_consultant'),
157+ 'product_uom_id': self.ref('product.product_uom_hour'),
158+ 'to_invoice': self.ref('hr_timesheet_invoice.timesheet_invoice_factor2'), # 50%
159+ 'unit_amount': self.QTY,
160+ })
161+ # XXX too strong coupling with UI?
162+ wizard_obj = self.registry('hr.timesheet.invoice.create')
163+ wizard_id = wizard_obj.create(self.cr, self.uid, {
164+ 'date': True,
165+ 'name': True,
166+ 'price': True,
167+ 'time': True,
168+ }, context={'active_ids': [line_id]})
169+ act_win = wizard_obj.do_create(self.cr, self.uid, [wizard_id], context={'active_ids': [line_id]})
170+ invoice_ids = self.invoice_obj.search(self.cr, self.uid, act_win['domain'])
171+ invoices = self.invoice_obj.browse(self.cr, self.uid, invoice_ids)
172+ self.assertEquals(1, len(invoices))
173+ return invoices[0]
174+
175+ def test_00(self):
176+ """ invoice task work basic test """
177+ self.prepare()
178+ invoice = self.create_invoice()
179+ self.assertEquals(round(self.QTY * self.PRICE * 0.5, 2), invoice.amount_untaxed)
180+
181+ def test_01(self):
182+ """ invoice task work for analytic account of other company """
183+ self.prepare()
184+ # create a company B with its own account chart
185+ self.company_b_id = self.company_obj.create(self.cr, self.uid, {'name': 'Company B'})
186+ self.company_b = self.company_obj.browse(self.cr, self.uid, self.company_b_id)
187+ mc_wizard = self.registry('wizard.multi.charts.accounts')
188+ mc_wizard_id = mc_wizard.create(self.cr, self.uid, {
189+ 'company_id': self.company_b_id,
190+ 'chart_template_id': self.ref('account.conf_chart0'),
191+ 'code_digits': 2,
192+ 'sale_tax': self.ref('account.itaxs'),
193+ 'purchase_tax': self.ref('account.otaxs'),
194+ # 'complete_tax_set': config.complete_tax_set,
195+ 'currency_id': self.company_b.currency_id.id,
196+ })
197+ mc_wizard.execute(self.cr, self.uid, [mc_wizard_id])
198+ # set our analytic account on company B
199+ self.analytic_account_obj.write(self.cr, self.uid, [self.aa_id], {
200+ 'company_id': self.company_b_id,
201+ })
202+ invoice = self.create_invoice()
203+ self.assertEquals(self.company_b_id, invoice.company_id.id, "invoice created for wrong company")
204+ self.assertEquals(self.company_b_id, invoice.journal_id.company_id.id, "invoice created with journal of wrong company")
205+ self.assertEquals(self.company_b_id, invoice.invoice_line[0].account_id.company_id.id, "invoice line created with account of wrong company")
206+ self.assertEquals(self.company_b_id, invoice.account_id.company_id.id, "invoice line created with partner account of wrong company")
207+ # self.assertEquals(self.company_b_id, invoice.fiscal_position.company_id.id, "invoice line created with fiscal position of wrong company")
208+
209+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: