Hello Everyone, recently i've an error (dunno if its error or bugs) in finance invoice that created from sales order.
the tax is there in orderline but not showing in the amount_tax.
but then i tried to make invoice directly from finance invoice, and it automatically shows the amount tax.
so i had a research on forum and found a few article related to it:
1.
https://www.odoo.com/forum/help-1/question/taxes-do-not-update-remain-0-00-when-creating-an-invoice-75539
(this one says that there are update tax button on odoo 8, and i cant
seem to found one in odoo 10)
2. https://stackoverflow.com/questions/31768708/odoo-calculate-tax-via-api (this one mentioning
button_reset_taxes , but i can't found this at account_invoice.py )..so
after a few hours, i found a solution thats is a similar API called
compute_taxes.
and DONE!, my task is done!, there comes a button to refresh that calls compute_taxes.
but the thing is, does it affect other module/ model/ field/ computation?
i just want to make sure its safe to use
===========================button_reset_taxes======================
@api.multi
def button_reset_taxes(self):
account_invoice_tax = self.env['account.invoice.tax']
ctx = dict(self._context)
for invoice in self:
self._cr.execute("DELETE FROM account_invoice_tax WHERE invoice_id=%s AND manual is False", (invoice.id,))
self.invalidate_cache()
partner = invoice.partner_id
if partner.lang:
ctx['lang'] = partner.lang
for taxe in account_invoice_tax.compute(invoice.with_context(ctx)).values():
account_invoice_tax.create(taxe)
# dummy write on self to trigger recomputations
return self.with_context(ctx).write({'invoice_line': []})
======================compute_taxes==================
@api.multi
def compute_taxes(self):
"""Function used in other module to compute the taxes on a fresh invoice created (onchanges did not applied)"""
account_invoice_tax = self.env['account.invoice.tax']
ctx = dict(self._context)
for invoice in self:
# Delete non-manual tax lines
self._cr.execute("DELETE FROM account_invoice_tax WHERE invoice_id=%s AND manual is False", (invoice.id,))
if self._cr.rowcount:
self.invalidate_cache()
# Generate one tax line per tax, however many invoice lines it's applied to
tax_grouped = invoice.get_taxes_values()
# Create new tax lines
for tax in tax_grouped.values():
account_invoice_tax.create(tax)
# dummy write on self to trigger recomputations
return self.with_context(ctx).write({'invoice_line_ids': []})