Skip to content

fix: multiple rounding issue (backport #4953) - #4987

Merged
ljain112 merged 4 commits into
version-16-hotfixfrom
mergify/bp/version-16-hotfix/pr-4953
Oct 8, 2026
Merged

ljain112 merged 4 commits into
version-16-hotfixfrom
mergify/bp/version-16-hotfix/pr-4953

Conversation

@mergify

@mergify mergify Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

This is an automatic backport of pull request #4953 done by [Mergify](https://mergify.com).

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics -6 complexity

Metric Results
Complexity -6

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@greptile-apps

greptile-apps Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Fixes rounding precision in tax calculations across multiple modules.

Do not merge until advance-tax calculations and ledger posting use consistent company-currency precision.

Findings

  1. P1 Advance GST stays partly unreversed ▶

Reviews (1) · Last reviewed commit: "fix: use field precision for advance gst..." · Reviewed by Greptile

Comment on lines +323 to +326
return flt(
amount * base_allocated_amount / base_amount,
get_field_precision(frappe.get_meta("Advance Taxes and Charges").get_field("base_tax_amount")),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Advance GST stays partly unreversed

If currency_precision is unset and currency-specific number formats are enabled, get_proportionate_tax chooses precision without the payment document or company currency. This can use the site's decimal count instead of the company's, while ERPNext rounds ledger amounts to the company currency.

For an INR company with two decimals on a site with three, separately allocating ₹33.30, ₹33.30, and ₹933.40 against a ₹1,000 advance with ₹180 GST calculates reversal shares of ₹5.994, ₹5.994, and ₹168.012. Ledger rounding reduces those to ₹5.99, ₹5.99, and ₹168.01, reversing only ₹179.99. The final allocation enters balance_taxes, but subtracts the earlier three-decimal shares rather than their rounded ledger amounts, so it cannot recover the missing paisa.

Use company-currency precision for proportional calculations and final balancing, and cover separate allocations with different site and currency formats in a regression test. This financial accuracy issue must be fixed before merging.

Artifacts

Complete executable GST precision check

  • The authored script extracts and executes real base/head functions and snapshot/version-16 contracts with explicit service stubs, making the focused reproduction inspectable.

Base execution with full GST reversal

  • Executed the three separate allocations against base with both contract sets and captured all extracted source and output, showing ₹180.00 reversed with no residual.

Head execution with one paisa left unreversed

  • Executed the identical allocations against head with both contract sets and captured the final balancing and GL rounding output, showing ₹179.99 reversed and ₹0.01 remaining.

View artifacts

T-Rex Ran code and verified through T-Rex

@ljain112
ljain112 merged commit a115eb3 into version-16-hotfix Oct 8, 2026
15 checks passed
@ljain112
ljain112 deleted the mergify/bp/version-16-hotfix/pr-4953 branch October 8, 2026 06:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant