[FIX] invoice tasks work: default to account tax when product has no tax
authorStéphane Bidoul <stephane.bidoul@acsone.eu>
Tue, 30 Oct 2012 11:26:32 +0000 (12:26 +0100)
committerStéphane Bidoul <stephane.bidoul@acsone.eu>
Tue, 30 Oct 2012 11:26:32 +0000 (12:26 +0100)
lp bug: https://launchpad.net/bugs/1048305 fixed

bzr revid: stephane.bidoul@acsone.eu-20121030112632-7cbfv7xgzqnua6i5

addons/hr_timesheet_invoice/test/test_hr_timesheet_invoice.yml
addons/hr_timesheet_invoice/wizard/hr_timesheet_invoice_create.py

index 91520da..bc19ce4 100644 (file)
@@ -69,6 +69,7 @@
     assert aline.invoice_id == invoice_id, "Invoice doesn't match the one at analytic line"
     # The expected amount is hard coded here, please keep updated:
     assert invoice_id.amount_untaxed == 187.5, "Invoice amount mismatch: %s" % invoice_id.amount_untaxed
+    assert invoice_id.amount_tax == 28.13, "Invoice tax mismatch: %s" %  invoice_id.amount_tax
 -
   I create final invoice for this analytic account.
 -
index 1201cc7..695d589 100644 (file)
@@ -49,7 +49,6 @@ class account_analytic_line(osv.osv):
     # }
     def invoice_cost_create(self, cr, uid, ids, data=None, context=None):
         analytic_account_obj = self.pool.get('account.analytic.account')
-        res_partner_obj = self.pool.get('res.partner')
         account_payment_term_obj = self.pool.get('account.payment.term')
         invoice_obj = self.pool.get('account.invoice')
         product_obj = self.pool.get('product.product')
@@ -115,7 +114,7 @@ class account_analytic_line(osv.osv):
 
             for product_id, user_id, factor_id, qty, uom, line_name in cr.fetchall():
                 if data.get('product'):
-                     product_id = data['product'][0]
+                    product_id = data['product'][0]
                 product = product_obj.browse(cr, uid, product_id, context=context2)
                 if not product:
                     raise osv.except_osv(_('Error!'), _('There is no product defined for the line %s. Please select one or force the product through the wizard.') % (line_name))
@@ -132,7 +131,7 @@ class account_analytic_line(osv.osv):
                 general_account = product.product_tmpl_id.property_account_income or product.categ_id.property_account_income_categ
                 if not general_account:
                     raise osv.except_osv(_("Configuration Error!"), _("Please define income account for product '%s'.") % product.name)
-                taxes = product.taxes_id
+                taxes = product.taxes_id or general_account.tax_ids
                 tax = fiscal_pos_obj.map_tax(cr, uid, account.partner_id.property_account_position, taxes)
                 curr_line = {
                     'price_unit': price,
@@ -211,7 +210,7 @@ class hr_timesheet_invoice_create(osv.osv_memory):
         data = context and context.get('active_ids', [])
         for analytic in analytic_obj.browse(cr, uid, data, context=context):
             if analytic.invoice_id:
-                     raise osv.except_osv(_('Warning!'), _("Invoice is already linked to some of the analytic line(s)!"))
+                raise osv.except_osv(_('Warning!'), _("Invoice is already linked to some of the analytic line(s)!"))
 
     def do_create(self, cr, uid, ids, context=None):
         data = self.read(cr, uid, ids, [], context=context)[0]