From 4e5b652372682495ed40ff2c5cc396dadac34f31 Mon Sep 17 00:00:00 2001 From: Gokul1407 Date: Tue, 6 Aug 2024 12:43:48 +0530 Subject: [PATCH] fix(healthcare service unit): Tree view add_node and related fixes (cherry picked from commit 02d70d3b375ade6d4ee346b106e665dfadf61c8f) --- .../healthcare_service_unit.js | 2 +- .../healthcare_service_unit.py | 2 +- .../healthcare_service_unit_tree.js | 3 ++- healthcare/healthcare/utils.py | 14 +++++++++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.js b/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.js index 65796c6ae5..5132775c26 100644 --- a/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.js +++ b/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.js @@ -42,7 +42,7 @@ frappe.ui.form.on('Healthcare Service Unit', { set_root_readonly: function(frm) { // read-only for root healthcare service unit frm.set_intro(''); - if (!frm.doc.parent_healthcare_service_unit) { + if (!frm.is_new() && !frm.doc.parent_healthcare_service_unit) { frm.set_read_only(); frm.set_intro(__('This is a root healthcare service unit and cannot be edited.'), true); } diff --git a/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py b/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py index 34e6406bac..8ccc3e7b43 100644 --- a/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py +++ b/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py @@ -103,7 +103,7 @@ def add_multiple_service_units(parent, data): service_unit = { "doctype": "Healthcare Service Unit", - "parent_healthcare_service_unit": parent, + "parent_healthcare_service_unit": parent if parent != company else None, "service_unit_type": data.get("service_unit_type") or None, "service_unit_capacity": capacity if capacity > 0 else 1, "warehouse": data.get("warehouse") or None, diff --git a/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js b/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js index 24b8125f8b..c8cc903202 100644 --- a/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js +++ b/healthcare/healthcare/doctype/healthcare_service_unit/healthcare_service_unit_tree.js @@ -5,6 +5,7 @@ frappe.treeview_settings['Healthcare Service Unit'] = { title: __('Service Unit Tree'), get_tree_root: false, get_tree_nodes: 'healthcare.healthcare.utils.get_children', + add_tree_node: 'healthcare.healthcare.utils.add_node', filters: [{ fieldname: 'company', fieldtype: 'Select', @@ -24,7 +25,7 @@ frappe.treeview_settings['Healthcare Service Unit'] = { { fieldtype: 'Link', fieldname: 'service_unit_type', label: __('Service Unit Type'), options: 'Healthcare Service Unit Type', description: __('Type of the new Service Unit'), - depends_on: 'eval:!doc.is_group', default: '', + depends_on: 'eval:!doc.is_group', default: '', mandatory_depends_on: 'eval:!doc.is_group', onchange: () => { if (cur_dialog) { if (cur_dialog.fields_dict.service_unit_type.value) { diff --git a/healthcare/healthcare/utils.py b/healthcare/healthcare/utils.py index 67d43ac528..4b485a90dd 100644 --- a/healthcare/healthcare/utils.py +++ b/healthcare/healthcare/utils.py @@ -9,7 +9,7 @@ import frappe from frappe import _ -from frappe.utils import cstr, flt, get_link_to_form, rounded, time_diff_in_hours +from frappe.utils import cint, cstr, flt, get_link_to_form, rounded, time_diff_in_hours from frappe.utils.formatters import format_value from erpnext.setup.utils import insert_record @@ -1290,3 +1290,15 @@ def generate_barcodes(in_val): stream.close() return barcode_base64 + + +@frappe.whitelist() +def add_node(): + from frappe.desk.treeview import make_tree_args + + args = make_tree_args(**frappe.form_dict) + + if cint(args.is_root): + args.parent_healthcare_service_unit = None + + frappe.get_doc(args).insert()