Fix incorrect wholesale value calculation from unrounded batch rate#22052
Conversation
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>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughWholesale 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. ChangesWholesale rate rounding
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Summary
ItemBatch.wholesaleRateis frequently stored with more than 2 decimal places (e.g.8.4564), while the UI always displays rates rounded to 2dp.WholesaleSaleNativeSqlControllerwas 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 hasWHOLESALERATE = 8.4564, and8.4564 x 10 = 84.564rounds 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.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 onbid.getRate(), which now holds the rounded value from the moment a line is added.wholesaleRatewhen it's computed/stored onItemBatchduring 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 compilepasses cleanly with the change.bill_item_finance_detailsnet total/wholesale rate matches.🤖 Generated with Claude Code
Summary by CodeRabbit