fix(medication): don't disable non-billable stock/purchase linked Items#1020
Conversation
Medication tied an Item's `disabled` state to its linked row's `is_billable` flag, conflating "not separately billable" with "inactive". Both the insert and update paths set `disabled = 1` whenever `is_billable` was unchecked, which deactivated Items that are valid and in active use elsewhere (purchasing, stock), e.g. a vaccine modelled as a non-billable batch-tracked consumable billed through a separate service Item. The consumable was re-disabled on every save and could no longer be received or issued (a disabled Item is rejected by Stock Entry / Purchase Receipt). Only disable linked Items that aren't transactable elsewhere (skip `is_stock_item` / `is_purchase_item`); on insert, honour just the parent Medication's disabled state. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR refines Item disabled state management in the Medication class. The Possibly related issues
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
|
Closes #1019 |
Problem
Medication ties the disabled state of each linked Item to that row’s is_billable flag, conflating two independent concepts — “not separately billable” and “inactive”. On both insert and update, a linked Item whose is_billable is unchecked is set to disabled = 1, deactivating Items that are valid and in active use in other flows (purchasing, stock).
This makes it impossible to model a medication whose linked Item is a non-billable stock consumable — e.g. a vaccine purchased as a batch-tracked stock item (entered via Purchase Receipt, issued per dose) while the patient is billed through a separate service Item. The consumable is re-disabled on every Medication save, disappears from Item pickers, and cannot be transacted at all (a disabled Item is rejected by Stock Entry / Purchase Receipt).
Steps to reproduce
Item VAC-X: Maintain Stock = 1, Has Batch No = 1, Allow Sales = 0.
Item SVC-X: a service Item (Maintain Stock = 0, Allow Sales = 1).
Medication with both in Linked Items: VAC-X with Is Billable = 0, SVC-X with Is Billable = 1. Save.
VAC-X becomes disabled = 1.
Fix
Only disable linked Items that aren’t transactable elsewhere: skip is_stock_item / is_purchase_item Items in the update path, and on the insert path honour just the parent Medication’s own disabled state (the Item created there is always a stock item). This preserves the original intent — hiding a non billable, Medication-owned service Item from billing — without breaking shared stock/purchase Items.
No DocType/schema changes; behaviour for plain non-stock service Items is unchanged