Thursday, December 7, 2023
1 change · 17.0
Resolved issues and error corrections
This fix resolves two critical issues when processing Mexican invoices with negative line items. The system was crashing when trying to generate tax documents (CFDI) and was incorrectly calculating discount distributions across invoice lines. The fix ensures negative amounts are properly distributed and tax calculations are accurate.
Original PR description
Steps to reproduce: - Install Accounting and l10n_mx_edi - Switch to a Mexican company (e.g. ESCUELA KEMPER URGATE) - Go to "Settings / Technical / Parameters / System Parameters" - Create this…
Steps to reproduce:
- Install Accounting and l10n_mx_edi
- Switch to a Mexican company (e.g. ESCUELA KEMPER URGATE)
- Go to "Settings / Technical / Parameters / System Parameters"
- Create this parameter:
* Key: l10n_mx_edi.manage_invoice_negative_lines
* Value: True
- Create an invoice:
* Customer: [a Mexican customer] (e.g. INMOBILIARIA CVA)
* Invoice Lines:
- Product: P1 - Price: 200 - Taxes: 16%
- Product: P2 - Price: 100 - Taxes: 16% - Product: Discount - Price: -201 (i.e. absolute value greater than 200) - Taxes: 16%
- Confirm the invoice
- Generate "CFDI" via "Send & Print" button => A KeyError ('tax') is raised.
Cause:
When there is a negative line, its amount is distributed as a discount between the other lines and the tax data are updated. During the process, if the amount to distribute is greater than the amount of the first line, a ratio is computed using the inexistant "tax" key.
Another issue:
The distribution ratio is wrongly computed, dividing [the amount to distribute] by [the remaining amount to distribute].
In our example, the amount to distribute for the first line is 200 and the remaining amount to distribute is 1, resulting on a ratio of (200 / 1) = 200, which is not correct.
The ratio should be computed with the total amount to distribute (i.e. 201). In our example, the ratio for the first line should be (200 / 201).
opw-3614319
Forward-Port-Of: odoo/enterprise#52064