Friday, September 6, 2024
1 change
Resolved issues and error corrections
This update fixes how Odoo calculates and rounds tax amounts on Mexican invoices (CFDI) to comply with Mexican tax authority requirements. The system now ensures that tax calculations stay within the allowed 0.01 rounding error margin, preventing invoice rejections by Mexican authorities. This is critical for businesses operating in Mexico that use the global rounding method for invoices.
Original PR description
This commit adds an additional step when aggregating the values for sending invoice CFDI, and ensures the final result to be within the allowed maximum rounding error of `0.01`. Purpose: When…
This commit adds an additional step when aggregating the values for sending invoice CFDI, and ensures the final result to be within the allowed maximum rounding error of `0.01`. Purpose: When creating an invoice with the following amounts: - line 1: 505.0, tax_16 - line 2: 495.0, tax_16 - line 3: 475.0, tax_16 - set tax_16.price_include to True The CFDI result of the invoice when generated using "round globally" method on either normal or global sending will be rejected by the mexican authorities. This is caused by an inherent flaw of how Odoo calculates line amounts. The `compute_all` method in taxes rounds all the lines in cfdi_values to 2 digits precision in the final result, resulting in a loss of precision when calculating the total amounts. The mexican authorities requires us to make sure that: 1. the sum of the base/tax amounts in the lines (Conceptos) matches the total 2. the rounding of the total base and tax amount to be within 0.01 rounding error In the provided example, in Odoo, we will generate a total of 1271.54 base amount and 203.46 tax amount. This is not acceptable by the mexican government because 1271.54 * 0.16 equals 203.4464, which when compared with our result of the tax amount exceeds the maximum allowed rounding error. To fix this, we have to sacrifice our correctness and generate amounts that will have disrepancies whenever we need it (for global rounding method). We will now re-calculate the base and tax amounts in `cfdi_values` based on the total amount and generate new amounts with 6 digits precision, and apply that on each line of Conceptos. The 2 digit rounding precision limit on `Importe` and `ValorUnitario` XML will be changed to 6 digits to make sure we pass the first requirement, as the mexican authorities will also calculate their total and check if it matches our total. Due to this change, all of the test files than contain this element needs to be udpated too. task-id: 4071712