fix: Clinical Procedure Template code refactor
diff --git a/erpnext/healthcare/doctype/clinical_procedure_item/clinical_procedure_item.json b/erpnext/healthcare/doctype/clinical_procedure_item/clinical_procedure_item.json
index 75151b1..4d0502b 100644
--- a/erpnext/healthcare/doctype/clinical_procedure_item/clinical_procedure_item.json
+++ b/erpnext/healthcare/doctype/clinical_procedure_item/clinical_procedure_item.json
@@ -1,431 +1,122 @@
{
- "allow_copy": 0,
- "allow_events_in_timeline": 0,
- "allow_guest_to_view": 0,
- "allow_import": 0,
- "allow_rename": 0,
- "beta": 1,
- "creation": "2017-10-05 16:15:10.876952",
- "custom": 0,
- "docstatus": 0,
- "doctype": "DocType",
- "document_type": "",
- "editable_grid": 1,
- "engine": "InnoDB",
+ "actions": [],
+ "beta": 1,
+ "creation": "2017-10-05 16:15:10.876952",
+ "doctype": "DocType",
+ "editable_grid": 1,
+ "engine": "InnoDB",
+ "field_order": [
+ "item_code",
+ "barcode",
+ "item_name",
+ "qty",
+ "uom",
+ "invoice_separately_as_consumables",
+ "column_break_5",
+ "batch_no",
+ "conversion_factor",
+ "stock_uom",
+ "transfer_qty",
+ "actual_qty"
+ ],
"fields": [
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 1,
- "collapsible": 0,
- "columns": 3,
- "fieldname": "item_code",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 1,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 1,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Item",
- "length": 0,
- "no_copy": 0,
- "options": "Item",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 1,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "bold": 1,
+ "columns": 3,
+ "fieldname": "item_code",
+ "fieldtype": "Link",
+ "ignore_user_permissions": 1,
+ "in_global_search": 1,
+ "in_list_view": 1,
+ "label": "Item",
+ "options": "Item",
+ "reqd": 1,
+ "search_index": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "barcode",
- "fieldtype": "Data",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Barcode",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "barcode",
+ "fieldtype": "Data",
+ "label": "Barcode"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "item_name",
- "fieldtype": "Data",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Item Name",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "item_name",
+ "fieldtype": "Data",
+ "in_list_view": 1,
+ "label": "Item Name"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "qty",
- "fieldtype": "Float",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Quantity",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "qty",
+ "fieldtype": "Float",
+ "in_list_view": 1,
+ "label": "Quantity",
+ "reqd": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "uom",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "UOM",
- "length": 0,
- "no_copy": 0,
- "options": "UOM",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "uom",
+ "fieldtype": "Link",
+ "in_list_view": 1,
+ "label": "UOM",
+ "options": "UOM",
+ "reqd": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "invoice_separately_as_consumables",
- "fieldtype": "Check",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 1,
- "in_standard_filter": 0,
- "label": "Invoice Separately as Consumables",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "default": "0",
+ "fieldname": "invoice_separately_as_consumables",
+ "fieldtype": "Check",
+ "in_list_view": 1,
+ "label": "Invoice Separately as Consumables"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "column_break_5",
- "fieldtype": "Column Break",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "column_break_5",
+ "fieldtype": "Column Break"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "batch_no",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Batch",
- "length": 0,
- "no_copy": 0,
- "options": "Batch",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "batch_no",
+ "fieldtype": "Link",
+ "label": "Batch",
+ "options": "Batch"
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "conversion_factor",
- "fieldtype": "Float",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Conversion Factor",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 1,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "conversion_factor",
+ "fieldtype": "Float",
+ "label": "Conversion Factor",
+ "read_only": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "stock_uom",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Stock UOM",
- "length": 0,
- "no_copy": 0,
- "options": "UOM",
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 1,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 1,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "stock_uom",
+ "fieldtype": "Link",
+ "label": "Stock UOM",
+ "options": "UOM",
+ "read_only": 1,
+ "reqd": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "transfer_qty",
- "fieldtype": "Float",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Transfer Qty",
- "length": 0,
- "no_copy": 0,
- "permlevel": 0,
- "precision": "",
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 1,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
- },
+ "fieldname": "transfer_qty",
+ "fieldtype": "Float",
+ "label": "Transfer Qty",
+ "read_only": 1
+ },
{
- "allow_bulk_edit": 0,
- "allow_in_quick_entry": 0,
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
- "fieldname": "actual_qty",
- "fieldtype": "Float",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Actual Qty (at source/target)",
- "length": 0,
- "no_copy": 1,
- "permlevel": 0,
- "precision": "",
- "print_hide": 1,
- "print_hide_if_no_value": 0,
- "read_only": 1,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 1,
- "set_only_once": 0,
- "translatable": 0,
- "unique": 0
+ "fieldname": "actual_qty",
+ "fieldtype": "Float",
+ "label": "Actual Qty (at source/target)",
+ "no_copy": 1,
+ "print_hide": 1,
+ "read_only": 1,
+ "search_index": 1
}
- ],
- "has_web_view": 0,
- "hide_heading": 0,
- "hide_toolbar": 0,
- "idx": 0,
- "image_view": 0,
- "in_create": 0,
- "is_submittable": 0,
- "issingle": 0,
- "istable": 1,
- "max_attachments": 0,
- "modified": "2018-11-04 03:33:16.833884",
- "modified_by": "Administrator",
- "module": "Healthcare",
- "name": "Clinical Procedure Item",
- "name_case": "",
- "owner": "Administrator",
- "permissions": [],
- "quick_entry": 1,
- "read_only": 0,
- "read_only_onload": 0,
- "restrict_to_domain": "Healthcare",
- "show_name_in_global_search": 0,
- "sort_field": "modified",
- "sort_order": "DESC",
- "track_changes": 1,
- "track_seen": 0,
- "track_views": 0
+ ],
+ "istable": 1,
+ "links": [],
+ "modified": "2020-02-28 13:15:09.058073",
+ "modified_by": "Administrator",
+ "module": "Healthcare",
+ "name": "Clinical Procedure Item",
+ "owner": "Administrator",
+ "permissions": [],
+ "quick_entry": 1,
+ "restrict_to_domain": "Healthcare",
+ "sort_field": "modified",
+ "sort_order": "DESC",
+ "track_changes": 1
}
\ No newline at end of file
diff --git a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.js b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.js
index de0f9c4..181881e 100644
--- a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.js
+++ b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.js
@@ -3,32 +3,38 @@
frappe.ui.form.on('Clinical Procedure Template', {
template: function(frm) {
- if(!frm.doc.item_code)
- frm.set_value("item_code", frm.doc.template);
- if(!frm.doc.description)
- frm.set_value("description", frm.doc.template);
+ if (!frm.doc.item_code)
+ frm.set_value('item_code', frm.doc.template);
+ if (!frm.doc.description)
+ frm.set_value('description', frm.doc.template);
mark_change_in_item(frm);
},
+
rate: function(frm) {
mark_change_in_item(frm);
},
+
is_billable: function (frm) {
mark_change_in_item(frm);
},
+
item_group: function(frm) {
mark_change_in_item(frm);
},
+
description: function(frm) {
mark_change_in_item(frm);
},
+
medical_department: function(frm) {
mark_change_in_item(frm);
},
+
refresh: function(frm) {
- frm.fields_dict["items"].grid.set_column_disp("barcode", false);
- frm.fields_dict["items"].grid.set_column_disp("batch_no", false);
- cur_frm.set_df_property("item_code", "read_only", frm.doc.__islocal ? 0 : 1);
- if(!frm.doc.__islocal) {
+ frm.fields_dict['items'].grid.set_column_disp('barcode', false);
+ frm.fields_dict['items'].grid.set_column_disp('batch_no', false);
+
+ if (!frm.doc.__islocal) {
cur_frm.add_custom_button(__('Change Item Code'), function() {
change_template_code(frm.doc);
});
@@ -36,106 +42,104 @@
}
});
-var mark_change_in_item = function(frm) {
- if(!frm.doc.__islocal){
+let mark_change_in_item = function(frm) {
+ if (!frm.doc.__islocal) {
frm.doc.change_in_item = 1;
}
};
-var change_template_code = function(doc){
- var d = new frappe.ui.Dialog({
- title:__("Change Template Code"),
+let change_template_code = function(doc) {
+ let d = new frappe.ui.Dialog({
+ title:__('Change Item Code'),
fields:[
{
- "fieldtype": "Data",
- "label": "Template Code",
- "fieldname": "Item Code",
- reqd:1
- },
- {
- "fieldtype": "Button",
- "label": __("Change Code"),
- click: function() {
- var values = d.get_values();
- if(!values)
- return;
- change_item_code_from_template(values["Item Code"], doc);
- d.hide();
- }
+ 'fieldtype': 'Data',
+ 'label': 'Item Code',
+ 'fieldname': 'item_code',
+ reqd: 1
}
- ]
+ ],
+ primary_action: function() {
+ let values = d.get_values();
+
+ if (values) {
+ frappe.call({
+ 'method': 'erpnext.healthcare.doctype.clinical_procedure_template.clinical_procedure_template.change_item_code_from_template',
+ 'args': {item_code: values.item_code, doc: doc},
+ callback: function () {
+ cur_frm.reload_doc();
+ frappe.show_alert({
+ message: 'Item Code renamed successfully',
+ indicator: 'green'
+ });
+ }
+ });
+ }
+ d.hide();
+ },
+ primary_action_label: __('Change Item Code')
});
d.show();
- d.set_values({
- 'Item Code': doc.item_code
- });
-};
-var change_item_code_from_template = function(item_code, doc){
- frappe.call({
- "method": "erpnext.healthcare.doctype.clinical_procedure_template.clinical_procedure_template.change_item_code_from_template",
- "args": {item_code: item_code, doc: doc},
- callback: function () {
- cur_frm.reload_doc();
- frappe.show_alert({
- message: "Item Code renamed successfully",
- indicator: "green"
- });
- }
+ d.set_values({
+ 'item_code': doc.item_code
});
};
frappe.ui.form.on('Clinical Procedure Item', {
- qty: function(frm, cdt, cdn){
- var d = locals[cdt][cdn];
- frappe.model.set_value(cdt, cdn, "transfer_qty", d.qty*d.conversion_factor);
+ qty: function(frm, cdt, cdn) {
+ let d = locals[cdt][cdn];
+ frappe.model.set_value(cdt, cdn, 'transfer_qty', d.qty * d.conversion_factor);
},
+
uom: function(doc, cdt, cdn){
- var d = locals[cdt][cdn];
- if(d.uom && d.item_code){
+ let d = locals[cdt][cdn];
+ if (d.uom && d.item_code) {
return frappe.call({
- method: "erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details",
+ method: 'erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details',
args: {
item_code: d.item_code,
uom: d.uom,
qty: d.qty
},
callback: function(r) {
- if(r.message) {
+ if (r.message) {
frappe.model.set_value(cdt, cdn, r.message);
}
}
});
}
},
+
item_code: function(frm, cdt, cdn) {
- var d = locals[cdt][cdn];
- if(d.item_code) {
+ let d = locals[cdt][cdn];
+ if (d.item_code) {
let args = {
'item_code' : d.item_code,
'transfer_qty' : d.transfer_qty,
'company' : frm.doc.company,
- 'quantity' : d.qty
+ 'quantity' : d.qty
};
return frappe.call({
doc: frm.doc,
- method: "get_item_details",
+ method: 'get_item_details',
args: args,
callback: function(r) {
- if(r.message) {
- var d = locals[cdt][cdn];
+ if (r.message) {
+ let d = locals[cdt][cdn];
$.each(r.message, function(k, v){
d[k] = v;
});
- refresh_field("items");
+ refresh_field('items');
}
}
});
}
}
});
+
// List Stock items
-cur_frm.set_query("item_code", "items", function() {
+cur_frm.set_query('item_code', 'items', function() {
return {
filters: {
is_stock_item:1
diff --git a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.json b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.json
index 7ae4be8..a93f69f 100644
--- a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.json
+++ b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.json
@@ -79,6 +79,8 @@
"depends_on": "is_billable",
"fieldname": "rate",
"fieldtype": "Float",
+ "in_list_view": 1,
+ "in_standard_filter": 1,
"label": "Rate",
"mandatory_depends_on": "is_billable"
},
@@ -127,7 +129,8 @@
"fetch_from": "sample.sample_uom",
"fieldname": "sample_uom",
"fieldtype": "Data",
- "label": "UOM"
+ "label": "Sample UOM",
+ "read_only": 1
},
{
"fieldname": "sample_qty",
@@ -163,6 +166,8 @@
{
"fieldname": "item",
"fieldtype": "Link",
+ "in_list_view": 1,
+ "in_standard_filter": 1,
"label": "Item",
"no_copy": 1,
"options": "Item",
@@ -170,7 +175,7 @@
}
],
"links": [],
- "modified": "2020-02-27 16:32:55.780893",
+ "modified": "2020-02-28 13:20:23.692613",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Clinical Procedure Template",
diff --git a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py
index 3bfca6c..ebf6afd 100644
--- a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py
+++ b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template.py
@@ -17,16 +17,8 @@
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()
+ if self.change_in_item:
+ self.update_item_and_item_price()
def enable_disable_item(self):
if self.is_billable:
@@ -35,26 +27,26 @@
else:
frappe.db.set_value('Item', self.item, 'disabled', 0)
- #Call before delete the template
def on_trash(self):
- if(self.item):
+ 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"""))
+ frappe.throw(_('Not permitted. Please disable the Procedure Template'), title='Not Permitted')
def get_item_details(self, args=None):
- item = frappe.db.sql("""select stock_uom, item_name
- from `tabItem`
- where name = %s
- and disabled=0
- 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)
+ item = frappe.db.get_all('Item',
+ filters={
+ 'disabled': 0,
+ 'name': args.get('item_code')
+ },
+ fields=['stock_uom', 'item_name']
+ )
+
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').format(args.get('item_code')))
item = item[0]
-
ret = {
'uom' : item.stock_uom,
'stock_uom' : item.stock_uom,
@@ -65,22 +57,34 @@
}
return ret
-def updating_item(self):
- frappe.db.sql("""update `tabItem` set item_name=%s, item_group=%s, disabled=0,
- description=%s, modified=NOW() where item_code=%s""",
- (self.template, self.item_group , self.description, self.item))
-def updating_rate(self):
- frappe.db.sql("""update `tabItem Price` set item_name=%s, price_list_rate=%s, modified=NOW() where
- item_code=%s""",(self.template, self.rate, self.item))
+ def update_item_and_item_price(self):
+ if self.is_billable and self.item:
+ item_doc = frappe.get_doc('Item', {'item_code': self.item})
+ item_doc.item_name = self.template
+ item_doc.item_group = self.item_group
+ item_doc.description = self.description
+ item_doc.disabled = 0
+ 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.template
+ item_price.price_list_name = self.rate
+ item_price.save()
+
+ elif not self.is_billable 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 create_item_from_template(doc):
- disabled = 1
-
- if doc.is_billable == 1:
+ disabled = doc.disabled
+ if doc.is_billable and not doc.disabled:
disabled = 0
- #insert item
- item = frappe.get_doc({
+ item = frappe.get_doc({
'doctype': 'Item',
'item_code': doc.template,
'item_name':doc.template,
@@ -96,20 +100,13 @@
'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})
- 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
+ make_item_price(item.name, doc.rate)
+
frappe.db.set_value('Clinical Procedure Template', doc.name, 'item', item.name)
+ doc.reload()
- doc.reload() #refresh the doc after insert.
-
-def make_item_price(item, price_list_name, item_price):
+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,
@@ -119,13 +116,10 @@
@frappe.whitelist()
def change_item_code_from_template(item_code, doc):
- args = json.loads(doc)
- doc = frappe._dict(args)
+ doc = frappe._dict(json.loads(doc))
- if(frappe.db.exists({
- 'doctype': 'Item',
- 'item_code': item_code})):
- frappe.throw(_('Code {0} already exist').format(item_code))
+ if frappe.db.exists('Item', {'item_code': item_code}):
+ frappe.throw(_('Item with Item Code {0} already exists').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)
diff --git a/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template_dashboard.py b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template_dashboard.py
new file mode 100644
index 0000000..9aab521
--- /dev/null
+++ b/erpnext/healthcare/doctype/clinical_procedure_template/clinical_procedure_template_dashboard.py
@@ -0,0 +1,13 @@
+from __future__ import unicode_literals
+from frappe import _
+
+def get_data():
+ return {
+ 'fieldname': 'procedure_template',
+ 'transactions': [
+ {
+ 'label': _('Consultations'),
+ 'items': ['Clinical Procedure']
+ }
+ ]
+ }