Skip to content

Commit

Permalink
fix: check item price exists on update of Therapy Type
Browse files Browse the repository at this point in the history
  • Loading branch information
akashkrishna619 committed Apr 16, 2023
1 parent a928536 commit 77d0a5c
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions healthcare/healthcare/doctype/therapy_type/therapy_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 77d0a5c

Please sign in to comment.