fix: change item_code from Link to Data to avoid item not found error

This commit is contained in:
Rucha Mahabal 2020-02-27 17:18:52 +05:30
parent 61203b8701
commit 8c5725c799
2 changed files with 51 additions and 58 deletions

View File

@ -12,17 +12,17 @@
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"template", "template",
"item",
"item_code", "item_code",
"item_group", "item_group",
"medical_department", "description",
"column_break_5", "column_break_5",
"disabled", "disabled",
"is_billable", "is_billable",
"rate", "rate",
"description", "medical_department",
"section_break_9",
"consume_stock",
"consumables", "consumables",
"consume_stock",
"items", "items",
"sample_collection", "sample_collection",
"sample", "sample",
@ -30,8 +30,7 @@
"sample_qty", "sample_qty",
"column_break_21", "column_break_21",
"sample_details", "sample_details",
"change_in_item", "change_in_item"
"item"
], ],
"fields": [ "fields": [
{ {
@ -45,11 +44,10 @@
}, },
{ {
"fieldname": "item_code", "fieldname": "item_code",
"fieldtype": "Link", "fieldtype": "Data",
"label": "Item Code", "label": "Item Code",
"no_copy": 1,
"options": "Item", "options": "Item",
"read_only": 1 "reqd": 1
}, },
{ {
"fieldname": "item_group", "fieldname": "item_group",
@ -81,7 +79,8 @@
"depends_on": "is_billable", "depends_on": "is_billable",
"fieldname": "rate", "fieldname": "rate",
"fieldtype": "Float", "fieldtype": "Float",
"label": "Rate" "label": "Rate",
"mandatory_depends_on": "is_billable"
}, },
{ {
"fieldname": "description", "fieldname": "description",
@ -91,10 +90,6 @@
"no_copy": 1, "no_copy": 1,
"reqd": 1 "reqd": 1
}, },
{
"fieldname": "section_break_9",
"fieldtype": "Section Break"
},
{ {
"default": "0", "default": "0",
"fieldname": "consume_stock", "fieldname": "consume_stock",
@ -103,12 +98,12 @@
"search_index": 1 "search_index": 1
}, },
{ {
"depends_on": "eval:doc.consume_stock == 1",
"fieldname": "consumables", "fieldname": "consumables",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"label": "Consumables" "label": "Consumables"
}, },
{ {
"depends_on": "eval:doc.consume_stock == 1",
"fieldname": "items", "fieldname": "items",
"fieldtype": "Table", "fieldtype": "Table",
"ignore_user_permissions": 1, "ignore_user_permissions": 1,
@ -168,16 +163,14 @@
{ {
"fieldname": "item", "fieldname": "item",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 1,
"label": "Item", "label": "Item",
"no_copy": 1, "no_copy": 1,
"options": "Item", "options": "Item",
"print_hide": 1, "read_only": 1
"report_hide": 1
} }
], ],
"links": [], "links": [],
"modified": "2020-02-27 13:37:10.143609", "modified": "2020-02-27 16:32:55.780893",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Healthcare", "module": "Healthcare",
"name": "Clinical Procedure Template", "name": "Clinical Procedure Template",

View File

@ -13,21 +13,21 @@ class ClinicalProcedureTemplate(Document):
def validate(self): def validate(self):
self.enable_disable_item() self.enable_disable_item()
def on_update(self):
#Item and Price List update --> if (change_in_item)
if(self.change_in_item and self.is_billable == 1 and self.item):
updating_item(self)
if(self.rate != 0.0):
updating_rate(self)
elif(self.is_billable == 0 and self.item):
frappe.db.set_value("Item",self.item,"disabled",1)
frappe.db.set_value(self.doctype,self.name,"change_in_item",0)
self.reload()
def after_insert(self): def after_insert(self):
create_item_from_template(self) create_item_from_template(self)
def on_update(self):
#Item and Price List update --> if (change_in_item)
if self.change_in_item and self.is_billable == 1 and self.item:
updating_item(self)
if self.rate != 0.0:
updating_rate(self)
elif self.is_billable == 0 and self.item:
frappe.db.set_value('Item',self.item,'disabled',1)
frappe.db.set_value(self.doctype,self.name,'change_in_item',0)
self.reload()
def enable_disable_item(self): def enable_disable_item(self):
if self.is_billable: if self.is_billable:
if self.disabled: if self.disabled:
@ -39,7 +39,7 @@ class ClinicalProcedureTemplate(Document):
def on_trash(self): def on_trash(self):
if(self.item): if(self.item):
try: try:
frappe.delete_doc("Item",self.item) frappe.delete_doc('Item',self.item)
except Exception: except Exception:
frappe.throw(_("""Not permitted. Please disable the Procedure Template""")) frappe.throw(_("""Not permitted. Please disable the Procedure Template"""))
@ -51,7 +51,7 @@ class ClinicalProcedureTemplate(Document):
and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""", and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""",
(args.get('item_code'), nowdate()), as_dict = 1) (args.get('item_code'), nowdate()), as_dict = 1)
if not item: if not item:
frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get('item_code'))) frappe.throw(_('Item {0} is not active or end of life has been reached').format(args.get('item_code')))
item = item[0] item = item[0]
@ -76,45 +76,45 @@ def updating_rate(self):
def create_item_from_template(doc): def create_item_from_template(doc):
disabled = 1 disabled = 1
if(doc.is_billable == 1): if doc.is_billable == 1:
disabled = 0 disabled = 0
#insert item #insert item
item = frappe.get_doc({ item = frappe.get_doc({
"doctype": "Item", 'doctype': 'Item',
"item_code": doc.template, 'item_code': doc.template,
"item_name":doc.template, 'item_name':doc.template,
"item_group": doc.item_group, 'item_group': doc.item_group,
"description":doc.description, 'description':doc.description,
"is_sales_item": 1, 'is_sales_item': 1,
"is_service_item": 1, 'is_service_item': 1,
"is_purchase_item": 0, 'is_purchase_item': 0,
"is_stock_item": 0, 'is_stock_item': 0,
"show_in_website": 0, 'show_in_website': 0,
"is_pro_applicable": 0, 'is_pro_applicable': 0,
"disabled": disabled, 'disabled': disabled,
"stock_uom": "Unit" 'stock_uom': 'Unit'
}).insert(ignore_permissions=True) }).insert(ignore_permissions=True)
#insert item price #insert item price
#get item price list to insert item price #get item price list to insert item price
if(doc.rate != 0.0): if(doc.rate != 0.0):
price_list_name = frappe.db.get_value("Price List", {"selling": 1}) price_list_name = frappe.db.get_value('Price List', {'selling': 1})
if(doc.rate): if(doc.rate):
make_item_price(item.name, price_list_name, doc.rate) make_item_price(item.name, price_list_name, doc.rate)
else: else:
make_item_price(item.name, price_list_name, 0.0) make_item_price(item.name, price_list_name, 0.0)
#Set item to the template #Set item to the template
frappe.db.set_value("Clinical Procedure Template", doc.name, "item", item.name) frappe.db.set_value('Clinical Procedure Template', doc.name, 'item', item.name)
doc.reload() #refresh the doc after insert. doc.reload() #refresh the doc after insert.
def make_item_price(item, price_list_name, item_price): def make_item_price(item, price_list_name, item_price):
frappe.get_doc({ frappe.get_doc({
"doctype": "Item Price", 'doctype': 'Item Price',
"price_list": price_list_name, 'price_list': price_list_name,
"item_code": item, 'item_code': item,
"price_list_rate": item_price 'price_list_rate': item_price
}).insert(ignore_permissions=True) }).insert(ignore_permissions=True)
@frappe.whitelist() @frappe.whitelist()
@ -123,11 +123,11 @@ def change_item_code_from_template(item_code, doc):
doc = frappe._dict(args) doc = frappe._dict(args)
if(frappe.db.exists({ if(frappe.db.exists({
"doctype": "Item", 'doctype': 'Item',
"item_code": item_code})): 'item_code': item_code})):
frappe.throw(_("Code {0} already exist").format(item_code)) frappe.throw(_('Code {0} already exist').format(item_code))
else: else:
rename_doc("Item", doc.item_code, item_code, ignore_permissions=True) rename_doc('Item', doc.item_code, item_code, ignore_permissions=True)
frappe.db.set_value("Clinical Procedure Template", doc.name, "item_code", item_code) frappe.db.set_value('Clinical Procedure Template', doc.name, 'item_code', item_code)
return return