diff --git a/healthcare/healthcare/doctype/therapy_type/therapy_type.py b/healthcare/healthcare/doctype/therapy_type/therapy_type.py index d524dd29a3..b4de83ee6a 100644 --- a/healthcare/healthcare/doctype/therapy_type/therapy_type.py +++ b/healthcare/healthcare/doctype/therapy_type/therapy_type.py @@ -11,6 +11,10 @@ from frappe.model.rename_doc import rename_doc from frappe.utils import cint +from healthcare.healthcare.doctype.clinical_procedure_template.clinical_procedure_template import ( + make_item_price, +) + class TherapyType(Document): def validate(self): @@ -41,11 +45,14 @@ def update_item_and_item_price(self): item_doc.save(ignore_permissions=True) if self.rate: - item_price = frappe.get_doc("Item Price", {"item_code": self.item}) - item_price.item_name = self.item_name - item_price.price_list_rate = self.rate - item_price.ignore_mandatory = True - item_price.save() + if frappe.db.exists("Item Price", {"item_code": self.item}): + item_price = frappe.get_doc("Item Price", {"item_code": self.item}) + item_price.item_name = self.item_name + item_price.price_list_rate = self.rate + item_price.ignore_mandatory = True + item_price.save() + else: + make_item_price(self.item, self.rate) elif not self.is_billable and self.item: frappe.db.set_value("Item", self.item, "disabled", 1) @@ -114,18 +121,6 @@ def create_item_from_therapy(doc): doc.db_set("item", item.name) -def make_item_price(item, item_price): - price_list_name = frappe.db.get_value("Price List", {"selling": 1}) - frappe.get_doc( - { - "doctype": "Item Price", - "price_list": price_list_name, - "item_code": item, - "price_list_rate": item_price, - } - ).insert(ignore_permissions=True, ignore_mandatory=True) - - @frappe.whitelist() def change_item_code_from_therapy(item_code, doc): doc = frappe._dict(json.loads(doc))