Skip to content

Add VAT rate resolution and VAT amount difference for E-Document purchases#8251

Merged
ventselartur merged 71 commits into
mainfrom
private/ventselartur/PayablesAgentVATSpike
May 24, 2026
Merged

Add VAT rate resolution and VAT amount difference for E-Document purchases#8251
ventselartur merged 71 commits into
mainfrom
private/ventselartur/PayablesAgentVATSpike

Conversation

@ventselartur
Copy link
Copy Markdown
Contributor

@ventselartur ventselartur commented May 20, 2026

Why

When importing e-documents for purchase processing, the system did not automatically resolve VAT Product Posting Groups from extracted VAT rates. Users had to manually identify and assign the correct VAT posting group for each line, which was error-prone and time-consuming. Additionally, rounding differences between the document's total VAT and the computed line-level VAT amounts were not reconciled, leading to posting discrepancies.

Summary

  • Added VAT Product Posting Group resolution during Prepare Draft — matches the extracted VAT rate against VAT Posting Setup entries (Normal VAT and Reverse Charge VAT only) for the vendor's VAT Bus. Posting Group
  • Added [BC] VAT Prod. Posting Group and [BC] VAT Rate Mismatch fields on E-Document Purchase Line with OnValidate/OnLookup support
  • Added VAT amount difference computation and application to purchase lines when finalizing drafts, respecting Allow VAT Difference and Max. VAT Difference Allowed settings
  • Added "Resolve VAT Group Purch EDoc" and "Apply VAT Diff. For Purch EDoc" toggles on Purchases & Payables Setup
  • Improved ADI handler to prefer the unambiguous taxRate field and properly disambiguate the tax field between percentage and monetary values
  • Added comprehensive test codeunit E-Doc Purch. VAT Tests covering resolution, mismatch detection, OnValidate behavior, and VAT calculation type filtering
  • Updated existing structured validation tests to reflect corrected VAT rate expectations

Fixes AB#619564

ventselartur and others added 30 commits March 29, 2026 21:28
…Line

Prefer TaxRate (string, unambiguous percentage) over Tax (currency,
ambiguous). Fall back to computing Tax/Amount*100 only when Tax
contains a monetary amount (no % in value_text).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds enum value 2 ("VAT Rate Mismatch") to E-Document Notification Type,
with parallel Add/Dismiss/Disable procedures in the notification codeunit
and an updated SendPurchaseDocumentDraftNotifications that fans out to both
notification types via SetFilter.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Prepare Draft

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…nvoice line

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…repare Draft

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replaces the notification banner approach with a persisted boolean
field and an inline warning column on the draft subform, following
the PO matching warning pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…racted rate

Instead of blindly clearing the mismatch flag when any posting group
is selected, look up the VAT Posting Setup and compare its VAT %
against the line's extracted VAT Rate. Only clear the warning when
the rates actually match.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…date

Remove rounding tolerance — compare VAT % from setup against extracted
rate with exact equality. Zero-rate lines also go through the comparison
instead of being skipped.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The lookup opens the VAT Posting Setup page filtered by the vendor's
VAT Bus. Posting Group so the user only sees relevant combinations.
Selection runs through Validate to trigger mismatch re-evaluation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Full VAT and Sales Tax do not use VAT % for rate-based matching.
Filter FindVATProductPostingGroup, OnValidate, and OnLookup to
exclude those calculation types.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…alidate

Tests cover: Full VAT and Sales Tax ignored during Prepare Draft,
Reverse Charge VAT resolved, OnValidate clears/keeps mismatch based
on rate comparison, mismatch set when clearing posting group, Full VAT
skips comparison, and zero-rate matching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
7 tasks covering: table field + triggers, Prepare Draft refactor,
subform warning column, notification removal, and 9 tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…. Posting Group

Field 111 [BC] VAT Rate Mismatch persists whether VAT resolution failed.
OnValidate re-evaluates mismatch by comparing VAT Posting Setup rate
against extracted rate, filtering to Normal/Reverse Charge VAT only.
OnLookup opens VAT Posting Setup filtered by vendor's bus posting group.
…re Draft

