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
=== modified file 'account/account_invoice_view.xml'
--- account/account_invoice_view.xml 2013-05-31 12:19:45 +0000
+++ account/account_invoice_view.xml 2013-08-01 13:22:31 +0000
@@ -345,7 +345,7 @@
345 <field name="sent" invisible="1"/>345 <field name="sent" invisible="1"/>
346 <notebook colspan="4">346 <notebook colspan="4">
347 <page string="Invoice Lines">347 <page string="Invoice Lines">
348 <field name="invoice_line" nolabel="1" widget="one2many_list" context="{'type': type}">348 <field name="invoice_line" nolabel="1" widget="one2many_list" context="{'type': type, 'company_id': company_id}">
349 <tree string="Invoice Lines" editable="bottom">349 <tree string="Invoice Lines" editable="bottom">
350 <field name="product_id"350 <field name="product_id"
351 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)"/>351 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)"/>
352352
=== 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-08-01 13:22:31 +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-08-01 13:22:31 +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-08-01 13:22:31 +0000
@@ -0,0 +1,116 @@
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': config.sale_tax.id,
98 # 'purchase_tax': config.purchase_tax.id,
99 'sale_tax_rate': 0.10,
100 'purchase_tax_rate': 0.10,
101 # 'complete_tax_set': config.complete_tax_set,
102 'currency_id': self.company_b.currency_id.id,
103 })
104 mc_wizard.execute(self.cr, self.uid, [mc_wizard_id])
105 # set our analytic account on company B
106 self.analytic_account_obj.write(self.cr, self.uid, [self.aa_id], {
107 'company_id': self.company_b_id,
108 })
109 invoice = self.create_invoice()
110 self.assertEquals(self.company_b_id, invoice.company_id.id, "invoice created for wrong company")
111 self.assertEquals(self.company_b_id, invoice.journal_id.company_id.id, "invoice created with journal of wrong company")
112 self.assertEquals(self.company_b_id, invoice.invoice_line[0].account_id.company_id.id, "invoice line created with account of wrong company")
113 self.assertEquals(self.company_b_id, invoice.account_id.company_id.id, "invoice line created with partner account of wrong company")
114 # self.assertEquals(self.company_b_id, invoice.fiscal_position.company_id.id, "invoice line created with fiscal position of wrong company")
115
116# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: