Skip to content

fix(medication): don't disable non-billable stock/purchase linked Items#1020

Open
nathanmachado wants to merge 1 commit into
earthians:developfrom
nathanmachado:fix/medication-disable-non-billable-stock-item
Open

fix(medication): don't disable non-billable stock/purchase linked Items#1020
nathanmachado wants to merge 1 commit into
earthians:developfrom
nathanmachado:fix/medication-disable-non-billable-stock-item

Conversation

@nathanmachado
Copy link
Copy Markdown

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.


# update_item_and_item_price() — before
else:
frappe.db.set_value("Item", item.item_code, "disabled", 1)

# after
else:
item_flags = frappe.db.get_value(
"Item", item.item_code, ["is_stock_item", "is_purchase_item"], as_dict=True
)
if item_flags and not item_flags.is_stock_item and not item_flags.is_purchase_item:
frappe.db.set_value("Item", item.item_code, "disabled", 1)

No DocType/schema changes; behaviour for plain non-stock service Items is unchanged

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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b580ba9f-525b-4caf-adb2-57c76aa62741

📥 Commits

Reviewing files that changed from the base of the PR and between 96ccbf8 and 51f0458.

📒 Files selected for processing (1)
  • healthcare/healthcare/doctype/medication/medication.py

Walkthrough

The PR refines Item disabled state management in the Medication class. The update_item_and_item_price method now disables linked Items only when they are neither stock nor purchase items, shifting from a direct is_billable and parent-disabled check. The insert_item method now sets newly created Items' disabled flag based solely on the parent Medication's disabled state, removing the prior is_billable dependency. Both changes align Item disabled behavior with transactability and parent state.

Possibly related issues

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: preventing non-billable stock/purchase linked Items from being disabled in the Medication doctype.
Description check ✅ Passed The description is directly related to the changeset, providing detailed context about the problem, reproduction steps, and the fix being implemented.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

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

@nathanmachado
Copy link
Copy Markdown
Author

Closes #1019

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.

1 participant