Merge lp:~openerp-community-testers/openobject-addons/trunk-sbi-bug1067375 into lp:openobject-addons

Proposed by Stéphane Bidoul (Acsone)
Status: Needs review
Proposed branch: lp:~openerp-community-testers/openobject-addons/trunk-sbi-bug1067375
Merge into: lp:openobject-addons
Diff against target: 158 lines (+115/-22)
3 files modified
account/account_invoice.py (+28/-22)
account/tests/__init__.py (+27/-0)
account/tests/test_multi_company.py (+60/-0)
To merge this branch: bzr merge lp:~openerp-community-testers/openobject-addons/trunk-sbi-bug1067375
Reviewer Review Type Date Requested Status
Olivier Dony (Odoo) Pending
Review via email: mp+132356@code.launchpad.net
To post a comment you must log in.
7901. By Stéphane Bidoul (Acsone)

account tests: add checks in __init__.py

Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Hi,

Anything blocking this MP from the test sprint?

-sbi

Revision history for this message
Olivier Dony (Odoo) (odo-openerp) wrote :

Hi Stephane,

Nothing blocking but the surrounding (older) code looks suspiciously complicated/redundant so I wanted to have a closer look at it before merging, if you don't mind too much (if I merge directly it will be forgotten)

Revision history for this message
Stéphane Bidoul (Acsone) (sbi) wrote :

Hi Olivier,

Yep indeed I also noticed the whole area looks quite convoluted.

Nothing urgent on my side.

Unmerged revisions

7901. By Stéphane Bidoul (Acsone)

account tests: add checks in __init__.py

7900. By Stéphane Bidoul (Acsone)

[FIX] account_invoice: system error creating invoice in multi-company context when customer has no payable/receivable account for current user's company

7899. By Stéphane Bidoul (Acsone)

account_invoice: added test for 1067375

7898. By Launchpad Translations on behalf of openerp

Launchpad automatic translations update.

7897. By Olivier Dony (Odoo)

[FIX] account: currency_id must be passed to the chart installation wizard

Otherwise the installation of a chart of account
via the settings page fails miserably.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_invoice.py'
2--- account/account_invoice.py 2012-10-29 09:17:13 +0000
3+++ account/account_invoice.py 2012-10-31 16:37:23 +0000
4@@ -449,28 +449,34 @@
5 opt.insert(0, ('id', partner_id))
6 res = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['invoice'])
7 invoice_addr_id = res['invoice']
8- p = self.pool.get('res.partner').browse(cr, uid, partner_id)
9- if company_id:
10- if p.property_account_receivable.company_id.id != company_id and p.property_account_payable.company_id.id != company_id:
11- property_obj = self.pool.get('ir.property')
12- rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
13- pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
14- if not rec_pro_id:
15- rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('company_id','=',company_id)])
16- if not pay_pro_id:
17- pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('company_id','=',company_id)])
18- rec_line_data = property_obj.read(cr,uid,rec_pro_id,['name','value_reference','res_id'])
19- pay_line_data = property_obj.read(cr,uid,pay_pro_id,['name','value_reference','res_id'])
20- rec_res_id = rec_line_data and rec_line_data[0].get('value_reference',False) and int(rec_line_data[0]['value_reference'].split(',')[1]) or False
21- pay_res_id = pay_line_data and pay_line_data[0].get('value_reference',False) and int(pay_line_data[0]['value_reference'].split(',')[1]) or False
22- if not rec_res_id and not pay_res_id:
23- raise osv.except_osv(_('Configuration Error!'),
24- _('Cannot find a chart of accounts for this company, you should create one.'))
25- account_obj = self.pool.get('account.account')
26- rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])
27- pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])
28- p.property_account_receivable = rec_obj_acc[0]
29- p.property_account_payable = pay_obj_acc[0]
30+ context = {}
31+ if company_id:
32+ # set company in context so account receivable/payable properties
33+ # are picked for the right company
34+ context.update({'company_id': company_id, 'force_company': company_id})
35+ p = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
36+ if company_id:
37+ if p.property_account_receivable and p.property_account_payable:
38+ if p.property_account_receivable.company_id.id != company_id and p.property_account_payable.company_id.id != company_id:
39+ property_obj = self.pool.get('ir.property')
40+ rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
41+ pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
42+ if not rec_pro_id:
43+ rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('company_id','=',company_id)])
44+ if not pay_pro_id:
45+ pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('company_id','=',company_id)])
46+ rec_line_data = property_obj.read(cr,uid,rec_pro_id,['name','value_reference','res_id'])
47+ pay_line_data = property_obj.read(cr,uid,pay_pro_id,['name','value_reference','res_id'])
48+ rec_res_id = rec_line_data and rec_line_data[0].get('value_reference',False) and int(rec_line_data[0]['value_reference'].split(',')[1]) or False
49+ pay_res_id = pay_line_data and pay_line_data[0].get('value_reference',False) and int(pay_line_data[0]['value_reference'].split(',')[1]) or False
50+ if not rec_res_id and not pay_res_id:
51+ raise osv.except_osv(_('Configuration Error!'),
52+ _('Cannot find a chart of accounts for this company, you should create one.'))
53+ account_obj = self.pool.get('account.account')
54+ rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])
55+ pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])
56+ p.property_account_receivable = rec_obj_acc[0]
57+ p.property_account_payable = pay_obj_acc[0]
58
59 if type in ('out_invoice', 'out_refund'):
60 acc_id = p.property_account_receivable.id
61
62=== added directory 'account/tests'
63=== added file 'account/tests/__init__.py'
64--- account/tests/__init__.py 1970-01-01 00:00:00 +0000
65+++ account/tests/__init__.py 2012-10-31 16:37:23 +0000
66@@ -0,0 +1,27 @@
67+# -*- coding: utf-8 -*-
68+##############################################################################
69+#
70+# OpenERP, Open Source Management Solution
71+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
72+#
73+# This program is free software: you can redistribute it and/or modify
74+# it under the terms of the GNU Affero General Public License as
75+# published by the Free Software Foundation, either version 3 of the
76+# License, or (at your option) any later version.
77+#
78+# This program is distributed in the hope that it will be useful,
79+# but WITHOUT ANY WARRANTY; without even the implied warranty of
80+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
81+# GNU Affero General Public License for more details.
82+#
83+# You should have received a copy of the GNU Affero General Public License
84+# along with this program. If not, see <http://www.gnu.org/licenses/>.
85+#
86+##############################################################################
87+
88+from . import test_multi_company
89+
90+checks = [
91+ test_multi_company,
92+]
93+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
94
95=== added file 'account/tests/test_multi_company.py'
96--- account/tests/test_multi_company.py 1970-01-01 00:00:00 +0000
97+++ account/tests/test_multi_company.py 2012-10-31 16:37:23 +0000
98@@ -0,0 +1,60 @@
99+# -*- coding: utf-8 -*-
100+##############################################################################
101+#
102+# OpenERP, Open Source Management Solution
103+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
104+#
105+# This program is free software: you can redistribute it and/or modify
106+# it under the terms of the GNU Affero General Public License as
107+# published by the Free Software Foundation, either version 3 of the
108+# License, or (at your option) any later version.
109+#
110+# This program is distributed in the hope that it will be useful,
111+# but WITHOUT ANY WARRANTY; without even the implied warranty of
112+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
113+# GNU Affero General Public License for more details.
114+#
115+# You should have received a copy of the GNU Affero General Public License
116+# along with this program. If not, see <http://www.gnu.org/licenses/>.
117+#
118+##############################################################################
119+
120+from openerp.tests import common
121+
122+class test_multi_company(common.TransactionCase):
123+
124+ def prepare(self):
125+ self.invoice_obj = self.registry('account.invoice')
126+ self.company_obj = self.registry('res.company')
127+ self.user_obj = self.registry('res.users')
128+ self.account_obj = self.registry('account.account')
129+
130+ self.company_a_id = self.ref('base.main_company')
131+ self.invoice_id = self.invoice_obj.create(self.cr, self.uid, {
132+ 'type': 'out_invoice',
133+ 'journal_id': self.ref('account.sales_journal'),
134+ 'company_id': self.company_a_id,
135+ 'partner_id': self.ref('base.res_partner_2'),
136+ 'account_id': self.ref('account.a_recv'),
137+ 'currency_id': self.ref('base.EUR'),
138+ })
139+
140+ def test_00(self):
141+ """ test account_invoice.onchange_partner_id """
142+ self.prepare()
143+ self.invoice_obj.onchange_partner_id(self.cr, self.uid, [self.invoice_id], 'out_invoice', self.ref('base.res_partner_3'))
144+
145+ def test_01(self):
146+ """ test account_invoice.onchange_partner_id when the user's company is different than the invoice company """
147+ self.prepare()
148+ # create a company B that has no account chart and change the user's pref to that company
149+ company_b_id = self.company_obj.create(self.cr, self.uid, {'name': 'Company B'})
150+ self.user_obj.write(self.cr, self.uid, [self.uid], {
151+ 'company_id': company_b_id,
152+ })
153+ res = self.invoice_obj.onchange_partner_id(self.cr, self.uid, [self.invoice_id],
154+ type= 'out_invoice', partner_id=self.ref('base.res_partner_3'), company_id=self.company_a_id)
155+ account = self.account_obj.browse(self.cr, self.uid, res['value'].get('account_id'))
156+ self.assertEquals(self.company_a_id, account.company_id.id)
157+
158+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches

to all changes: