Skip to Content
Menu
This question has been flagged
2 Replies
875 Views

As part of invoice import I need to adjust total tax (amount_tax) as there are rounding errors and tax calculated from invoice lines are off by 1 cent. In GUI there is button with pencil at the bottom of invoice and it works. It also recalculates Journal entries. I need to do the same from code, from module.

I tried:

invoice.amount_tax = 10

or

invoice.tax_totals = 10

but first just have no effect and second throws exception. Any ideas?

Using Odoo 17.0 CE

Avatar
Discard

Hi I want to migrate from source to destination db. total tax edited records are contained in some records when I migrate from source total tax is some of tax line ids I tried with these I added the tax amount in binary for the creation but it's not working how can I adda that in my migration

Author Best Answer

As it sometimes is, a while after I posted a question, I figured it out by myself. Will post for further references. Magical line is:

self.tax_totals = {'groups_by_subtotal': {'Untaxed Amount':[{'tax_group_id': 5, 'tax_group_amount':10.67}]}}

5 - is id of tax, 10.67 is amount of tax.

Bellow is explanation from Gemini:

=========

    tax_totals = fields.Binary(

        string="Invoice Totals",

        compute='_compute_tax_totals',

        inverse='_inverse_tax_totals',

        help='Edit Tax amounts if you encounter rounding issues.',

        exportable=False,

    )

In this case, tax_totals = fields.Binary(...) with inverse='_inverse_tax_totals' is used for a special purpose related to handling tax totals and potential rounding issues on invoices (or similar documents). It's not a typical Many2one relationship, so the way inverse works is slightly different.

Understanding the Context

The tax_totals field stores a serialized representation (usually JSON) of the tax breakdown for the invoice. This data is computed dynamically based on the invoice lines and tax configuration. The purpose of having an inverse function here is to allow users to manually adjust the tax totals in the UI, and then have Odoo recalculate the invoice lines to match those adjusted totals.

How it Works

  1. compute='_compute_tax_totals': This means the tax_totals value is calculated by the _compute_tax_totals method. This method generates the JSON representation of the tax breakdown.
  2. inverse='_inverse_tax_totals': This is where the manual adjustment comes in. When a user modifies the tax totals in the UI (which is typically presented as a table or a form), the _inverse_tax_totals method is called.
  3. _inverse_tax_totals(self): This method receives the modified tax totals (from the UI) and its task is to:
    • Parse the modified JSON data.
    • Attempt to adjust the invoice lines (amounts, quantities, or potentially even tax rates) in a way that results in the desired tax totals.
    • Handle potential rounding issues and inconsistencies.




Avatar
Discard