Skip to content

[FIX] account_invoice_import_facturx: line level allowances counted twice - #1412

Open
am-technix wants to merge 2 commits into
OCA:18.0from
am-technix:18.0-fix-facturx-line-allowance
Open

[FIX] account_invoice_import_facturx: line level allowances counted twice#1412
am-technix wants to merge 2 commits into
OCA:18.0from
am-technix:18.0-fix-facturx-line-allowance

Conversation

@am-technix

Copy link
Copy Markdown

BT-131 (ram:LineTotalAmount) is already net of the line level allowances and charges, but the parser used it as the amount of the product line and then appended each ram:SpecifiedTradeAllowanceCharge as a separate line. Every allowance was therefore counted twice, and the difference ended up on the global adjustment line built by _post_process_invoice().

A real invoice received through a French accredited platform (PDP) made the problem obvious: 370 lines, 115 allowances, and a single "Adjustment" line of -1471.95 EUR, exactly twice the sum of the allowances, posted to the adjustment income account. The total was right, the breakdown was not: the expense account was overstated and revenue appeared out of nowhere.

The same invoice also showed that this issuer sends a negative ram:ActualAmount for its allowances, while BT-92 and BT-136 are defined as positive amounts, the direction being carried by ram:ChargeIndicator alone. Taking the amount as-is negated it twice and turned each allowance into a charge, which is how a "Remise" line ended up increasing the invoice.

This PR rebuilds the gross amount of the product line from BT-131 and the allowances and charges taken in absolute value, so that the lines returned always add up to BT-131 whatever the sign convention of the issuer.

Checked against 8 real Factur-X invoices from 5 issuers, including the 370-line one: the sum of the imported lines now matches BT-106 to the cent on all of them, with no adjustment line left, and the allowances read as negative amounts as they should.

…wice

BT-131 (ram:LineTotalAmount) is already net of the line level allowances and
charges, but the parser used it as the amount of the product line and then
appended each ram:SpecifiedTradeAllowanceCharge as a separate line. Every
allowance was therefore counted twice, and the difference ended up on the
global adjustment line built by _post_process_invoice().

A real invoice received through a French accredited platform (PDP) made the
problem obvious: 370 lines, 115 allowances, and a single 'Adjustment' line of
-1471.95 EUR, exactly twice the sum of the allowances, posted to the
adjustment income account. The total was right, the breakdown was not: the
expense account was overstated and revenue appeared out of nowhere.

The same invoice also showed that this issuer sends a negative
ram:ActualAmount for its allowances, while BT-92 and BT-136 are defined as
positive amounts, the direction being carried by ram:ChargeIndicator alone.
Taking the amount as-is negated it twice and turned each allowance into a
charge.

Rebuild the gross amount of the product line from BT-131 and the allowances
and charges taken in absolute value, so that the lines returned always add up
to BT-131 whatever the sign convention of the issuer.
@OCA-git-bot OCA-git-bot added series:18.0 mod:account_invoice_import_facturx Module account_invoice_import_facturx labels Sep 10, 2026
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @alexis-via,
some modules you are maintaining are being modified, check this out!

@am-technix

Copy link
Copy Markdown
Author

Added a unit test. The sample is Facture_FR_EN16931 from this very module, converted to XML, with a 2.00 allowance added on the first line and all the totals recomputed accordingly; it validates against the EN16931 XSD. The issuer writes the allowance as a negative ram:ActualAmount, as seen in the wild, so the test covers both the double counting and the sign convention. Without the fix the invoice comes out with an extra adjustment line and the allowance added instead of deducted.

@am-technix
am-technix force-pushed the 18.0-fix-facturx-line-allowance branch from fca7036 to f653aea Compare September 10, 2026 10:12
The sample is Facture_FR_EN16931 from this module, with a 2.00 allowance added
on the first line and all the totals recomputed accordingly. The issuer writes
the allowance as a negative ram:ActualAmount, as seen in the wild, so the test
covers both the double counting and the sign convention.
@am-technix
am-technix force-pushed the 18.0-fix-facturx-line-allowance branch from f653aea to f4ec891 Compare September 10, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:account_invoice_import_facturx Module account_invoice_import_facturx series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants