From 36ec4a03f59e479b4b821b334c944e35e78408b2 Mon Sep 17 00:00:00 2001 From: Jose Antonio Garcia Garcia Date: Wed, 12 Aug 2026 11:18:26 +0200 Subject: [PATCH 1/6] [APAC] Keep vendor ACY on purchase invoice payables entry --- .../Posting/GenJnlPostLine.Codeunit.al | 3 +- .../Local/ERMMiscellaneousAPAC.Codeunit.al | 79 ++++++++++++++++++- 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 0e2d86cfd4c..4e7890475a6 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8163,7 +8163,8 @@ codeunit 12 "Gen. Jnl.-Post Line" GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, TotalAmountAddCurr) else InitGLEntry( - GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, 0, false, true, TotalAmountAddCurr); + GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, + CalcAmountSrcCurr(GenJnlLine, TotalAmountLCY)); end; end; diff --git a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al index dde693ca5ae..e00b1ca7762 100644 --- a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al +++ b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al @@ -814,6 +814,84 @@ codeunit 141008 "ERM - Miscellaneous APAC" PurchaseLine.Quantity * PurchaseLine."Direct Unit Cost" * PurchaseHeader."Vendor Exchange Rate (ACY)"); end; + [Test] + [Scope('OnPrem')] + procedure PurchaseInvoiceWithVendorACYPostsACYOnPayablesEntry() + var + Currency: Record Currency; + GLEntry: Record "G/L Entry"; + PurchaseHeader: Record "Purchase Header"; + PurchaseLine: Record "Purchase Line"; + PurchasesPayablesSetup: Record "Purchases & Payables Setup"; + CurrencyCode: Code[10]; + PayablesAccountNo: Code[20]; + PostedDocumentNo: Code[20]; + ExpectedACYAmount: Decimal; + begin + // [FEATURE] [Purchase] [ACY] + // [SCENARIO 641827] Vendor ACY is posted on the payables entry for a purchase invoice in LCY. + Initialize(); + LibrarySetupStorage.Save(DATABASE::"Purchases & Payables Setup"); + UpdateGeneralLedgerSetupGSTReport(); + + // [GIVEN] Vendor GST amounts in ACY are enabled and an Additional Reporting Currency is configured. + CurrencyCode := LibraryERM.CreateCurrencyWithRandomExchRates(); + Currency.Get(CurrencyCode); + PurchasesPayablesSetup.Get(); + PurchasesPayablesSetup."Enable Vendor GST Amount (ACY)" := true; + PurchasesPayablesSetup.Modify(); + LibraryERM.SetAddReportingCurrency(CurrencyCode); + + // [GIVEN] A purchase invoice in LCY with a vendor exchange rate for ACY. + CreatePurchDocWithLine( + PurchaseHeader, PurchaseLine, PurchaseHeader."Document Type"::Invoice, + PurchaseLine.Type::"G/L Account", LibraryERM.CreateGLAccountWithPurchSetup(), WorkDate()); + PurchaseHeader.TestField("Currency Code", ''); + PurchaseHeader."Vendor Exchange Rate (ACY)" := LibraryRandom.RandInt(10); + PurchaseHeader.Modify(); + ExpectedACYAmount := + PurchaseLine.Quantity * PurchaseLine."Direct Unit Cost" * PurchaseHeader."Vendor Exchange Rate (ACY)"; + + // [WHEN] The purchase invoice is posted. + PostedDocumentNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, false, true); + + // [THEN] The purchase and payables entries carry balancing ACY amounts. + GLEntry.SetRange("Document No.", PostedDocumentNo); + GLEntry.SetRange("G/L Account No.", PurchaseLine."No."); + Assert.RecordCount(GLEntry, 1); + GLEntry.FindFirst(); + + PayablesAccountNo := GetPayablesAccountFromVendorPostingGroup(PurchaseHeader."Pay-to Vendor No."); + GLEntry.Reset(); + GLEntry.SetRange("Document No.", PostedDocumentNo); + GLEntry.SetFilter( + "G/L Account No.", '<>%1&<>%2&<>%3', + PayablesAccountNo, Currency."Residual Gains Account", Currency."Residual Losses Account"); + GLEntry.CalcSums("Additional-Currency Amount"); + ExpectedACYAmount := GLEntry."Additional-Currency Amount"; + Assert.IsTrue(ExpectedACYAmount <> 0, AmountMustBeEqualMsg); + + GLEntry.SetRange("G/L Account No.", PayablesAccountNo); + Assert.RecordCount(GLEntry, 1); + GLEntry.FindFirst(); + GLEntry.TestField("Source Currency Code", ''); + GLEntry.TestField("Source Currency Amount", GLEntry.Amount); + GLEntry.TestField("Additional-Currency Amount", -ExpectedACYAmount); + + // [THEN] LCY, source currency, and ACY are balanced. + GLEntry.Reset(); + GLEntry.SetRange("Document No.", PostedDocumentNo); + GLEntry.CalcSums(Amount, "Source Currency Amount", "Additional-Currency Amount"); + Assert.AreEqual(0, GLEntry.Amount, AmountMustBeEqualMsg); + Assert.AreEqual(0, GLEntry."Source Currency Amount", AmountMustBeEqualMsg); + Assert.AreEqual(0, GLEntry."Additional-Currency Amount", AmountMustBeEqualMsg); + + // [THEN] No residual gains or losses entry is created. + GLEntry.SetFilter( + "G/L Account No.", '%1|%2', Currency."Residual Gains Account", Currency."Residual Losses Account"); + Assert.RecordCount(GLEntry, 0); + end; + [Test] [Scope('OnPrem')] procedure SalesOrderWithTwoLinesAndDeferralCreatesSingleGSTSalesEntry() @@ -2944,4 +3022,3 @@ codeunit 141008 "ERM - Miscellaneous APAC" SalesStatistics.OK().Invoke(); end; } - From 03c1023b74e0265e9235a6dacb8bfbd3810db3db Mon Sep 17 00:00:00 2001 From: Djordje Cenic Date: Wed, 12 Aug 2026 11:59:26 +0200 Subject: [PATCH 2/6] Improving the test, as per review comment --- .../APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al index e00b1ca7762..ac4e4c184cb 100644 --- a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al +++ b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al @@ -827,6 +827,7 @@ codeunit 141008 "ERM - Miscellaneous APAC" PayablesAccountNo: Code[20]; PostedDocumentNo: Code[20]; ExpectedACYAmount: Decimal; + NonPayablesACY: Decimal; begin // [FEATURE] [Purchase] [ACY] // [SCENARIO 641827] Vendor ACY is posted on the payables entry for a purchase invoice in LCY. @@ -855,12 +856,14 @@ codeunit 141008 "ERM - Miscellaneous APAC" // [WHEN] The purchase invoice is posted. PostedDocumentNo := LibraryPurchase.PostPurchaseDocument(PurchaseHeader, false, true); - // [THEN] The purchase and payables entries carry balancing ACY amounts. + // [THEN] The purchase (expense) G/L entry carries the vendor-rate ACY: Quantity * Direct Unit Cost * Vendor Exchange Rate (ACY). GLEntry.SetRange("Document No.", PostedDocumentNo); GLEntry.SetRange("G/L Account No.", PurchaseLine."No."); Assert.RecordCount(GLEntry, 1); GLEntry.FindFirst(); + GLEntry.TestField("Additional-Currency Amount", ExpectedACYAmount); + // [THEN] The payables (balancing) entry carries the offsetting ACY of all non-residual entries, in blank source currency. PayablesAccountNo := GetPayablesAccountFromVendorPostingGroup(PurchaseHeader."Pay-to Vendor No."); GLEntry.Reset(); GLEntry.SetRange("Document No.", PostedDocumentNo); @@ -868,15 +871,15 @@ codeunit 141008 "ERM - Miscellaneous APAC" "G/L Account No.", '<>%1&<>%2&<>%3', PayablesAccountNo, Currency."Residual Gains Account", Currency."Residual Losses Account"); GLEntry.CalcSums("Additional-Currency Amount"); - ExpectedACYAmount := GLEntry."Additional-Currency Amount"; - Assert.IsTrue(ExpectedACYAmount <> 0, AmountMustBeEqualMsg); + NonPayablesACY := GLEntry."Additional-Currency Amount"; + Assert.IsTrue(NonPayablesACY <> 0, AmountMustBeEqualMsg); GLEntry.SetRange("G/L Account No.", PayablesAccountNo); Assert.RecordCount(GLEntry, 1); GLEntry.FindFirst(); GLEntry.TestField("Source Currency Code", ''); GLEntry.TestField("Source Currency Amount", GLEntry.Amount); - GLEntry.TestField("Additional-Currency Amount", -ExpectedACYAmount); + GLEntry.TestField("Additional-Currency Amount", -NonPayablesACY); // [THEN] LCY, source currency, and ACY are balanced. GLEntry.Reset(); From 3f72dc7752d0e76d818059797abbe58f09878387 Mon Sep 17 00:00:00 2001 From: Djordje Cenic Date: Thu, 13 Aug 2026 10:45:16 +0200 Subject: [PATCH 3/6] [APAC] Keep vendor ACY on purchase invoice payables entry --- .../Posting/GenJnlPostLine.Codeunit.al | 27 ++++++++++++++++--- .../Local/ERMMiscellaneousAPAC.Codeunit.al | 1 - 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 4e7890475a6..be328d50ac9 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8162,12 +8162,33 @@ codeunit 12 "Gen. Jnl.-Post Line" InitGLEntry( GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, TotalAmountAddCurr) else - InitGLEntry( - GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, - CalcAmountSrcCurr(GenJnlLine, TotalAmountLCY)); + if VendorACYExchangeRateApplies() then + // [641827] With "Enable Vendor GST Amount (ACY)" the aggregated amount is the vendor-calculated + // ACY, which GLCalcAddCurrency keeps on the balancing entry. Derive the source-currency amount + // from LCY so the reporting currency stays balanced instead of posting a separate residual entry. + InitGLEntry( + GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, + CalcAmountSrcCurr(GenJnlLine, TotalAmountLCY)) + else + InitGLEntry( + GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, 0, false, true, TotalAmountAddCurr); end; end; + local procedure VendorACYExchangeRateApplies(): Boolean + var + PurchSetup: Record "Purchases & Payables Setup"; + begin + // Mirrors the vendor-ACY branch in GLCalcAddCurrency: only then does the balancing entry keep the + // aggregated amount as its Additional-Currency Amount, so only then must the Source Currency Amount be + // derived from LCY. In every other case the original behavior (Source Currency Amount = aggregated amount) + // must be preserved to keep Source Currency Consistency balanced. + if (AddCurrencyCode = '') or (not UseVendExchRate) then + exit(false); + PurchSetup.Get(); + exit(PurchSetup."Enable Vendor GST Amount (ACY)"); + end; + local procedure PostDtldAdjustment(GenJnlLine: Record "Gen. Journal Line"; var GLEntry: Record "G/L Entry"; AdjAmount: array[4] of Decimal; TotalAmountLCY: Decimal; TotalAmountAddCurr: Decimal; GLAcc: Code[20]; ArrayIndex: Integer): Boolean var IsHandled: Boolean; diff --git a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al index ac4e4c184cb..22771a5e942 100644 --- a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al +++ b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al @@ -832,7 +832,6 @@ codeunit 141008 "ERM - Miscellaneous APAC" // [FEATURE] [Purchase] [ACY] // [SCENARIO 641827] Vendor ACY is posted on the payables entry for a purchase invoice in LCY. Initialize(); - LibrarySetupStorage.Save(DATABASE::"Purchases & Payables Setup"); UpdateGeneralLedgerSetupGSTReport(); // [GIVEN] Vendor GST amounts in ACY are enabled and an Additional Reporting Currency is configured. From 7840016d4e3caa9d3e1a68a197f8b11753f62c4e Mon Sep 17 00:00:00 2001 From: Djordje Cenic Date: Fri, 14 Aug 2026 06:36:09 +0200 Subject: [PATCH 4/6] [APAC] Keep vendor ACY on purchase invoice payables entry --- .../GeneralLedger/Posting/GenJnlPostLine.Codeunit.al | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index be328d50ac9..1d3a96850b5 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8163,9 +8163,7 @@ codeunit 12 "Gen. Jnl.-Post Line" GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, TotalAmountAddCurr) else if VendorACYExchangeRateApplies() then - // [641827] With "Enable Vendor GST Amount (ACY)" the aggregated amount is the vendor-calculated - // ACY, which GLCalcAddCurrency keeps on the balancing entry. Derive the source-currency amount - // from LCY so the reporting currency stays balanced instead of posting a separate residual entry. + // [641827] GLCalcAddCurrency keeps the vendor ACY here, so derive Source Currency Amount from LCY. InitGLEntry( GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, CalcAmountSrcCurr(GenJnlLine, TotalAmountLCY)) @@ -8179,12 +8177,10 @@ codeunit 12 "Gen. Jnl.-Post Line" var PurchSetup: Record "Purchases & Payables Setup"; begin - // Mirrors the vendor-ACY branch in GLCalcAddCurrency: only then does the balancing entry keep the - // aggregated amount as its Additional-Currency Amount, so only then must the Source Currency Amount be - // derived from LCY. In every other case the original behavior (Source Currency Amount = aggregated amount) - // must be preserved to keep Source Currency Consistency balanced. + // Mirrors GLCalcAddCurrency's vendor-ACY branch so the balancing entry's Source Currency Amount matches its ACY. if (AddCurrencyCode = '') or (not UseVendExchRate) then exit(false); + PurchSetup.SetLoadFields("Enable Vendor GST Amount (ACY)"); PurchSetup.Get(); exit(PurchSetup."Enable Vendor GST Amount (ACY)"); end; @@ -8456,6 +8452,8 @@ codeunit 12 "Gen. Jnl.-Post Line" GLEntry: Record "G/L Entry"; IsHandled: Boolean; begin + // General balancing entries are never the vendor-ACY case; clear the transient flag so leftover state cannot select it. + UseVendExchRate := false; HandleDtldAdjustment(GenJnlLine, GLEntry, AdjAmountBuf, Amount, AmountACY, GLAccNo); GLEntry."Bal. Account Type" := GenJnlLine."Bal. Account Type"; GLEntry."Bal. Account No." := GenJnlLine."Bal. Account No."; From 524e03418f128d562ab343002462c68665bff87f Mon Sep 17 00:00:00 2001 From: Djordje Cenic Date: Fri, 14 Aug 2026 10:14:06 +0200 Subject: [PATCH 5/6] Implementing review comments --- .../Posting/GenJnlPostLine.Codeunit.al | 21 ++++++++++++++----- .../Local/ERMMiscellaneousAPAC.Codeunit.al | 7 +++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 1d3a96850b5..0abb1685bd1 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -188,6 +188,8 @@ codeunit 12 "Gen. Jnl.-Post Line" HadWHTEntryNo: Boolean; NextNo: Integer; UseVendExchRate: Boolean; + VendGSTAmountACYEnabled: Boolean; + VendGSTAmountACYRead: Boolean; Text28000: Label 'No Matching Document'; CheckRem: Boolean; IsReversal: Boolean; @@ -8174,15 +8176,24 @@ codeunit 12 "Gen. Jnl.-Post Line" end; local procedure VendorACYExchangeRateApplies(): Boolean - var - PurchSetup: Record "Purchases & Payables Setup"; begin // Mirrors GLCalcAddCurrency's vendor-ACY branch so the balancing entry's Source Currency Amount matches its ACY. if (AddCurrencyCode = '') or (not UseVendExchRate) then exit(false); - PurchSetup.SetLoadFields("Enable Vendor GST Amount (ACY)"); - PurchSetup.Get(); - exit(PurchSetup."Enable Vendor GST Amount (ACY)"); + exit(GetVendGSTAmountACYEnabled()); + end; + + local procedure GetVendGSTAmountACYEnabled(): Boolean + var + PurchSetup: Record "Purchases & Payables Setup"; + begin + if not VendGSTAmountACYRead then begin + PurchSetup.SetLoadFields("Enable Vendor GST Amount (ACY)"); + PurchSetup.Get(); + VendGSTAmountACYEnabled := PurchSetup."Enable Vendor GST Amount (ACY)"; + VendGSTAmountACYRead := true; + end; + exit(VendGSTAmountACYEnabled); end; local procedure PostDtldAdjustment(GenJnlLine: Record "Gen. Journal Line"; var GLEntry: Record "G/L Entry"; AdjAmount: array[4] of Decimal; TotalAmountLCY: Decimal; TotalAmountAddCurr: Decimal; GLAcc: Code[20]; ArrayIndex: Integer): Boolean diff --git a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al index 22771a5e942..99e04ee333f 100644 --- a/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al +++ b/src/Layers/APAC/Tests/Local/ERMMiscellaneousAPAC.Codeunit.al @@ -828,6 +828,7 @@ codeunit 141008 "ERM - Miscellaneous APAC" PostedDocumentNo: Code[20]; ExpectedACYAmount: Decimal; NonPayablesACY: Decimal; + OriginalVendorGSTAmountACY: Boolean; begin // [FEATURE] [Purchase] [ACY] // [SCENARIO 641827] Vendor ACY is posted on the payables entry for a purchase invoice in LCY. @@ -838,6 +839,7 @@ codeunit 141008 "ERM - Miscellaneous APAC" CurrencyCode := LibraryERM.CreateCurrencyWithRandomExchRates(); Currency.Get(CurrencyCode); PurchasesPayablesSetup.Get(); + OriginalVendorGSTAmountACY := PurchasesPayablesSetup."Enable Vendor GST Amount (ACY)"; PurchasesPayablesSetup."Enable Vendor GST Amount (ACY)" := true; PurchasesPayablesSetup.Modify(); LibraryERM.SetAddReportingCurrency(CurrencyCode); @@ -892,6 +894,11 @@ codeunit 141008 "ERM - Miscellaneous APAC" GLEntry.SetFilter( "G/L Account No.", '%1|%2', Currency."Residual Gains Account", Currency."Residual Losses Account"); Assert.RecordCount(GLEntry, 0); + + // The flag is not registered in setup storage, so restore its original value to avoid leaking into later tests. + PurchasesPayablesSetup.Get(); + PurchasesPayablesSetup."Enable Vendor GST Amount (ACY)" := OriginalVendorGSTAmountACY; + PurchasesPayablesSetup.Modify(); end; [Test] From 68c4e5b82181f2f1abc811558741c59de55a46a9 Mon Sep 17 00:00:00 2001 From: Djordje Cenic Date: Fri, 14 Aug 2026 15:34:01 +0200 Subject: [PATCH 6/6] [APAC] Keep vendor ACY on purchase invoice payables entry --- .../Posting/GenJnlPostLine.Codeunit.al | 28 +++++++------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 0abb1685bd1..cd78c00ef29 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -188,8 +188,6 @@ codeunit 12 "Gen. Jnl.-Post Line" HadWHTEntryNo: Boolean; NextNo: Integer; UseVendExchRate: Boolean; - VendGSTAmountACYEnabled: Boolean; - VendGSTAmountACYRead: Boolean; Text28000: Label 'No Matching Document'; CheckRem: Boolean; IsReversal: Boolean; @@ -8164,7 +8162,7 @@ codeunit 12 "Gen. Jnl.-Post Line" InitGLEntry( GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, TotalAmountAddCurr) else - if VendorACYExchangeRateApplies() then + if VendorACYExchangeRateApplies(GenJnlLine) then // [641827] GLCalcAddCurrency keeps the vendor ACY here, so derive Source Currency Amount from LCY. InitGLEntry( GenJnlLine, GLEntry, GLAccNo, TotalAmountLCY, TotalAmountAddCurr, true, true, @@ -8175,25 +8173,19 @@ codeunit 12 "Gen. Jnl.-Post Line" end; end; - local procedure VendorACYExchangeRateApplies(): Boolean + local procedure VendorACYExchangeRateApplies(GenJnlLine: Record "Gen. Journal Line"): Boolean + var + PurchSetup: Record "Purchases & Payables Setup"; begin // Mirrors GLCalcAddCurrency's vendor-ACY branch so the balancing entry's Source Currency Amount matches its ACY. if (AddCurrencyCode = '') or (not UseVendExchRate) then exit(false); - exit(GetVendGSTAmountACYEnabled()); - end; - - local procedure GetVendGSTAmountACYEnabled(): Boolean - var - PurchSetup: Record "Purchases & Payables Setup"; - begin - if not VendGSTAmountACYRead then begin - PurchSetup.SetLoadFields("Enable Vendor GST Amount (ACY)"); - PurchSetup.Get(); - VendGSTAmountACYEnabled := PurchSetup."Enable Vendor GST Amount (ACY)"; - VendGSTAmountACYRead := true; - end; - exit(VendGSTAmountACYEnabled); + if GenJnlLine."Additional-Currency Posting" <> GenJnlLine."Additional-Currency Posting"::None then + exit(false); + // Read fresh, like GLCalcAddCurrency, so a mid-batch setup change is not masked by a cached value. + PurchSetup.SetLoadFields("Enable Vendor GST Amount (ACY)"); + PurchSetup.Get(); + exit(PurchSetup."Enable Vendor GST Amount (ACY)"); end; local procedure PostDtldAdjustment(GenJnlLine: Record "Gen. Journal Line"; var GLEntry: Record "G/L Entry"; AdjAmount: array[4] of Decimal; TotalAmountLCY: Decimal; TotalAmountAddCurr: Decimal; GLAcc: Code[20]; ArrayIndex: Integer): Boolean