Skip to content

Commit

Permalink
fix(Medication): make item unique for Medication in child table
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkrishna619 committed Feb 16, 2024
1 parent 44892c5 commit d04c086
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions healthcare/healthcare/doctype/medication/medication.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ def on_update(self):
if self.linked_items:
self.update_item_and_item_price()

def validate(self):
if self.linked_items:
for item in self.linked_items:
exist_medication = frappe.db.get_value(
"Medication Linked Item",
{"item": item.item_code, "parent": ("!=", self.name)},
"parent",
)
if exist_medication:
frappe.throw(
_(
"Item <b>{}</b> has been already used in <b><a href='/app/medication/{}'>Medication</a></b>"
).format(item.item_code, exist_medication)
)

def update_item_and_item_price(self):
for item in self.linked_items:
if not item.item:
Expand Down

0 comments on commit d04c086

Please sign in to comment.