fix: change item_code from Link to Data to avoid item not found error
This commit is contained in:
parent
61203b8701
commit
8c5725c799
@ -12,17 +12,17 @@
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"template",
|
||||
"item",
|
||||
"item_code",
|
||||
"item_group",
|
||||
"medical_department",
|
||||
"description",
|
||||
"column_break_5",
|
||||
"disabled",
|
||||
"is_billable",
|
||||
"rate",
|
||||
"description",
|
||||
"section_break_9",
|
||||
"consume_stock",
|
||||
"medical_department",
|
||||
"consumables",
|
||||
"consume_stock",
|
||||
"items",
|
||||
"sample_collection",
|
||||
"sample",
|
||||
@ -30,8 +30,7 @@
|
||||
"sample_qty",
|
||||
"column_break_21",
|
||||
"sample_details",
|
||||
"change_in_item",
|
||||
"item"
|
||||
"change_in_item"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
@ -45,11 +44,10 @@
|
||||
},
|
||||
{
|
||||
"fieldname": "item_code",
|
||||
"fieldtype": "Link",
|
||||
"fieldtype": "Data",
|
||||
"label": "Item Code",
|
||||
"no_copy": 1,
|
||||
"options": "Item",
|
||||
"read_only": 1
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "item_group",
|
||||
@ -81,7 +79,8 @@
|
||||
"depends_on": "is_billable",
|
||||
"fieldname": "rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Rate"
|
||||
"label": "Rate",
|
||||
"mandatory_depends_on": "is_billable"
|
||||
},
|
||||
{
|
||||
"fieldname": "description",
|
||||
@ -91,10 +90,6 @@
|
||||
"no_copy": 1,
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "section_break_9",
|
||||
"fieldtype": "Section Break"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"fieldname": "consume_stock",
|
||||
@ -103,12 +98,12 @@
|
||||
"search_index": 1
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.consume_stock == 1",
|
||||
"fieldname": "consumables",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Consumables"
|
||||
},
|
||||
{
|
||||
"depends_on": "eval:doc.consume_stock == 1",
|
||||
"fieldname": "items",
|
||||
"fieldtype": "Table",
|
||||
"ignore_user_permissions": 1,
|
||||
@ -168,16 +163,14 @@
|
||||
{
|
||||
"fieldname": "item",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 1,
|
||||
"label": "Item",
|
||||
"no_copy": 1,
|
||||
"options": "Item",
|
||||
"print_hide": 1,
|
||||
"report_hide": 1
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"links": [],
|
||||
"modified": "2020-02-27 13:37:10.143609",
|
||||
"modified": "2020-02-27 16:32:55.780893",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Clinical Procedure Template",
|
||||
|
@ -13,21 +13,21 @@ class ClinicalProcedureTemplate(Document):
|
||||
def validate(self):
|
||||
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):
|
||||
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):
|
||||
if self.is_billable:
|
||||
if self.disabled:
|
||||
@ -39,7 +39,7 @@ class ClinicalProcedureTemplate(Document):
|
||||
def on_trash(self):
|
||||
if(self.item):
|
||||
try:
|
||||
frappe.delete_doc("Item",self.item)
|
||||
frappe.delete_doc('Item',self.item)
|
||||
except Exception:
|
||||
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)""",
|
||||
(args.get('item_code'), nowdate()), as_dict = 1)
|
||||
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]
|
||||
|
||||
@ -76,45 +76,45 @@ def updating_rate(self):
|
||||
def create_item_from_template(doc):
|
||||
disabled = 1
|
||||
|
||||
if(doc.is_billable == 1):
|
||||
if doc.is_billable == 1:
|
||||
disabled = 0
|
||||
|
||||
#insert item
|
||||
item = frappe.get_doc({
|
||||
"doctype": "Item",
|
||||
"item_code": doc.template,
|
||||
"item_name":doc.template,
|
||||
"item_group": doc.item_group,
|
||||
"description":doc.description,
|
||||
"is_sales_item": 1,
|
||||
"is_service_item": 1,
|
||||
"is_purchase_item": 0,
|
||||
"is_stock_item": 0,
|
||||
"show_in_website": 0,
|
||||
"is_pro_applicable": 0,
|
||||
"disabled": disabled,
|
||||
"stock_uom": "Unit"
|
||||
'doctype': 'Item',
|
||||
'item_code': doc.template,
|
||||
'item_name':doc.template,
|
||||
'item_group': doc.item_group,
|
||||
'description':doc.description,
|
||||
'is_sales_item': 1,
|
||||
'is_service_item': 1,
|
||||
'is_purchase_item': 0,
|
||||
'is_stock_item': 0,
|
||||
'show_in_website': 0,
|
||||
'is_pro_applicable': 0,
|
||||
'disabled': disabled,
|
||||
'stock_uom': 'Unit'
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
#insert item price
|
||||
#get item price list to insert item price
|
||||
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):
|
||||
make_item_price(item.name, price_list_name, doc.rate)
|
||||
else:
|
||||
make_item_price(item.name, price_list_name, 0.0)
|
||||
#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.
|
||||
|
||||
def make_item_price(item, price_list_name, item_price):
|
||||
frappe.get_doc({
|
||||
"doctype": "Item Price",
|
||||
"price_list": price_list_name,
|
||||
"item_code": item,
|
||||
"price_list_rate": item_price
|
||||
'doctype': 'Item Price',
|
||||
'price_list': price_list_name,
|
||||
'item_code': item,
|
||||
'price_list_rate': item_price
|
||||
}).insert(ignore_permissions=True)
|
||||
|
||||
@frappe.whitelist()
|
||||
@ -123,11 +123,11 @@ def change_item_code_from_template(item_code, doc):
|
||||
doc = frappe._dict(args)
|
||||
|
||||
if(frappe.db.exists({
|
||||
"doctype": "Item",
|
||||
"item_code": item_code})):
|
||||
frappe.throw(_("Code {0} already exist").format(item_code))
|
||||
'doctype': 'Item',
|
||||
'item_code': item_code})):
|
||||
frappe.throw(_('Code {0} already exist').format(item_code))
|
||||
else:
|
||||
rename_doc("Item", doc.item_code, item_code, ignore_permissions=True)
|
||||
frappe.db.set_value("Clinical Procedure Template", doc.name, "item_code", item_code)
|
||||
rename_doc('Item', doc.item_code, item_code, ignore_permissions=True)
|
||||
frappe.db.set_value('Clinical Procedure Template', doc.name, 'item_code', item_code)
|
||||
return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user