select account and taxes for the invoice's company instead of the user's default...
authorStéphane Bidoul <stephane.bidoul@acsone.eu>
Sun, 9 Sep 2012 12:42:59 +0000 (14:42 +0200)
committerStéphane Bidoul <stephane.bidoul@acsone.eu>
Sun, 9 Sep 2012 12:42:59 +0000 (14:42 +0200)
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

index e925e87..cd77b20 100644 (file)
@@ -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'])