[Main]- Mismatch between Purchase Invoice Total in Lines and Statistics after VAT adjustment - #10178
Conversation
| TotalPurchaseLine := TotalPurchaseLine2; | ||
| end; | ||
|
|
||
| local procedure TryGetGroupedVATAmount(var PurchHeader: Record "Purchase Header"; var GroupedVATAmount: Decimal): Boolean |
There was a problem hiding this comment.
TryGetGroupedVATAmount rebuilds grouped VAT by calling CalcVATAmountLines over the full document, and this helper is now invoked from both PurchaseDeltaUpdateTotals (the incremental/delta update path) and CalculatePurchaseSubPageTotals. Because it runs unconditionally on every line edit rather than only for the mixed-VAT-groups-on-one-G/L-account scenario the fix targets, each delta update can trigger an extra full Purchase Line scan and VAT regrouping pass, defeating the purpose of the 'delta' optimization.
Recommendation:
- gate the recomputation to cases where it is actually needed (e.g. detect mixed VAT groups on the same account) or cache/reuse the grouped result instead of recalculating on every call.
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
| begin | ||
| LibraryPurchase.CreatePurchaseLine( | ||
| PurchaseLine, PurchaseHeader, PurchaseLine.Type::"G/L Account", GLAccountNo, 1); | ||
| PurchaseLine."VAT Bus. Posting Group" := VATPostingSetup."VAT Bus. Posting Group"; |
There was a problem hiding this comment.
CreatePurchLineWithGLAccAndVATSetup assigns PurchaseLine."VAT Bus. Posting Group" directly while building the fixture. That bypasses the field's TableRelation and OnValidate logic, so the test data can drift from production behavior when VAT setup validation changes.
Suggested fix (apply manually — could not be anchored as a one-click suggestion):
PurchaseLine.Validate("VAT Bus. Posting Group", VATPostingSetup."VAT Bus. Posting Group");Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v1.32.4
Agentic PR Review - Round 1Recommendation: Request ChangesWhat this PR doesThis PR recalculates purchase document totals from grouped VAT amount lines after a VAT amount is changed on the Purchase Statistics page. The main W1 scenario is valid and the new W1 test targets the reported mixed-VAT purchase invoice case, but the same change was copied into BE where Document Totals has extra reverse-charge and non-deductible VAT adjustments. The new grouped VAT overwrite runs after those adjustments and can undo them, so the fix is not safe for all changed layers. SuggestionsS1 - Preserve BE VAT total adjustments S2 - Fix the new variable order warning Risk assessment and necessityRisk: The touched code is in purchase document totals, so the regression surface is financial UI totals for purchase invoices and related purchase documents. The BE layer is higher risk because its existing reverse-charge and non-deductible VAT logic is overwritten by the new generic grouped VAT value. CI also shows W1 build failures from a new analyzer warning. Necessity: The bug is valid: after a manual VAT adjustment, the line totals should match the Purchase Statistics total that posting uses. The scope is reasonable for W1 and NA, but the BE copy must preserve local VAT rules before this can be merged.
|
…Bug-642172-Mismatch-between-Purchase-Invoice-Total-and-Statistics
Workitem Bug 642172: [master] [all-e]Mismatch between Purchase Invoice Total in Lines and Statistics after VAT adjustment.
Fixes AB#642172