Stéphane Bidoul (Acsone) has proposed merging
lp:~openerp-community-testers/openobject-addons/trunk-sbi-bug1067375 into
lp:openobject-addons.
Requested reviews:
Olivier Dony (OpenERP) (odo-openerp)
Related bugs:
Bug #1067375 in OpenERP Addons: "[trunk / 6.1] system error creating invoice
in multi-company context when customer has no payable/receivable account for
current user's company"
https://bugs.launchpad.net/openobject-addons/+bug/1067375
For more details, see:
https://code.launchpad.net/~openerp-community-testers/openobject-addons/trunk-sbi-bug1067375/+merge/132356
--
https://code.launchpad.net/~openerp-community-testers/openobject-addons/trunk-sbi-bug1067375/+merge/132356
Your team OpenERP Community Testers is subscribed to branch
lp:~openerp-community-testers/openobject-addons/trunk-sbi-bug1067375.
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py 2012-10-29 09:17:13 +0000
+++ account/account_invoice.py 2012-10-31 15:37:25 +0000
@@ -449,28 +449,34 @@
opt.insert(0, ('id', partner_id))
res = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['invoice'])
invoice_addr_id = res['invoice']
- p = self.pool.get('res.partner').browse(cr, uid, partner_id)
- if company_id:
- if p.property_account_receivable.company_id.id != company_id and p.property_account_payable.company_id.id != company_id:
- property_obj = self.pool.get('ir.property')
- rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
- pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
- if not rec_pro_id:
- rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('company_id','=',company_id)])
- if not pay_pro_id:
- pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('company_id','=',company_id)])
- rec_line_data = property_obj.read(cr,uid,rec_pro_id,['name','value_reference','res_id'])
- pay_line_data = property_obj.read(cr,uid,pay_pro_id,['name','value_reference','res_id'])
- 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
- 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
- if not rec_res_id and not pay_res_id:
- raise osv.except_osv(_('Configuration Error!'),
- _('Cannot find a chart of accounts for this company, you should create one.'))
- account_obj = self.pool.get('account.account')
- rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])
- pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])
- p.property_account_receivable = rec_obj_acc[0]
- p.property_account_payable = pay_obj_acc[0]
+ context = {}
+ if company_id:
+ # set company in context so account receivable/payable properties
+ # are picked for the right company
+ context.update({'company_id': company_id, 'force_company': company_id})
+ p = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
+ if company_id:
+ if p.property_account_receivable and p.property_account_payable:
+ if p.property_account_receivable.company_id.id != company_id and p.property_account_payable.company_id.id != company_id:
+ property_obj = self.pool.get('ir.property')
+ rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
+ pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
+ if not rec_pro_id:
+ rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('company_id','=',company_id)])
+ if not pay_pro_id:
+ pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('company_id','=',company_id)])
+ rec_line_data = property_obj.read(cr,uid,rec_pro_id,['name','value_reference','res_id'])
+ pay_line_data = property_obj.read(cr,uid,pay_pro_id,['name','value_reference','res_id'])
+ 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
+ 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
+ if not rec_res_id and not pay_res_id:
+ raise osv.except_osv(_('Configuration Error!'),
+ _('Cannot find a chart of accounts for this company, you should create one.'))
+ account_obj = self.pool.get('account.account')
+ rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])
+ pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])
+ p.property_account_receivable = rec_obj_acc[0]
+ p.property_account_payable = pay_obj_acc[0]
if type in ('out_invoice', 'out_refund'):
acc_id = p.property_account_receivable.id
=== added directory 'account/tests'
=== added file 'account/tests/__init__.py'
--- account/tests/__init__.py 1970-01-01 00:00:00 +0000
+++ account/tests/__init__.py 2012-10-31 15:37:25 +0000
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from . import test_multi_company
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
=== added file 'account/tests/test_multi_company.py'
--- account/tests/test_multi_company.py 1970-01-01 00:00:00 +0000
+++ account/tests/test_multi_company.py 2012-10-31 15:37:25 +0000
@@ -0,0 +1,60 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from openerp.tests import common
+
+class test_multi_company(common.TransactionCase):
+
+ def prepare(self):
+ self.invoice_obj = self.registry('account.invoice')
+ self.company_obj = self.registry('res.company')
+ self.user_obj = self.registry('res.users')
+ self.account_obj = self.registry('account.account')
+
+ self.company_a_id = self.ref('base.main_company')
+ self.invoice_id = self.invoice_obj.create(self.cr, self.uid, {
+ 'type': 'out_invoice',
+ 'journal_id': self.ref('account.sales_journal'),
+ 'company_id': self.company_a_id,
+ 'partner_id': self.ref('base.res_partner_2'),
+ 'account_id': self.ref('account.a_recv'),
+ 'currency_id': self.ref('base.EUR'),
+ })
+
+ def test_00(self):
+ """ test account_invoice.onchange_partner_id """
+ self.prepare()
+ self.invoice_obj.onchange_partner_id(self.cr, self.uid, [self.invoice_id], 'out_invoice', self.ref('base.res_partner_3'))
+
+ def test_01(self):
+ """ test account_invoice.onchange_partner_id when the user's company is different than the invoice company """
+ self.prepare()
+ # create a company B that has no account chart and change the user's pref to that company
+ company_b_id = self.company_obj.create(self.cr, self.uid, {'name': 'Company B'})
+ self.user_obj.write(self.cr, self.uid, [self.uid], {
+ 'company_id': company_b_id,
+ })
+ res = self.invoice_obj.onchange_partner_id(self.cr, self.uid, [self.invoice_id],
+ type= 'out_invoice', partner_id=self.ref('base.res_partner_3'), company_id=self.company_a_id)
+ account = self.account_obj.browse(self.cr, self.uid, res['value'].get('account_id'))
+ self.assertEquals(self.company_a_id, account.company_id.id)
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp