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
=== modified file 'account/account_invoice.py'
--- account/account_invoice.py 2012-10-29 09:17:13 +0000
+++ account/account_invoice.py 2012-10-31 16:37:23 +0000
@@ -449,28 +449,34 @@
449 opt.insert(0, ('id', partner_id))449 opt.insert(0, ('id', partner_id))
450 res = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['invoice'])450 res = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['invoice'])
451 invoice_addr_id = res['invoice']451 invoice_addr_id = res['invoice']
452 p = self.pool.get('res.partner').browse(cr, uid, partner_id)452 context = {}
453 if company_id:453 if company_id:
454 if p.property_account_receivable.company_id.id != company_id and p.property_account_payable.company_id.id != company_id:454 # set company in context so account receivable/payable properties
455 property_obj = self.pool.get('ir.property')455 # are picked for the right company
456 rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])456 context.update({'company_id': company_id, 'force_company': company_id})
457 pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])457 p = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
458 if not rec_pro_id:458 if company_id:
459 rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('company_id','=',company_id)])459 if p.property_account_receivable and p.property_account_payable:
460 if not pay_pro_id:460 if p.property_account_receivable.company_id.id != company_id and p.property_account_payable.company_id.id != company_id:
461 pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('company_id','=',company_id)])461 property_obj = self.pool.get('ir.property')
462 rec_line_data = property_obj.read(cr,uid,rec_pro_id,['name','value_reference','res_id'])462 rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
463 pay_line_data = property_obj.read(cr,uid,pay_pro_id,['name','value_reference','res_id'])463 pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('res_id','=','res.partner,'+str(partner_id)+''),('company_id','=',company_id)])
464 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 False464 if not rec_pro_id:
465 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 False465 rec_pro_id = property_obj.search(cr,uid,[('name','=','property_account_receivable'),('company_id','=',company_id)])
466 if not rec_res_id and not pay_res_id:466 if not pay_pro_id:
467 raise osv.except_osv(_('Configuration Error!'),467 pay_pro_id = property_obj.search(cr,uid,[('name','=','property_account_payable'),('company_id','=',company_id)])
468 _('Cannot find a chart of accounts for this company, you should create one.'))468 rec_line_data = property_obj.read(cr,uid,rec_pro_id,['name','value_reference','res_id'])
469 account_obj = self.pool.get('account.account')469 pay_line_data = property_obj.read(cr,uid,pay_pro_id,['name','value_reference','res_id'])
470 rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])470 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
471 pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])471 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
472 p.property_account_receivable = rec_obj_acc[0]472 if not rec_res_id and not pay_res_id:
473 p.property_account_payable = pay_obj_acc[0]473 raise osv.except_osv(_('Configuration Error!'),
474 _('Cannot find a chart of accounts for this company, you should create one.'))
475 account_obj = self.pool.get('account.account')
476 rec_obj_acc = account_obj.browse(cr, uid, [rec_res_id])
477 pay_obj_acc = account_obj.browse(cr, uid, [pay_res_id])
478 p.property_account_receivable = rec_obj_acc[0]
479 p.property_account_payable = pay_obj_acc[0]
474480
475 if type in ('out_invoice', 'out_refund'):481 if type in ('out_invoice', 'out_refund'):
476 acc_id = p.property_account_receivable.id482 acc_id = p.property_account_receivable.id
477483
=== 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 16:37:23 +0000
@@ -0,0 +1,27 @@
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 . import test_multi_company
23
24checks = [
25 test_multi_company,
26]
27# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
028
=== 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 16:37:23 +0000
@@ -0,0 +1,60 @@
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
24class test_multi_company(common.TransactionCase):
25
26 def prepare(self):
27 self.invoice_obj = self.registry('account.invoice')
28 self.company_obj = self.registry('res.company')
29 self.user_obj = self.registry('res.users')
30 self.account_obj = self.registry('account.account')
31
32 self.company_a_id = self.ref('base.main_company')
33 self.invoice_id = self.invoice_obj.create(self.cr, self.uid, {
34 'type': 'out_invoice',
35 'journal_id': self.ref('account.sales_journal'),
36 'company_id': self.company_a_id,
37 'partner_id': self.ref('base.res_partner_2'),
38 'account_id': self.ref('account.a_recv'),
39 'currency_id': self.ref('base.EUR'),
40 })
41
42 def test_00(self):
43 """ test account_invoice.onchange_partner_id """
44 self.prepare()
45 self.invoice_obj.onchange_partner_id(self.cr, self.uid, [self.invoice_id], 'out_invoice', self.ref('base.res_partner_3'))
46
47 def test_01(self):
48 """ test account_invoice.onchange_partner_id when the user's company is different than the invoice company """
49 self.prepare()
50 # create a company B that has no account chart and change the user's pref to that company
51 company_b_id = self.company_obj.create(self.cr, self.uid, {'name': 'Company B'})
52 self.user_obj.write(self.cr, self.uid, [self.uid], {
53 'company_id': company_b_id,
54 })
55 res = self.invoice_obj.onchange_partner_id(self.cr, self.uid, [self.invoice_id],
56 type= 'out_invoice', partner_id=self.ref('base.res_partner_3'), company_id=self.company_a_id)
57 account = self.account_obj.browse(self.cr, self.uid, res['value'].get('account_id'))
58 self.assertEquals(self.company_a_id, account.company_id.id)
59
60# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

Subscribers

People subscribed via source and target branches

to all changes: