diff --git a/src/DisabledTests/Expense_Agent_Tests/Expense_Agent_Tests.DisabledTest.json b/src/DisabledTests/Expense_Agent_Tests/Expense_Agent_Tests.DisabledTest.json index f1181ff4635..9d1b6f9a519 100644 --- a/src/DisabledTests/Expense_Agent_Tests/Expense_Agent_Tests.DisabledTest.json +++ b/src/DisabledTests/Expense_Agent_Tests/Expense_Agent_Tests.DisabledTest.json @@ -119,26 +119,6 @@ "codeunitName": "Expense Projects API Test", "method": "AssignedProjectsBlockedWhenProjectFieldsDisabledViaAPI" }, - { - "codeunitId": 148302, - "codeunitName": "Expense Report Posting Test", - "method": "ExpenseReportIsPostedWithCurrencyOnHeaderAndExchangeRateForExpensesIsExpenseDate" - }, - { - "codeunitId": 148302, - "codeunitName": "Expense Report Posting Test", - "method": "ExpenseReportIsPostedWithCurrencyOnHeaderAndExchangeRateForExpensesIsPostingDate" - }, - { - "codeunitId": 148302, - "codeunitName": "Expense Report Posting Test", - "method": "ExpenseReportIsPostedWithFCYOnHeaderAndExchangeRateForExpensesIsPostingDateWithMultipleFCYLinesAndEmployeePaid" - }, - { - "codeunitId": 148302, - "codeunitName": "Expense Report Posting Test", - "method": "ExpenseReportIsPostedWithFCYOnHeaderAndExchangeRateForExpensesIsExpenseDateWithMultipleFCYLinesAndEmployeePaid" - }, { "codeunitId": 148305, "codeunitName": "Expense Test", 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 9dd1fba0ebe..f4aaf54c555 100644 --- a/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al +++ b/src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al @@ -5958,6 +5958,7 @@ codeunit 12 "Gen. Jnl.-Post Line" IsHandled: Boolean; PayableAccAmtLCY: Decimal; PayableAccAmtAddCurr: Decimal; + AmountSrcCurr: Decimal; begin if GenJnlLine."Account Type" <> GenJnlLine."Account Type"::Employee then exit; @@ -6007,9 +6008,17 @@ codeunit 12 "Gen. Jnl.-Post Line" if (PayableAccAmtLCY <> 0) or ((PayableAccAmtAddCurr <> 0) and (AddCurrencyCode <> '')) then begin + if (GenJnlLine."Source Currency Code" <> '') and (GenJnlLine."Source Currency Code" = GenJnlLine."Currency Code") and + (GenJnlLine.Amount <> 0) and (GenJnlLine."Amount (LCY)" <> 0) and (Abs(GenJnlLine."Amount (LCY)") = Abs(PayableAccAmtLCY)) + then begin + AmountSrcCurr := Abs(GenJnlLine.Amount); + if PayableAccAmtLCY < 0 then + AmountSrcCurr := -AmountSrcCurr; + end else + AmountSrcCurr := CalcAmountSrcCurr(GenJnlLine, PayableAccAmtLCY); InitGLEntry( GenJnlLine, GLEntry, AccNo, PayableAccAmtLCY, PayableAccAmtAddCurr, true, true, - CalcAmountSrcCurr(GenJnlLine, PayableAccAmtLCY)); + AmountSrcCurr); GLEntry."Bal. Account Type" := GenJnlLine."Bal. Account Type"; GLEntry."Bal. Account No." := GenJnlLine."Bal. Account No."; UpdateGLEntryNo(GLEntry."Entry No.", SaveEntryNo); diff --git a/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al b/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al index 89bc73c6c7d..c029fac6134 100644 --- a/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al +++ b/src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al @@ -11,6 +11,7 @@ codeunit 134897 "ERM Source Currency" LibraryPurchase: Codeunit "Library - Purchase"; LibrarySales: Codeunit "Library - Sales"; LibraryFiscalYear: Codeunit "Library - Fiscal Year"; + LibraryHumanResource: Codeunit "Library - Human Resource"; isInitialized: Boolean; AmountIncorrectSignErr: Label 'The Source Currency Amount should have the same sign as the amount on the G/L Entry', Locked = true; VATAmountIncorrectErr: Label 'The Source Currency Amount should be equal to the amount %1 multiplied by the VAT % %2', Locked = true; @@ -1930,6 +1931,52 @@ codeunit 134897 "ERM Source Currency" Assert.AreEqual(-InvoiceAmount, GLEntry."Source Currency Amount", PayablesSCYAmountErr); end; + [Test] + procedure EmployeeFCYPaymentPayablesGLEntryHasCorrectSCYAmount() + var + Employee: Record Employee; + EmployeePostingGroup: Record "Employee Posting Group"; + Currency: Record Currency; + GenJournalLine: Record "Gen. Journal Line"; + GLEntry: Record "G/L Entry"; + StartDate: Date; + PaymentAmount: Decimal; + begin + // [FEATURE] [Employee] + // [SCENARIO] Payables G/L entry keeps the full FCY amount as Source Currency Amount when posting an FCY employee payment, + // instead of a value that has been reconverted through LCY and rounded (bug 639486). + Initialize(); + + // [GIVEN] Start date "D" as WorkDate. + StartDate := WorkDate(); + + // [GIVEN] Currency "C" with an exchange rate of 7 FCY = 1 LCY on "D". + // [GIVEN] With this rate an FCY amount not divisible by 7 converts to an inexact LCY amount, and back-converting through LCY would round to a slightly different FCY amount. + Currency.Get(LibraryERM.CreateCurrencyWithGLAccountSetup()); + CreateCurrencyExchangeRate(Currency.Code, StartDate, 7, 1); + + // [GIVEN] Employee "E". + LibraryHumanResource.CreateEmployee(Employee); + + // [GIVEN] Posted employee Payment via Gen. Journal on "D" with a fixed positive amount 650 in "C". + PaymentAmount := 650; + CreatePostGenJnlLineWithCurrency( + GenJournalLine, GenJournalLine."Document Type"::Payment, + GenJournalLine."Account Type"::Employee, Employee."No.", + Currency.Code, PaymentAmount, StartDate); + + // [THEN] The payables G/L entry has Source Currency Code equal to "C". + EmployeePostingGroup.Get(Employee."Employee Posting Group"); + GLEntry.SetLoadFields("Document No.", "G/L Account No.", "Source Currency Code", "Source Currency Amount"); + GLEntry.SetRange("Document No.", GenJournalLine."Document No."); + GLEntry.SetRange("G/L Account No.", EmployeePostingGroup."Payables Account"); + GLEntry.FindFirst(); + Assert.AreEqual(Currency.Code, GLEntry."Source Currency Code", SourceCurrencyCodeErr); + + // [THEN] Source Currency Amount on payables G/L entry equals the full FCY amount, not a value reconverted through LCY and rounded. + Assert.AreEqual(PaymentAmount, GLEntry."Source Currency Amount", PayablesSCYAmountErr); + end; + local procedure CreatePurchaseInvoice(var PurchaseHeader: Record "Purchase Header"; VendorNo: Code[20]; GLAccountNo: Code[20]; WithForeignCurrency: Boolean) var PurchaseLine: Record "Purchase Line";