From 17edcf06301179bd9d7a7d05458e7d00c67a1d4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 9 Sep 2012 14:42:59 +0200 Subject: [PATCH] select account and taxes for the invoice's company instead of the user's default company when changing product or account This partially fixes lp:1048213 since the default account proposed when creating a new invoice line (in trunk only) is still from the user's company. lp bug: https://launchpad.net/bugs/1048213 fixed bzr revid: stephane.bidoul@acsone.eu-20120909124259-df6qo743sfogltf9 --- addons/account/account_invoice.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index e925e87c136..cd77b202e0e 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -1365,7 +1365,10 @@ class account_invoice_line(osv.osv): 'partner_id': fields.related('invoice_id','partner_id',type='many2one',relation='res.partner',string='Partner',store=True) } - def _default_account_id(self, cr, uid, ids, context=None): + def _default_account_id(self, cr, uid, context=None): + # XXX this gets the default account for the user's company, + # it should get the default account for the invoice's company + # however, the invoice's company does not reach this point prop = self.pool.get('ir.property').get(cr, uid, 'property_account_income_categ', 'product.category', context=context) return prop and prop.id or False @@ -1395,7 +1398,7 @@ class account_invoice_line(osv.osv): context = {} company_id = company_id if company_id != None else context.get('company_id',False) context = dict(context) - context.update({'company_id': company_id}) + context.update({'company_id': company_id, 'force_company': company_id}) if not partner_id: raise osv.except_osv(_('No Partner Defined !'),_("You must first select a partner !") ) if not product: @@ -1550,12 +1553,14 @@ class account_invoice_line(osv.osv): def onchange_account_id(self, cr, uid, ids, product_id, partner_id, inv_type, fposition_id, account_id): if not account_id: return {} - taxes = self.pool.get('account.account').browse(cr, uid, account_id).tax_ids + account = self.pool.get('account.account').browse(cr, uid, account_id) + taxes = account.tax_ids fpos = fposition_id and self.pool.get('account.fiscal.position').browse(cr, uid, fposition_id) or False tax_ids = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes) product_change_result = self.product_id_change(cr, uid, ids, product_id, False, type=inv_type, - partner_id=partner_id, fposition_id=fposition_id) + partner_id=partner_id, fposition_id=fposition_id, + company_id=account.company_id.id) unique_tax_ids = set(tax_ids) if product_change_result and 'value' in product_change_result and 'invoice_line_tax_id' in product_change_result['value']: unique_tax_ids |= set(product_change_result['value']['invoice_line_tax_id'])