Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check item price exists on update of Therapy Type #222

Merged
merged 2 commits into from
Apr 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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