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 343cefe325e..dbfbcbff692 100644 --- a/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/APAC/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -11096,9 +11096,12 @@ codeunit 12 "Gen. Jnl.-Post Line" if GenJnlLine."Source Curr. VAT Base Amount" <> 0 then exit(GenJnlLine."Source Curr. VAT Base Amount" + CalcAmountSrcCurr(GenJnlLine, WHTAmountLCY)) else - exit(GenJnlLine."Source Currency Amount" + CalcAmountSrcCurr(GenJnlLine, WHTAmountLCY)); + exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)" + WHTAmountLCY)); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - WHTAmountLCY)) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - WHTAmountLCY); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] @@ -13711,4 +13714,4 @@ codeunit 12 "Gen. Jnl.-Post Line" local procedure OnPostEmployeeAfterTempDtldCVLedgEntryBufInit(var GenJnlLine: Record "Gen. Journal Line"; var TempDtldCVLedgEntryBuf: Record "Detailed CV Ledg. Entry Buffer" temporary; TaxAmount: Decimal; TaxBaseAmount: Decimal) begin end; -} \ No newline at end of file +} diff --git a/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 9f8b85eb843..e46d1dc74ec 100644 --- a/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/BE/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8686,7 +8686,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 1baf81c739a..75ecc18f66e 100644 --- a/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/CH/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8708,7 +8708,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/CZ/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al b/src/Layers/CZ/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al index 89bc73c6c7d..5ec304d3bf2 100644 --- a/src/Layers/CZ/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al +++ b/src/Layers/CZ/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al @@ -1412,6 +1412,57 @@ codeunit 134897 "ERM Source Currency" Assert.AreEqual(0, SourceCurrencyBalance, TotalSCYAmountNotZeroErr); end; + [Test] + procedure SalesInvoiceLCYWithPaymentMethodBalAccountPosting() + var + Customer: Record Customer; + GeneralLedgerSetup: Record "General Ledger Setup"; + ExistingGeneralLedgerSetup: Record "General Ledger Setup"; + PaymentMethod: Record "Payment Method"; + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + SalesPost: Codeunit "Sales-Post"; + begin + // [SCENARIO] An LCY sales invoice with a payment method balancing account can be previewed when source currency consistency is enabled. + Initialize(); + + // [FEATURE] [AI test] + // [GIVEN] Source currency consistency and extended posting preview are enabled. + GeneralLedgerSetup.Get(); + ExistingGeneralLedgerSetup := GeneralLedgerSetup; + GeneralLedgerSetup.Validate("Check Source Curr. Consistency", true); + GeneralLedgerSetup.Modify(true); + + // [GIVEN] A payment method with a G/L balancing account and payment terms without a payment discount. + LibraryERM.CreatePaymentMethod(PaymentMethod); + PaymentMethod.Validate("Bal. Account Type", PaymentMethod."Bal. Account Type"::"G/L Account"); + PaymentMethod.Validate("Bal. Account No.", LibraryERM.CreateGLAccountNoWithDirectPosting()); + PaymentMethod.Modify(true); + + // [GIVEN] A customer whose payment method and payment terms flow to a new LCY sales invoice. + LibrarySales.CreateCustomer(Customer); + Customer.Validate("Payment Method Code", PaymentMethod.Code); + Customer.Modify(true); + + LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Invoice, Customer."No."); + SalesHeader.TestField("Currency Code", ''); + SalesHeader.TestField("Payment Method Code", PaymentMethod.Code); + + LibrarySales.CreateSalesLine( + SalesLine, SalesHeader, SalesLine.Type::"G/L Account", LibraryERM.CreateGLAccountWithSalesSetup(), 1); + SalesLine.Validate("Unit Price", LibraryRandom.RandDecInRange(100, 200, 2)); + SalesLine.Modify(true); + + // [WHEN] Posting the salesinvoice. + SalesPost.Run(SalesHeader); + + // [THEN] The posting completes without a source currency consistency error. + + //reset General Ledger Setup to original values + GeneralLedgerSetup := ExistingGeneralLedgerSetup; + GeneralLedgerSetup.Modify(); + end; + [Test] procedure SalesInvoiceFCYWithExchRateAdjmtAndPayment() var diff --git a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index a00c86803a1..dc6bd0150f5 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -10333,7 +10333,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al b/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al index c029fac6134..566a2ee62ab 100644 --- a/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al +++ b/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al @@ -1413,6 +1413,57 @@ codeunit 134897 "ERM Source Currency" Assert.AreEqual(0, SourceCurrencyBalance, TotalSCYAmountNotZeroErr); end; + [Test] + procedure SalesInvoiceLCYWithPaymentMethodBalAccountPosting() + var + Customer: Record Customer; + GeneralLedgerSetup: Record "General Ledger Setup"; + ExistingGeneralLedgerSetup: Record "General Ledger Setup"; + PaymentMethod: Record "Payment Method"; + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + SalesPost: Codeunit "Sales-Post"; + begin + // [SCENARIO] An LCY sales invoice with a payment method balancing account can be previewed when source currency consistency is enabled. + Initialize(); + + // [FEATURE] [AI test] + // [GIVEN] Source currency consistency and extended posting preview are enabled. + GeneralLedgerSetup.Get(); + ExistingGeneralLedgerSetup := GeneralLedgerSetup; + GeneralLedgerSetup.Validate("Check Source Curr. Consistency", true); + GeneralLedgerSetup.Modify(true); + + // [GIVEN] A payment method with a G/L balancing account and payment terms without a payment discount. + LibraryERM.CreatePaymentMethod(PaymentMethod); + PaymentMethod.Validate("Bal. Account Type", PaymentMethod."Bal. Account Type"::"G/L Account"); + PaymentMethod.Validate("Bal. Account No.", LibraryERM.CreateGLAccountNoWithDirectPosting()); + PaymentMethod.Modify(true); + + // [GIVEN] A customer whose payment method and payment terms flow to a new LCY sales invoice. + LibrarySales.CreateCustomer(Customer); + Customer.Validate("Payment Method Code", PaymentMethod.Code); + Customer.Modify(true); + + LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Invoice, Customer."No."); + SalesHeader.TestField("Currency Code", ''); + SalesHeader.TestField("Payment Method Code", PaymentMethod.Code); + + LibrarySales.CreateSalesLine( + SalesLine, SalesHeader, SalesLine.Type::"G/L Account", LibraryERM.CreateGLAccountWithSalesSetup(), 1); + SalesLine.Validate("Unit Price", LibraryRandom.RandDecInRange(100, 200, 2)); + SalesLine.Modify(true); + + // [WHEN] Posting the salesinvoice. + SalesPost.Run(SalesHeader); + + // [THEN] The posting completes without a source currency consistency error. + + //reset General Ledger Setup to original values + GeneralLedgerSetup := ExistingGeneralLedgerSetup; + GeneralLedgerSetup.Modify(); + end; + [Test] procedure SalesInvoiceFCYWithExchRateAdjmtAndPayment() var diff --git a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 5c55bf6568b..c5cda66ed9a 100644 --- a/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/FI/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8709,7 +8709,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index c00b24ed602..9c0a80eee70 100644 --- a/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/FR/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -9012,7 +9012,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 5ef8f4059e5..2580e43d066 100644 --- a/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/IT/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -9688,7 +9688,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/IT/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al b/src/Layers/IT/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al index 20de9299944..baca8350c9a 100644 --- a/src/Layers/IT/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al +++ b/src/Layers/IT/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al @@ -1650,6 +1650,57 @@ codeunit 134897 "ERM Source Currency" Assert.AreEqual(0, SourceCurrencyBalance, TotalSCYAmountNotZeroErr); end; + [Test] + procedure SalesInvoiceLCYWithPaymentMethodBalAccountPosting() + var + Customer: Record Customer; + GeneralLedgerSetup: Record "General Ledger Setup"; + ExistingGeneralLedgerSetup: Record "General Ledger Setup"; + PaymentMethod: Record "Payment Method"; + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + SalesPost: Codeunit "Sales-Post"; + begin + // [SCENARIO] An LCY sales invoice with a payment method balancing account can be previewed when source currency consistency is enabled. + Initialize(); + + // [FEATURE] [AI test] + // [GIVEN] Source currency consistency and extended posting preview are enabled. + GeneralLedgerSetup.Get(); + ExistingGeneralLedgerSetup := GeneralLedgerSetup; + GeneralLedgerSetup.Validate("Check Source Curr. Consistency", true); + GeneralLedgerSetup.Modify(true); + + // [GIVEN] A payment method with a G/L balancing account and payment terms without a payment discount. + LibraryERM.CreatePaymentMethod(PaymentMethod); + PaymentMethod.Validate("Bal. Account Type", PaymentMethod."Bal. Account Type"::"G/L Account"); + PaymentMethod.Validate("Bal. Account No.", LibraryERM.CreateGLAccountNoWithDirectPosting()); + PaymentMethod.Modify(true); + + // [GIVEN] A customer whose payment method and payment terms flow to a new LCY sales invoice. + LibrarySales.CreateCustomer(Customer); + Customer.Validate("Payment Method Code", PaymentMethod.Code); + Customer.Modify(true); + + LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Invoice, Customer."No."); + SalesHeader.TestField("Currency Code", ''); + SalesHeader.TestField("Payment Method Code", PaymentMethod.Code); + + LibrarySales.CreateSalesLine( + SalesLine, SalesHeader, SalesLine.Type::"G/L Account", LibraryERM.CreateGLAccountWithSalesSetup(), 1); + SalesLine.Validate("Unit Price", LibraryRandom.RandDecInRange(100, 200, 2)); + SalesLine.Modify(true); + + // [WHEN] Posting the salesinvoice. + SalesPost.Run(SalesHeader); + + // [THEN] The posting completes without a source currency consistency error. + + //reset General Ledger Setup to original values + GeneralLedgerSetup := ExistingGeneralLedgerSetup; + GeneralLedgerSetup.Modify(); + end; + [Test] procedure SalesInvoiceFCYWithExchRateAdjmtAndPayment() var diff --git a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 5f0c0bd2552..36ce8940e66 100644 --- a/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/NA/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -9125,7 +9125,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 064c4165f3f..d7ad5ebd092 100644 --- a/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/NO/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8747,7 +8747,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 71f0201e34a..cb97fa9d196 100644 --- a/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/RU/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -11175,7 +11175,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/RU/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al b/src/Layers/RU/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al index 5eadc4c7c57..58ddd8e775b 100644 --- a/src/Layers/RU/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al +++ b/src/Layers/RU/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al @@ -1802,3 +1802,4 @@ codeunit 134897 "ERM Source Currency" end; } + diff --git a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al index 30f2ba744e7..e338d9d9c0c 100644 --- a/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/W1/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -8643,7 +8643,10 @@ codeunit 12 "Gen. Jnl.-Post Line" else exit(GenJnlLine."Source Currency Amount"); end else - exit(CalcAmountSrcCurr(GenJnlLine, GenJnlLine."VAT Base Amount (LCY)")); + if (GenJnlLine."Source Currency amount" <> (GenJnlLine.Amount - GenJnlLine."VAT Amount")) and (GenJnlLine."Source Currency Amount" <> 0) then + exit(GenJnlLine."Source Currency amount") + else + exit(GenJnlLine.Amount - GenJnlLine."VAT Amount"); end; local procedure GetVendorPayablesAccount2(var DetailedCVLedgEntryBuffer: Record "Detailed CV Ledg. Entry Buffer"; var GenJournalLine: Record "Gen. Journal Line"; VendPostingGr: Record "Vendor Posting Group"): Code[20] diff --git a/src/Layers/W1/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al b/src/Layers/W1/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al index 5a2812a7e0a..b95a58d50ae 100644 --- a/src/Layers/W1/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al +++ b/src/Layers/W1/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al @@ -1639,6 +1639,57 @@ codeunit 134897 "ERM Source Currency" Assert.AreEqual(0, SourceCurrencyBalance, TotalSCYAmountNotZeroErr); end; + [Test] + procedure SalesInvoiceLCYWithPaymentMethodBalAccountPosting() + var + Customer: Record Customer; + GeneralLedgerSetup: Record "General Ledger Setup"; + ExistingGeneralLedgerSetup: Record "General Ledger Setup"; + PaymentMethod: Record "Payment Method"; + SalesHeader: Record "Sales Header"; + SalesLine: Record "Sales Line"; + SalesPost: Codeunit "Sales-Post"; + begin + // [SCENARIO] An LCY sales invoice with a payment method balancing account can be previewed when source currency consistency is enabled. + Initialize(); + + // [FEATURE] [AI test] + // [GIVEN] Source currency consistency and extended posting preview are enabled. + GeneralLedgerSetup.Get(); + ExistingGeneralLedgerSetup := GeneralLedgerSetup; + GeneralLedgerSetup.Validate("Check Source Curr. Consistency", true); + GeneralLedgerSetup.Modify(true); + + // [GIVEN] A payment method with a G/L balancing account and payment terms without a payment discount. + LibraryERM.CreatePaymentMethod(PaymentMethod); + PaymentMethod.Validate("Bal. Account Type", PaymentMethod."Bal. Account Type"::"G/L Account"); + PaymentMethod.Validate("Bal. Account No.", LibraryERM.CreateGLAccountNoWithDirectPosting()); + PaymentMethod.Modify(true); + + // [GIVEN] A customer whose payment method and payment terms flow to a new LCY sales invoice. + LibrarySales.CreateCustomer(Customer); + Customer.Validate("Payment Method Code", PaymentMethod.Code); + Customer.Modify(true); + + LibrarySales.CreateSalesHeader(SalesHeader, SalesHeader."Document Type"::Invoice, Customer."No."); + SalesHeader.TestField("Currency Code", ''); + SalesHeader.TestField("Payment Method Code", PaymentMethod.Code); + + LibrarySales.CreateSalesLine( + SalesLine, SalesHeader, SalesLine.Type::"G/L Account", LibraryERM.CreateGLAccountWithSalesSetup(), 1); + SalesLine.Validate("Unit Price", LibraryRandom.RandDecInRange(100, 200, 2)); + SalesLine.Modify(true); + + // [WHEN] Posting the salesinvoice. + SalesPost.Run(SalesHeader); + + // [THEN] The posting completes without a source currency consistency error. + + //reset General Ledger Setup to original values + GeneralLedgerSetup := ExistingGeneralLedgerSetup; + GeneralLedgerSetup.Modify(); + end; + [Test] procedure SalesInvoiceFCYWithExchRateAdjmtAndPayment() var