Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(healthcare service unit): Tree view add_node and related fixes (backport #495) #496

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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()
Loading