[FIX] bugfixed the incoming tax on onchange of product in supplier invoice and refund
authorqdp <qdp@tinyerp.com>
Tue, 27 Jan 2009 10:06:08 +0000 (11:06 +0100)
committerqdp <qdp@tinyerp.com>
Tue, 27 Jan 2009 10:06:08 +0000 (11:06 +0100)
[FIX] bugfixed the invoice validation: if we were setting up a customer invoice with a tax in one line and validated it without pressing the compute button first, it was
creating the tax line twice.

bzr revid: qdp@tinyerp.com-20090127100608-u942qhh9egpa420f

addons/account/invoice.py

index 2e55503..de343ee 100644 (file)
@@ -483,13 +483,9 @@ class account_invoice(osv.osv):
         cur_obj = self.pool.get('res.currency')
 
         for inv in self.browse(cr, uid, ids):
-            if not inv.tax_line:
-                self.button_compute(cr, uid, [inv.id], context={}, set_total=False)
             if inv.move_id:
                 continue
 
-            if inv.type in ('in_invoice', 'in_refund') and abs(inv.check_total - inv.amount_total) >= (inv.currency_id.rounding/2.0):
-                raise osv.except_osv(_('Bad total !'), _('Please verify the price of the invoice !\nThe real total does not match the computed total.'))
             if not inv.date_invoice:
                 self.write(cr, uid, [inv.id], {'date_invoice':time.strftime('%Y-%m-%d')})
             company_currency = inv.company_id.currency_id.id
@@ -519,6 +515,9 @@ class account_invoice(osv.osv):
                     if not key in tax_key:
                         raise osv.except_osv(_('Warning !'), _('Taxes missing !'))
 
+            if inv.type in ('in_invoice', 'in_refund') and abs(inv.check_total - inv.amount_total) >= (inv.currency_id.rounding/2.0):
+                raise osv.except_osv(_('Bad total !'), _('Please verify the price of the invoice !\nThe real total does not match the computed total.'))
+
             # one move line per tax line
             iml += ait_obj.move_line_get(cr, uid, inv.id)
 
@@ -986,7 +985,7 @@ class account_invoice_line(osv.osv):
             taxes = res.taxes_id and res.taxes_id or (a and self.pool.get('account.account').browse(cr, uid,a).tax_ids or False)
             tax_id = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes)
         else:
-            taxes = res.taxes_id and res.taxes_id or (a and self.pool.get('account.account').browse(cr, uid,a).tax_ids or False)
+            taxes = res.supplier_taxes_id and res.supplier_taxes_id or (a and self.pool.get('account.account').browse(cr, uid,a).tax_ids or False)
             tax_id = self.pool.get('account.fiscal.position').map_tax(cr, uid, fpos, taxes)
         if type in ('in_invoice', 'in_refund'):
             to_update = self.product_id_change_unit_price_inv(cr, uid, tax_id, price_unit, qty, address_invoice_id, product, partner_id, context=context)