Skip to content

Commit 51f0458

Browse files
nathanmachadoclaude
andcommitted
fix(medication): don't disable non-billable stock/purchase linked Items
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>
1 parent 96ccbf8 commit 51f0458

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

healthcare/healthcare/doctype/medication/medication.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,17 @@ def update_item_and_item_price(self):
7777
item_price.price_list = self.price_list
7878
item_price.save()
7979
else:
80-
frappe.db.set_value("Item", item.item_code, "disabled", 1)
80+
# "Not separately billable" must not deactivate an Item that is
81+
# used in other flows. A linked Item can be a non-billable
82+
# stock/purchase consumable (e.g. a vaccine received via Purchase
83+
# Receipt and issued per dose, while the patient is billed through
84+
# a separate service Item). Only disable Items that aren't
85+
# transactable elsewhere.
86+
item_flags = frappe.db.get_value(
87+
"Item", item.item_code, ["is_stock_item", "is_purchase_item"], as_dict=True
88+
)
89+
if item_flags and not item_flags.is_stock_item and not item_flags.is_purchase_item:
90+
frappe.db.set_value("Item", item.item_code, "disabled", 1)
8191

8292
frappe.db.set_value("Medication Linked Item", item.name, "change_in_item", 0)
8393
self.reload()
@@ -100,7 +110,10 @@ def insert_item(doc, item):
100110
"description": item.item_code,
101111
"is_sales_item": 1,
102112
"is_stock_item": 1,
103-
"disabled": 0 if item.is_billable and not doc.disabled else 1,
113+
# The Item created here is a stock item; don't disable it merely
114+
# because the linked row isn't separately billable — only honour the
115+
# parent Medication's own disabled state.
116+
"disabled": 1 if doc.disabled else 0,
104117
"stock_uom": item.stock_uom or frappe.db.get_single_value("Stock Settings", "stock_uom"),
105118
}
106119
)

0 commit comments

Comments
 (0)