fix(pharmacy-report): show net consumption in Disposal Consumption Report (#21025) [ruhunu hotfix]#21034
Conversation
…port The Disposal Consumption Report mixed two sign conventions that coexist on disposal-issue bills: `billItem.qty` is stored positive on both issue and return bills, while `billItemFinanceDetails.valueAt*Rate` (and the bill-level `billFinanceDetails.total*Value`) use a stock-direction sign — negative when stock leaves, positive when it comes back. See `DataAdministrationController.isFinanceValueNegative` for the canonical rule. The byBill, byBillItem, and summary aggregations summed those fields raw, so: - quantity columns counted issued and returned units both positive, inflating totals (e.g. 8 issued + 8 returned showed as 16 instead of 0); - purchase/cost/retail summary columns netted to ~0 because issue and return rows cancelled, even when net consumption was non-zero, while the netTotal column (already signed correctly) was the only column that looked right. Translate each row to consumption direction (issue +, return/cancel −) before aggregating: negate the stored valueAt*Rate (its sign is opposite to consumption) and negate qty on return/cancel rows. netTotal already carries the right sign and is left alone. The byBill and byBillItem table now expose the per-row consumption-direction values on PharmacyRow so totals and rows agree, and the PDF export reads the same fields. Closes #21025 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8bb498ce4f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| double rowPurchase = valueAtPurchase != null ? valueSign * valueAtPurchase.doubleValue() : 0.0; | ||
| double rowCost = valueAtCost != null ? valueSign * valueAtCost.doubleValue() : 0.0; | ||
| double rowRetail = valueAtRetail != null ? valueSign * valueAtRetail.doubleValue() : 0.0; | ||
| double rowQty = qtySign * (row.getBillItem().getQty() != null ? row.getBillItem().getQty() : 0.0); |
There was a problem hiding this comment.
Preserve quantities when finance details are absent
When a disposal bill item has no BillItemFinanceDetails (the query above does not exclude those rows), this calculation is skipped because the whole block is guarded by row.getBillItem().getBillItemFinanceDetails() != null. Since the XHTML now displays i.consumptionQty instead of i.billItem.qty, those legacy/partial rows show a quantity of 0 even though the bill item still has a quantity; compute consumptionQty outside the finance-details guard so only the value columns default to zero.
Useful? React with 👍 / 👎.
Summary
Hotfix to
ruhunu-prodmirroring the fix in #21030 (againstdevelopment). The bug was first reported on Ruhunu (#21025), so this is the production branch where it needs to land.Issue #21025 reported the Disposal Consumption Report inflating quantity (8 issued + 8 returned shown as 16) and showing 0 for Purchase / Cost / Retail Value while Net Value looked correct. Root cause:
billItem.qtyis stored positive on both issue and return bills, whilebillItemFinanceDetails.valueAt*Rate/billFinanceDetails.total*Valueuse a stock-direction sign (negative on stock-out, positive on stock-back-in). Aggregations summed the two conventions raw, so qty over-counted and value columns cancelled.This change normalises each row to consumption direction (issue +, return / cancel −) before aggregating;
netTotalalready carries the correct sign and is left alone. The byBill / byBillItem tables now expose per-row consumption-direction values onPharmacyRowso the on-screen rows and the footer total agree, and the PDF export reads the same fields.Data is uniformly in the canonical convention (verified against ruhunu prod, 12.8 K issue rows / 160 return rows all in the expected sign). No data backfill required — the fix is purely reporting logic.
Test plan
R/DIS/RHD/LBK/26/000079/DIS/ML/RHD/26/000141,DIS/LBK/RHD/26/000249,R/DIS/RHD/LBK/26/000111/DIS/ML/RHD/26/000161.Refs #21025
Refs #21030
Refs #21032 (tracking issue for the wider sign-convention normalisation)
🤖 Generated with Claude Code