Skip to content

[Master] Expense Report posting FCY rounding mismatch "Expense Report Posting Test" fail in Spain only (Source Currency Amount 649.97 vs 650 - #9886

Open
sanjmaurya wants to merge 6 commits into
mainfrom
bugs/Bug-644891-Main-ExpenseAgentExpenseAgentESExpenseReportpostingounding
Open

[Master] Expense Report posting FCY rounding mismatch "Expense Report Posting Test" fail in Spain only (Source Currency Amount 649.97 vs 650#9886
sanjmaurya wants to merge 6 commits into
mainfrom
bugs/Bug-644891-Main-ExpenseAgentExpenseAgentESExpenseReportpostingounding

Conversation

@sanjmaurya

@sanjmaurya sanjmaurya commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Bug 644891: [Master][ALL-E] [Expense Agent] Expense Agent] [ES] Expense Report posting FCY rounding mismatch "Expense Report Posting Test" fail in Spain only (Source Currency Amount 649.97 vs 650

Fixes AB#644891

Issue:- Expense Agent] [ES] Expense Report posting FCY rounding mismatch "Expense Report Posting Test" fail in Spain only (Source Currency Amount 649.97 vs 650

Cause :- The employee payables balancing G/L entry is created in PostDtldEmplLedgEntries (ES layer GenJnlPostLine, line ~5967) like this:

And CalcAmountSrcCurr (line ~3258) computes:

So for the employee entry, ES unconditionally derives Source Currency Amount from the LCY amount (PayableAccAmtLCY) — it never reads GenJournalLine."Source Currency Amount". (Note: the vendor path does have a System-Created branch that uses the journal line's value, but the employee path does not.)

Solution:- : the employee payable balancing entry has PayableAccAmtLCY as positive (+650), while the journal line's "Amount (LCY)" is negative (-650). My old condition "Amount (LCY)" = PayableAccAmtLCY was therefore never true, so the code always fell back to CalcAmountSrcCurr (the LCY→FCY reconversion that yields 649.97).

The updated block in PostDtldEmplLedgEntries:
if (GenJnlLine."Source Currency Code" <> '') and (GenJnlLine."Source Currency Amount" <> 0) and (GenJnlLine."Amount (LCY)" <> 0) and (Abs(GenJnlLine."Amount (LCY)") = Abs(PayableAccAmtLCY)) then begin
AmountSrcCurr := Abs(GenJnlLine."Source Currency Amount");
if PayableAccAmtLCY < 0 then
AmountSrcCurr := -AmountSrcCurr;
end else
AmountSrcCurr := CalcAmountSrcCurr(GenJnlLine, PayableAccAmtLCY);

@github-actions github-actions Bot added the Finance GitHub request for Finance area label Aug 3, 2026
@github-actions github-actions Bot added this to the Version 29.0 milestone Aug 3, 2026
…Bug-644891-Main-ExpenseAgentExpenseAgentESExpenseReportpostingounding
@sanjmaurya
sanjmaurya marked this pull request as ready for review August 5, 2026 06:59
@sanjmaurya
sanjmaurya requested review from a team August 5, 2026 06:59
Comment thread src/Layers/ES/Tests/ERM/ERMSourceCurrency.Codeunit.al Outdated
Comment thread src/Layers/ES/Tests/ERM/ERMSourceCurrency.Codeunit.al Outdated
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 1

Recommendation: Accept with Suggestions

What this PR does

This PR fixes the ES employee payables G/L entry for FCY employee and expense postings. When the journal source currency matches the journal currency and the LCY amount matches the payable amount by absolute value, it keeps the original FCY amount instead of converting LCY back to FCY.

The change is narrow and keeps the old CalcAmountSrcCurr path for cases that do not match that exact condition. This matches the bug evidence: the ES expense report tests failed because the payable entry was rounded through LCY and got 649.97 instead of 650. The PR also re-enables the four disabled Expense Report tests, so the original ES scenarios are covered again.

Suggestions

S1 - Make the new employee test deterministic
Use a fixed amount that is not divisible by 7, and assert the signed value instead of Abs(...). The current random amount can pick a value where the old LCY-to-FCY conversion gives the same result, so this new test may not always prove the fix.

Risk assessment and necessity

Risk: This is financial posting logic in the ES layer, so a wrong value can affect G/L Entry source currency reporting for employee payables. The code change is limited to PostDtldEmplLedgEntries, does not change public signatures or events, and leaves other posting cases on the existing calculation path.

Necessity: The change is needed because the active bug keeps four ES Expense Report FCY tests disabled. Re-enabling those tests is the right scope for this fix, and the added employee payables test gives a smaller regression path once it is made deterministic.

[AI-PR-REVIEW] version=1 promptVersion=1 system=github pr=9886 round=1 by=alexei-dobriansky at=2026-08-05T11:34:17Z lastSha=db30d794bc9342ea9ec18c3e58844c5bcc975f1f reviewKey=08d806d293c453541564ba85fd9c6cefa8ba96d4fdb62f621b87e8c46288290b suggestions=S1@8d40ef23

@sanjmaurya

sanjmaurya commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi alexei-dobriansky

I have fix the Suggestion. Please check

Comment thread src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 2

Recommendation: Accept

What this PR does

Since round 1, this PR makes the new ES employee FCY regression test deterministic. It now uses a fixed amount of 650 with the 7 FCY = 1 LCY exchange rate, and it asserts the signed Source Currency Amount directly.

This addresses the previous test concern. The test now always exercises the LCY-to-FCY rounding mismatch that the posting fix is meant to avoid, and it no longer hides a wrong sign with Abs(...).

Status of previous suggestions
ID Title Status Author response
S1 Make the new employee test deterministic Addressed Fixed in 2318126: the test uses amount 650 and asserts the signed source currency amount.
New observations (commits since round 1)

None - changes only addressed prior suggestions.

Risk assessment and necessity

Risk: The round-2 change only updates test code. The product-code risk remains limited to ES employee payables posting when source currency equals the journal currency and the payable LCY amount matches the journal LCY amount by absolute value.

Necessity: The deterministic test is needed because this is sensitive financial posting logic. The PR also re-enables the disabled ES Expense Report FCY tests, so the original failing scenario is covered again.


[AI-PR-REVIEW] version=1 promptVersion=1 system=github pr=9886 round=2 by=alexei-dobriansky at=2026-08-05T15:43:20Z lastSha=231812661372467cb145fe7072af30f7293e6402 reviewKey=8d3765c89d71355c764eef61e05cec04263f3f2c19f0f8b823f9effedce46267 suggestions=S1@8d40ef23:addressed parentRound=1

Comment thread src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes an ES-layer posting issue where employee payables balancing G/L entries could get a rounded/reconverted Source Currency Amount (FCY) instead of preserving the original FCY amount from the journal line, which caused Spain-only expense report posting test failures.

Changes:

  • Adjusts ES Gen. Jnl.-Post Line employee payables G/L entry creation to preserve the original FCY amount when the LCY amounts match by magnitude.
  • Adds an ES regression test covering FCY employee payment posting and validating the payables G/L entry Source Currency Amount.
  • Re-enables previously disabled Expense Agent “Expense Report Posting Test” cases by removing them from the disabled-tests list.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/Layers/ES/Tests/ERM/ERMSourceCurrency.Codeunit.al Adds a regression test for FCY employee payment payables G/L entry Source Currency Amount correctness.
src/Layers/ES/BaseApp/Finance/GeneralLedger/Posting/GenJnlPostLine.Codeunit.al Updates employee payables balancing G/L entry SCY amount derivation to avoid LCY→FCY reconversion rounding mismatch.
src/DisabledTests/Expense_Agent_Tests/Expense_Agent_Tests.DisabledTest.json Removes disabled entries for Expense Report Posting tests so they run again.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Layers/ES/Tests/ERM-Finance/ERMSourceCurrency.Codeunit.al
v-praghav
v-praghav previously approved these changes Aug 6, 2026
@sanjmaurya
sanjmaurya enabled auto-merge August 6, 2026 09:36
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 3

Recommendation: Accept

What this PR does

Since round 2, this PR adds a SetLoadFields call in the ES employee FCY regression test and removes two now-redundant developer comments. The SetLoadFields lists exactly the four fields used in the test (Document No., G/L Account No., Source Currency Code, Source Currency Amount), so it is correct and complete. No product code was changed.

The core fix — using Abs(GenJnlLine."Amount (LCY)") instead of a sign-sensitive equality check in PostDtldEmplLedgEntries — is unchanged and correct.

Status of previous suggestions
ID Title Status Author response
S1 Make the new employee test deterministic Addressed Fixed in round 2: test uses fixed amount 650, asserts signed source currency amount.
New observations (commits since round 2)

None — the single commit only adds SetLoadFields and removes obsolete comments. Both changes are correct and raise no new concerns.

Risk assessment and necessity

Risk: The round-3 change is test-only. No product logic was modified. The SetLoadFields call covers all fields asserted in the test, so there is no risk of a partial-load read returning an incorrect default value.

Necessity: The SetLoadFields call is a minor performance improvement for the test and is consistent with BCApps test patterns. The comment removal keeps the test clean. Neither change is strictly required, but both are appropriate.


[AI-PR-REVIEW] version=1 promptVersion=1 system=github pr=9886 round=3 by=alexei-dobriansky at=2026-08-06T13:08:20Z lastSha=24a12d451f7824fd257554e7f50de53fe9c4df85 reviewKey=c1e52924305ad15c13f75be9f45e248b54cfac5a0eb0e736feaa06d078a77206 suggestions=S1@8d40ef23:addressed parentRound=2

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Stale Status Check Deleted

The Pull Request Build workflow run for this PR was older than 72 hours and has been deleted.

📋 Why was it deleted?

Status checks that are too old may no longer reflect the current state of the target branch. To ensure this PR is validated against the latest code and passes up-to-date checks, a fresh build is required.


🔄 How to trigger a new status check:

  1. 📤 Push a new commit to the PR branch, or
  2. 🔁 Close and reopen the PR

This will automatically trigger a new Pull Request Build workflow run.

@sanjmaurya sanjmaurya closed this Aug 11, 2026
auto-merge was automatically disabled August 11, 2026 03:51

Pull request was closed

@sanjmaurya sanjmaurya reopened this Aug 11, 2026
@sanjmaurya
sanjmaurya enabled auto-merge August 11, 2026 12:41
@alexei-dobriansky

Copy link
Copy Markdown
Contributor

Agentic PR Review - Round 4

Recommendation: Accept

What this PR does

Since round 3, the PR head changed by merging current main. I found no PR-owned non-merge commits after 24a12d4. The current net diff still fixes the ES employee payables Source Currency Amount path by using the journal FCY amount when the journal source currency matches the journal currency and the payable LCY amount matches by absolute value.

The bug evidence describes an ES FCY rounding failure where expense report posting wrote 649.97 / -669.98 instead of 650 / -670. The current diff still keeps the existing LCY-to-FCY calculation for other employee posting cases, re-enables the four disabled expense report tests, and adds a deterministic employee FCY payment regression test in the ES ERM source currency test app. I did not find a new correctness issue in the current net diff.

Status of previous suggestions
ID Title Status Author response
S1 Make the new employee test deterministic Addressed Still addressed. The current diff keeps the fixed amount 650 and asserts the signed source currency amount.
New observations (commits since round 3)

None - the current update is a merge from main. I found no new PR-owned changed span to raise as a suggestion.

Risk assessment and necessity

Risk: This is ES financial posting logic. A wrong value can affect G/L Entry source currency reporting for employee payables. The code change remains narrow, does not change public signatures or events, and falls back to the existing calculation when the exact source-currency and LCY-amount conditions are not met.

Necessity: The change is needed to fix and re-enable the ES expense report FCY tests that were disabled for this bug. The deterministic employee posting test covers the smaller root cause directly, and the main merge keeps the PR aligned with the current split test app structure.


[AI-PR-REVIEW] version=1 promptVersion=2 system=github pr=9886 round=4 by=alexei-dobriansky at=2026-08-12T08:09:28Z lastSha=0585bdce805055954641006c42bc220c07a659a7 reviewKey=22170caa493f97ef3ce5c3566ff347f2c57096aa3194bc6edb4cd87e83a9074b suggestions=S1@8d40ef23:addressed parentRound=3

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Stale Status Check Deleted

The Pull Request Build workflow run for this PR was older than 72 hours and has been deleted.

📋 Why was it deleted?

Status checks that are too old may no longer reflect the current state of the target branch. To ensure this PR is validated against the latest code and passes up-to-date checks, a fresh build is required.


🔄 How to trigger a new status check:

  1. 📤 Push a new commit to the PR branch, or
  2. 🔁 Close and reopen the PR

This will automatically trigger a new Pull Request Build workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Finance GitHub request for Finance area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants