Skip to content

Fix incorrect wholesale value calculation from unrounded batch rate#22052

Merged
buddhika75 merged 1 commit into
developmentfrom
21912-wholesale-value-calculation
Jul 12, 2026
Merged

Fix incorrect wholesale value calculation from unrounded batch rate#22052
buddhika75 merged 1 commit into
developmentfrom
21912-wholesale-value-calculation

Conversation

@buddhika75

@buddhika75 buddhika75 commented Jul 12, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes Incorrect Wholesale Value Calculation #21912: on Pharmacy Wholesale Sale, a line's displayed Value could disagree with Rate x Qty (e.g. Rate 8.46, Qty 10 showed Value 84.56 instead of 84.60).
  • Root cause: ItemBatch.wholesaleRate is frequently stored with more than 2 decimal places (e.g. 8.4564), while the UI always displays rates rounded to 2dp. WholesaleSaleNativeSqlController was using the raw unrounded rate for all value/discount math, so the calculated Value didn't match what the user saw as the Rate. Confirmed against real data: the reported Amoxicillin 250mg (SPMC/SPC) batch has WHOLESALERATE = 8.4564, and 8.4564 x 10 = 84.564 rounds to display as 84.56 - matching the bug exactly. Other batches for the same item show the same pattern (e.g. 3.1418181818), so this is systemic, not a one-off data error.
  • Fix: round the wholesale rate to currency precision (2dp) at every point it's consumed for billing math - add item, substitute replacement, live preview (before "Add" is clicked), and the preview panel getters - using the existing CommonFunctions.round() helper, which is already the established convention for rounding wholesale rates elsewhere in the pharmacy module (PharmacyPurchaseController). Row-quantity edit and discount recalculation need no change since they already build on bid.getRate(), which now holds the rounded value from the moment a line is added.
  • Scoped to the wholesale-sale billing path only. Root-causing this at the source (rounding wholesaleRate when it's computed/stored on ItemBatch during GRN/costing) would be a much larger change touching purchase-costing logic and historical data across the app, and is out of scope here.

Test plan

  • mvn compile passes cleanly with the change.
  • QA to verify on RMH (the environment where wholesale sale data with fractional wholesale rates exists): add the Amoxicillin 250mg (SPMC/SPC) batch with Qty 10 to a wholesale sale bill, confirm the preview and bill-items table both show Value = 84.60 (not 84.56), settle the bill, and confirm the persisted bill_item_finance_details net total/wholesale rate matches.
  • Spot check an item whose batch already has a clean 2dp wholesale rate to confirm no regression.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Wholesale sale rates are now consistently rounded to two decimal places.
    • Gross and net amounts, line-item rates, and printed values now remain consistent when adding or replacing sale items.
    • Bill item previews display rounded rates and calculated net values.

ItemBatch.wholesaleRate is frequently stored with more than 2 decimal
places (e.g. 8.4564), but the UI always displays rates rounded to 2dp.
WholesaleSaleNativeSqlController used the raw unrounded rate for all
value/discount math, so the displayed Rate x Qty didn't match the
displayed Value (e.g. 8.46 x 10 showed as 84.56 instead of 84.60).

Round the wholesale rate to currency precision at the point it's
consumed for billing (add, substitute, live preview, row edit),
using the existing CommonFunctions.round() convention already used
for wholesale rates elsewhere in the pharmacy module.

Closes #21912

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d87e4d9d-c044-4148-bf72-1585e5a3c0f9

📥 Commits

Reviewing files that changed from the base of the PR and between dcf03ae and 0938626.

📒 Files selected for processing (1)
  • src/main/java/com/divudi/bean/pharmacy/WholesaleSaleNativeSqlController.java

Walkthrough

Wholesale sale line creation, substitute replacement, and preview calculations now round wholesale rates to two decimal places before assigning rates and calculating gross, discount, and net values.

Changes

Wholesale rate rounding

Layer / File(s) Summary
Round rates for sale line calculations
src/main/java/com/divudi/bean/pharmacy/WholesaleSaleNativeSqlController.java
New and substitute wholesale sale lines assign currency-rounded wholesale rates and calculate derived values from those rates.
Round rates in bill previews
src/main/java/com/divudi/bean/pharmacy/WholesaleSaleNativeSqlController.java
Bill-item listener fields and preview getters now return rounded wholesale-derived values.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • hmislk/hmis#21795: Introduced the native-SQL wholesale sale flow modified by this PR.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: correcting wholesale value calculations from unrounded batch rates.
Linked Issues check ✅ Passed The controller changes round wholesale rates before pricing math and previews, which addresses the incorrect Rs. 84.56 vs Rs. 84.60 calculation.
Out of Scope Changes check ✅ Passed The changes stay within the wholesale-sale billing path and directly support the linked pricing bug fix.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 21912-wholesale-value-calculation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@buddhika75 buddhika75 merged commit 14d6546 into development Jul 12, 2026
3 checks passed
@buddhika75 buddhika75 deleted the 21912-wholesale-value-calculation branch July 12, 2026 21:57
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.

Incorrect Wholesale Value Calculation

1 participant