[FIX] account_invoice_import_facturx: line level allowances counted twice - #1412
Open
am-technix wants to merge 2 commits into
Open
[FIX] account_invoice_import_facturx: line level allowances counted twice#1412am-technix wants to merge 2 commits into
am-technix wants to merge 2 commits into
Conversation
…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.
Contributor
|
Hi @alexis-via, |
Author
|
Added a unit test. The sample is |
am-technix
force-pushed
the
18.0-fix-facturx-line-allowance
branch
from
September 10, 2026 10:12
fca7036 to
f653aea
Compare
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
force-pushed
the
18.0-fix-facturx-line-allowance
branch
from
September 10, 2026 10:19
f653aea to
f4ec891
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 eachram:SpecifiedTradeAllowanceChargeas 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:ActualAmountfor its allowances, while BT-92 and BT-136 are defined as positive amounts, the direction being carried byram:ChargeIndicatoralone. 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.