Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,6 @@
"codeunitName": "Expense Projects API Test",
"method": "AssignedProjectsBlockedWhenProjectFieldsDisabledViaAPI"
},
{
Comment thread
sanjmaurya marked this conversation as resolved.
"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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Comment thread
sanjmaurya marked this conversation as resolved.
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);
Expand Down
47 changes: 47 additions & 0 deletions src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Comment thread
sanjmaurya marked this conversation as resolved.
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.");
Comment thread
sanjmaurya marked this conversation as resolved.
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";
Expand Down
Loading