Skip to content

Commit

Permalink
fix(healthcare service unit): Tree view add_node and related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gokul1407 authored and Sajinsr committed Aug 9, 2024
1 parent 14ff9cb commit 02d70d3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion healthcare/healthcare/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1327,3 +1327,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()

0 comments on commit 02d70d3

Please sign in to comment.