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