[MERGE] OPW 581301: account: fix wrong default taxes when changing account on invoice...
authorXavier ALT <xal@openerp.com>
Thu, 31 Jan 2013 10:22:57 +0000 (11:22 +0100)
committerXavier ALT <xal@openerp.com>
Thu, 31 Jan 2013 10:22:57 +0000 (11:22 +0100)
bzr revid: xal@openerp.com-20130131102257-k6llgiaxizris66h

1  2 
addons/account/account_invoice.py

@@@ -1356,15 -1356,16 +1356,21 @@@ class account_invoice_line(osv.osv)
              context.update({'lang': part.lang})
          result = {}
          res = self.pool.get('product.product').browse(cr, uid, product, context=context)
 +
          if type in ('out_invoice','out_refund'):
 -                a = res.product_tmpl_id.property_account_income.id
 -                if not a:
 -                    a = res.categ_id.property_account_income_categ.id
 +            a = res.product_tmpl_id.property_account_income.id
 +            if not a:
 +                a = res.categ_id.property_account_income_categ.id
          else:
 -                a = res.product_tmpl_id.property_account_expense.id
 -                if not a:
 -                    a = res.categ_id.property_account_expense_categ.id
 +            a = res.product_tmpl_id.property_account_expense.id
 +            if not a:
 +                a = res.categ_id.property_account_expense_categ.id
++
+         if context.get('account_id',False):
 -             a = context.get('account_id')
++            # this is set by onchange_account_id() to force the account choosen by the
++            # user - to get defaults taxes when product have no tax defined.
++            a = context['account_id']
++
          a = fpos_obj.map_account(cr, uid, fpos, a)
          if a:
              result['account_id'] = a
              taxes = account.tax_ids
              unique_tax_ids = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes)
          else:
 -            ctx = {'account_id': account_id}
++            # force user choosen account in context to allow product_id_change()
++            # to fallback to the this accounts in case product has no taxes defined.
++            context = {'account_id': account_id}
              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,context=ctx,
++                partner_id=partner_id, fposition_id=fposition_id, context=context,
                  company_id=account.company_id.id)
              if product_change_result and 'value' in product_change_result and 'invoice_line_tax_id' in product_change_result['value']:
                  unique_tax_ids = product_change_result['value']['invoice_line_tax_id']