Skip to content

[29.0] BE's PEPPOL "escompte" compensation - #11037

Open
Joshua (mynjj) wants to merge 4 commits into
releases/29.0from
bugs/be-peppol-escompte-compensation-29.0
Open

[29.0] BE's PEPPOL "escompte" compensation#11037
Joshua (mynjj) wants to merge 4 commits into
releases/29.0from
bugs/be-peppol-escompte-compensation-29.0

Conversation

@mynjj

@mynjj Joshua (mynjj) commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Backport of #11023 to releases/29.0.

In BE, there's this weird tradition that when you have a payment terms discount, the VAT is calculated with that discount as taxable base, even when the full amount (pre-discount) is shown in the total.

In our standard PEPPOL, payment discounts are added as AllowanceCharge, which is what is desired, but the totals then become less, which is not what they do in BE.

A previous attempt to fix this was to remove the AllowanceCharge for the VAT, which was incorrect, since the totals would now be mismatching. More over, the confusion of the recent move to this app from BaseApp, and branching of 28.x when the fix landed, made the fix unavailable for 28.4 (to be dealt in other PRs).

What the PR does

  • Modeled this situation as: the AllowanceCharge staying (so taxable base is with discount), but an additional AllowanceCharge was added to compensate and show the total as it's tradition (and legally mandated) in BE. This also implied adding another TaxSubtotal and a ChargeTotalAmount. The produced documents were validated against several online validators, and also match the approach that Scrada uses (from customer's examples).
  • Actually added the test app, before there was no app.json in the folder.
  • Analogous changes are in BaseApp (while that code goes away, already deprecated).

I didn't add BaseApp's test, since that code is going away anyway, in favor of the new place in E-Documents.

Fixes AB#649017

@mynjj
Joshua (mynjj) requested a review from a team September 4, 2026 07:43
@mynjj
Joshua (mynjj) requested review from a team as code owners September 4, 2026 07:43
@github-actions github-actions Bot added the AL: Apps (W1) Add-on apps for W1 label Sep 4, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Sep 4, 2026
@github-actions github-actions Bot added the Team: Finance GitHub request for Finance area label Sep 4, 2026
@mynjj
Joshua (mynjj) force-pushed the bugs/be-peppol-escompte-compensation-29.0 branch from 075096c to e6ed954 Compare September 4, 2026 07:48
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 1

Recommendation: Request Changes

What this PR does

The change adds a Belgian escompte compensation line so VAT stays on the discounted base while the payable amount remains whole. The main sales-invoice path and test follow that model, but the implementation does not safely distinguish the synthetic Exempt subtotal from normal Exempt VAT, and one analogous deprecated BaseApp export path is not updated.

Problem-solution fit

Fit: Partial

The reported sales-invoice case is mostly addressed by the synthetic tax subtotal, charge total, and test coverage. The fix still leaves mixed Exempt VAT documents and the matching BaseApp credit memo flow with incorrect export behavior.

Suggestions

S1 (🔴 High): Exemption reason applies to normal exempt lines
The fallback only checks category E. A normal Exempt VAT subtotal and the synthetic escompte subtotal both use E, so mixed documents can get the wrong exemption reason. Pass the current VAT amount line context, or another compensation marker, before using this reason.

S2 (🔴 High): BaseApp exemption reason applies too broadly
The deprecated BaseApp path has the same category-only fallback. It can write the payment-discount reason on a normal Exempt VAT subtotal, or hide the compensation reason behind a normal E description. Keep it aligned with the app fix and check the compensation marker.

S3 (🔴 High): BaseApp credit memos miss compensation
The new compensation is added to the BaseApp invoice XMLport only. The BaseApp sales credit memo XMLport builds the same VAT buffer and payment-discount AllowanceCharge, so credit memos can still export reduced payable totals. Add the same compensation call before the credit memo XML output starts.

Risk assessment and necessity

Risk: Belgian PEPPOL tax subtotals, exemption reasons, and payable totals are financial and compliance-sensitive export data. The default interface method limits compatibility risk, but wrong Exempt reasons or reduced credit memo totals can produce incorrect XML.

Necessity: The compensation is needed for Belgian escompte exports. The scope should also preserve correct normal Exempt VAT output and keep the analogous BaseApp export paths consistent.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11037 round=1 by=alexei-dobriansky at=2026-09-04T10:39:16Z lastSha=e6ed9545348a8f19644f7b8c079ce11235046292 reviewKey=0ec5c81e43fea396de820c9714b62a82203fb2e459c7c68ec86add8fc4ad5112 suggestions=S1@9bd62c83,S2@4a676ec8,S3@420035a2

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Stale Status Check Deleted

The Pull Request Build workflow run for this PR was older than 72 hours and has been deleted.

📋 Why was it deleted?

Status checks that are too old may no longer reflect the current state of the target branch. To ensure this PR is validated against the latest code and passes up-to-date checks, a fresh build is required.


🔄 How to trigger a new status check:

  1. 📤 Push a new commit to the PR branch, or
  2. 🔁 Close and reopen the PR

This will automatically trigger a new Pull Request Build workflow run.

Joshua Martínez Pineda added 2 commits September 8, 2026 13:43
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Good Sense Reviewer - Round 2

Recommendation: Request Changes

What this PR does

The new commits pass the current VAT amount line into the tax-exemption reason lookup, so normal Exempt VAT subtotals and the synthetic escompte subtotal can be told apart. They also add invoice tests for mixed Exempt VAT and no-discount cases, and align the exemption-reason lookup in the deprecated BaseApp export code. The main app invoice and credit memo paths use the shared finalization hook, but the deprecated BaseApp credit memo XMLport still builds its own VAT buffer and still does not add the payment-discount compensation line.

Status of previous suggestions
ID Title Status Author response
S1 Exemption reason applies to normal exempt lines Addressed
S2 BaseApp exemption reason applies too broadly Addressed
S3 BaseApp credit memos miss compensation Not addressed
New observations (commits since round 1)

None - the new commits address earlier exemption-reason issues and add tests. The remaining blocker is carried forward from round 1.

Risk assessment and necessity

Risk: The changed area writes Belgian PEPPOL tax subtotals, exemption reasons, AllowanceCharge lines, and payable totals. That is financial and compliance-sensitive export data. The new exemption-reason overload is additive, but the deprecated BaseApp credit memo path can still export reduced payable totals because it never calls AddPaymentDiscountCompensation after collecting TempVATAmtLine.

Necessity: The compensation remains needed so Belgian payment discounts keep VAT on the discounted base while the amount payable stays whole. The scope is closer now, but it still needs the same compensation step in the deprecated BaseApp credit memo export path to keep invoice and credit memo behavior aligned.


[AI-PR-REVIEW] version=1 promptVersion=4 system=github pr=11037 round=2 by=alexei-dobriansky at=2026-09-08T14:58:14Z lastSha=762e263eafa46569c5b79be32e1dfa9cfccc804c reviewKey=2b28d8a07561c8811fe64de9dd9e2e9328bc7155f689426dc17a53015123c3a3 suggestions=S1@9bd62c83:addressed,S2@4a676ec8:addressed,S3@420035a2:notaddressed parentRound=1

@mynjj
Joshua (mynjj) enabled auto-merge (squash) September 9, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AL: Apps (W1) Add-on apps for W1 Team: Finance GitHub request for Finance area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants