Repository navigation
[Main]ERM Purchase Payables.UnreliazedGainLossEntrieAreClearWhenUsingMultiplePostingGroups fails (G/L account not balanced)- #13241 - #14574
Conversation
Good Sense Reviewer - Round 1Recommendation: Accept with SuggestionsWhat this PR doesChanges vendor application posting so unrealized gain/loss reversals can move to the original payables account when the aggregate uses another account. It also clears the full detailed-entry buffer and adds gain, loss, and unapply/reapply scenarios in four test copies. The transfer posts equal and opposite amounts only when the accounts differ. Unapplication collects reversing entries for the same transfer step, and the final Problem-solution fitFit: Partial The posting changes target the reported control-account imbalance. The setup-only explanation does not match the production changes, and direct coverage of the new transfer path is missing. SuggestionsS1 (🟠 Moderate): Explain the actual production posting changes S2 (🟠 Moderate): Exercise the new payables transfer branch Risk assessment and necessityRisk: Financially sensitive: codeunit 12 changes payables account distribution during application and unapplication in 11 BaseApp copies. The account and amount guards limit the new postings, with no public signature or table changes. The transfer branch still needs direct regression coverage; AL builds and tests were not run. Necessity: Without a correction, revalued invoices applied across vendor posting groups can leave control-account balances after full settlement. A focused posting and buffer-cleanup fix is justified.
|
| exit; | ||
|
|
||
| // Keep the unrealized reversal on the payable account that was originally revalued. | ||
| UnrealizedPayablesAccountNo := GetVendDtldCVLedgEntryBufferAccNo(GenJournalLine, DetailedCVLedgEntryBuffer); |
There was a problem hiding this comment.
The new unrealized gain/loss loop calls GetVendDtldCVLedgEntryBufferAccNo for every buffer row. That helper performs primary-key Gets on Vendor Ledger Entry and Vendor Posting Group, creating an unbounded per-row lookup pattern in the vendor posting hot path. Resolve the posting account with a set-based join or a correctly scoped reuse strategy before iterating, while preserving distinct posting-group results.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
Good Sense Reviewer - Round 2Recommendation: Accept with SuggestionsWhat this PR doesSince round 1, the change adds explicit length bounds to test arguments in CZ, FI, GB, and W1 and removes a setup-helper call that is not available in FI. Production posting code is unchanged in this round. These corrections leave the payment amounts, exchange rates, application flow, and balance assertions unchanged. The full change still targets unrealized gain/loss reversals across vendor posting groups, but the explanation and direct two-account transfer coverage remain incomplete. Problem-solution fitFit: Partial The posting changes target the residual payables balance. The setup-only explanation still omits those changes, and the tests do not directly cover the unequal-account transfer. Status of previous suggestions
New observations (commits since round 1)None - the new commit only corrects test setup and argument lengths. Risk assessment and necessityRisk: The latest changes affect tests only. The full change remains financially sensitive: vendor application and unapplication posting changes span 11 BaseApp copies, and the unequal-account transfer branch still lacks direct coverage. Public signatures and customer posting logic are unchanged. AL builds and tests were not run. Necessity: Without a posting correction, revalued invoices applied across different vendor posting groups can leave control-account balances after settlement. A focused correction is justified; the two existing suggestions remain open.
|
|
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| DetailedCVLedgEntryBuffer.SetFilter("Entry Type", '%1|%2', DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Gain", DetailedCVLedgEntryBuffer."Entry Type"::"Unrealized Loss"); | ||
| if DetailedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLine, DetailedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnPostDtldVendLedgEntriesOnBeforeCreateGLEntriesForTotalAmounts can suppress this required posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| CreateGLEntriesForTotalAmountsUnapply(GenJournalLineToPost, TempDimensionPostingBuffer, PayablesAccountNo); | ||
| if TempUnrealizedCVLedgEntryBuffer.FindSet() then | ||
| repeat | ||
| PostUnrealizedVendGainLossTransfer(GenJournalLineToPost, TempUnrealizedCVLedgEntryBuffer, PayablesAccountNo); |
There was a problem hiding this comment.
The newly added unrealized gain/loss transfer creates ledger entries inside the existing IsHandled guard, so a subscriber handling OnBeforeCreateGLEntriesForTotalAmountsUnapplyVendorV19 can suppress this required unapply posting operation. Keep the transfer outside the overridable guard or expose only a safe calculation to IsHandled.
Knowledge:
👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
| var | ||
| UnrealizedPayablesAccountNo: Code[20]; | ||
| begin | ||
| if DetailedCVLedgEntryBuffer."Amount (LCY)" = 0 then |
There was a problem hiding this comment.
The new guard exits whenever the unrealized entry's LCY amount is zero, even when its additional-currency amount is nonzero. In additional-currency posting, this skips both transfer G/L entries and leaves the unrealized gain or loss on the wrong payables account. Use the same LCY-or-additional-currency nonzero condition used by the surrounding posting logic; the identical guard is present in all 11 localized GenJnlPostLine files.
Suggested fix (apply manually — could not be anchored as a one-click suggestion):
if (DetailedCVLedgEntryBuffer."Amount (LCY)" = 0) and
((AddCurrencyCode = '') or (DetailedCVLedgEntryBuffer."Additional-Currency Amount" = 0))
then
exit;👍 useful · ❤️ especially valuable · 👎 wrong - reply with why · AL review agent v10.0.7
Bug 647653: [ALL-E]ERM Purchase Payables.UnreliazedGainLossEntrieAreClearWhenUsingMultiplePostingGroups fails (G/L account not balanced)
Fixes AB#647653
Issue: The UnreliazedGainLossEntrieAreClearWhenUsingMultiplePostingGroups test failed when applying a payment that used a different vendor posting group from the purchase invoice.
Cause: The test setup allowed the vendor posting group change from group 1 to group 2, but did not define the reverse alternate posting-group relationship. The application flow needs that relationship when matching the payment and invoice.
Solution: Added the reverse alternate vendor posting-group mapping, from group 2 to group 1. The test now passes with both directions configured.