Replace HasUnresolvedVATLines + notification call with direct
[BC] VAT Rate Mismatch field assignment. Filter FindVATProductPostingGroup
to Normal VAT and Reverse Charge VAT calculation types only.
Per-line warning with Ambiguous styling, conditional visibility when
any line has a mismatch, and drill-down showing the extracted VAT rate.
Follows the PO matching warning pattern.
Notification replaced by persisted [BC] VAT Rate Mismatch field
and inline warning column on draft subform.
…notification

Rename and rewrite the mismatch test to assert [BC] VAT Rate Mismatch
boolean. Add mismatch=false assertion to the successful resolution test.
Full VAT and Sales Tax setups are excluded from resolution.
Reverse Charge VAT setups are matched successfully.
Covers: rate match clears mismatch, rate mismatch persists,
clearing group sets mismatch, Full VAT skips comparison,
zero-rate matching works.
Extract 10 VAT-related test procedures into new codeunit 139896
for better organization. No test logic changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

$\textbf{🟡\ Medium\ Severity\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

All three VAT rate assertions changed to same value

Three separate line assertions (originally 6, 3, 1) have all been changed to 10 without a corresponding update to the mock ADI test data source. This suggests the new taxRate field in the mock always returns a single fixed value, meaning the new disambiguation logic (ResolveVATRateFromADI) is not meaningfully exercised by these tests—different code paths (percentage string, percentage currency, monetary tax) remain uncovered.

Recommendation:

  • Update the mock ADI test fixture to provide distinct and realistic tax/taxRate values per line (e.g., a percentage string, a percentage currency value, and a monetary amount) so that each branch of ResolveVATRateFromADI is tested individually.
// In mock data for line 1: taxRate = "20%"  → expected VAT Rate = 20
// In mock data for line 2: tax as currency "6.00" + sub total 100 → expected VAT Rate = 6
// In mock data for line 3: taxRate = "VAT 5" → expected VAT Rate = 5
Assert.AreEqual(20, EDocumentPurchaseLine."VAT Rate", 'Line 1 VAT rate mismatch');

Line mapping was unavailable, so this was posted as an issue comment.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

Groenbech96
Groenbech96 previously approved these changes May 22, 2026
Copy link
Copy Markdown
Contributor

@Groenbech96 Groenbech96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work.

@github-actions
Copy link
Copy Markdown
Contributor

$\textbf{🟡\ Medium\ Severity\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Misleading Procedure Name: No 'Apply' Happens

ComputeAndApplyVATAmountDifference() computes the VAT diff and logs it, but does not actually apply it to any line — that happens later in ApplyVATDifferenceToLines(). The name implies a side-effect that does not occur here, which is confusing for future maintainers.

Recommendation:

  • Rename the procedure to reflect its actual behavior, e.g., ComputeAndLogVATAmountDifference().
    local procedure ComputeAndLogVATAmountDifference(EDocumentPurchaseHeader: Record "E-Document Purchase Header"; TotalLineVATAmount: Decimal)

Line mapping was unavailable, so this was posted as an issue comment.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

@github-actions
Copy link
Copy Markdown
Contributor

$\textbf{🟡\ Medium\ Severity\ —\ Style} \quad \color{gray}{\texttt{\small Iteration\ 1}}$

Missing Newline at End of File

The file ends without a trailing newline (git diff shows '\ No newline at end of file'). This causes noise in diffs, breaks some Unix tooling, and violates the repo's consistent file formatting.

Recommendation:

  • Add a newline character after the closing } of the codeunit.
}

Line mapping was unavailable, so this was posted as an issue comment.

👍 useful · ❤️ especially valuable · 👎 wrong - reply with why

Comment thread src/Apps/W1/EDocument/App/src/Setup/EDocumentUpgrade.Codeunit.al
Comment thread src/Apps/W1/EDocument/App/src/Setup/EDocumentUpgrade.Codeunit.al
@ventselartur ventselartur requested review from a team as code owners May 22, 2026 19:03
@ventselartur ventselartur enabled auto-merge (squash) May 23, 2026 18:47
@ventselartur ventselartur merged commit e4b017f into main May 24, 2026
83 of 86 checks passed
@ventselartur ventselartur deleted the private/ventselartur/PayablesAgentVATSpike branch May 24, 2026 20:50
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants