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

Proposed by Laurent Mignon (Acsone)
Status: Merged
Merged at revision: 9406
Proposed branch: lp:~lmi/ocb-addons/7.0-bug1067541
Merge into: lp:ocb-addons
Diff against target: 211 lines (+155/-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 (+116/-0)
To merge this branch: bzr merge lp:~lmi/ocb-addons/7.0-bug1067541
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Stéphane Bidoul (Acsone) (community) code review Approve
Stefan Rijnhart (Opener) Approve
Review via email: mp+178024@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks! You may want to move your code down below the check for a valid partner_id on the analytic account in line 41, otherwise you may run into trouble if you try to access its 'lang' in l.31.

review: Needs Fixing
Revision history for this message
Laurent Mignon (Acsone) (lmi) wrote :

Thanks for the review!

Code modified according to your review.
(modifications also done on the branch proposed for merge on the official branch)

> Thanks! You may want to move your code down below the check for a valid
> partner_id on the analytic account in line 41, otherwise you may run into
> trouble if you try to access its 'lang' in l.31.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks for the changes! Looks good to me.

review: Approve
Revision history for this message
Stéphane Bidoul (Acsone) (sbi) :
review: Approve (code review)
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)

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-05-31 12:19:45 +0000
3+++ account/account_invoice_view.xml 2013-08-01 13:22:31 +0000
4@@ -345,7 +345,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="product_id"
12 on_change="product_id_change(product_id, uos_id, quantity, name, parent.type, parent.partner_id, parent.fiscal_position, price_unit, parent.currency_id, context, parent.company_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-08-01 13:22:31 +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-08-01 13:22:31 +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-08-01 13:22:31 +0000
95@@ -0,0 +1,116 @@
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': config.sale_tax.id,
193+ # 'purchase_tax': config.purchase_tax.id,
194+ 'sale_tax_rate': 0.10,
195+ 'purchase_tax_rate': 0.10,
196+ # 'complete_tax_set': config.complete_tax_set,
197+ 'currency_id': self.company_b.currency_id.id,
198+ })
199+ mc_wizard.execute(self.cr, self.uid, [mc_wizard_id])
200+ # set our analytic account on company B
201+ self.analytic_account_obj.write(self.cr, self.uid, [self.aa_id], {
202+ 'company_id': self.company_b_id,
203+ })
204+ invoice = self.create_invoice()
205+ self.assertEquals(self.company_b_id, invoice.company_id.id, "invoice created for wrong company")
206+ self.assertEquals(self.company_b_id, invoice.journal_id.company_id.id, "invoice created with journal of wrong company")
207+ self.assertEquals(self.company_b_id, invoice.invoice_line[0].account_id.company_id.id, "invoice line created with account of wrong company")
208+ self.assertEquals(self.company_b_id, invoice.account_id.company_id.id, "invoice line created with partner account of wrong company")
209+ # self.assertEquals(self.company_b_id, invoice.fiscal_position.company_id.id, "invoice line created with fiscal position of wrong company")
210+
211+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: