fix: service unit create - set fields based on service unit type, added validations
diff --git a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json
index ea4ae84..9ee865a 100644
--- a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json
+++ b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.json
@@ -12,7 +12,6 @@
"engine": "InnoDB",
"field_order": [
"healthcare_service_unit_name",
- "parent_healthcare_service_unit",
"is_group",
"service_unit_type",
"allow_appointments",
@@ -20,8 +19,10 @@
"inpatient_occupancy",
"occupancy_status",
"column_break_9",
- "warehouse",
"company",
+ "warehouse",
+ "tree_details_section",
+ "parent_healthcare_service_unit",
"lft",
"rgt",
"old_parent"
@@ -51,7 +52,6 @@
"depends_on": "eval:doc.inpatient_occupancy != 1 && doc.allow_appointments != 1",
"fieldname": "is_group",
"fieldtype": "Check",
- "in_list_view": 1,
"label": "Is Group"
},
{
@@ -63,12 +63,12 @@
"options": "Healthcare Service Unit Type"
},
{
- "bold": 1,
"default": "0",
"depends_on": "eval:doc.is_group != 1 && doc.inpatient_occupancy != 1",
"fetch_from": "service_unit_type.allow_appointments",
"fieldname": "allow_appointments",
"fieldtype": "Check",
+ "in_list_view": 1,
"label": "Allow Appointments",
"no_copy": 1,
"read_only": 1
@@ -90,6 +90,7 @@
"fetch_from": "service_unit_type.inpatient_occupancy",
"fieldname": "inpatient_occupancy",
"fieldtype": "Check",
+ "in_list_view": 1,
"label": "Inpatient Occupancy",
"no_copy": 1,
"read_only": 1,
@@ -101,7 +102,7 @@
"fieldtype": "Select",
"label": "Occupancy Status",
"no_copy": 1,
- "options": "\nVacant\nOccupied",
+ "options": "Vacant\nOccupied",
"read_only": 1
},
{
@@ -157,10 +158,16 @@
"options": "Healthcare Service Unit",
"print_hide": 1,
"report_hide": 1
+ },
+ {
+ "collapsible": 1,
+ "fieldname": "tree_details_section",
+ "fieldtype": "Section Break",
+ "label": "Tree Details"
}
],
"links": [],
- "modified": "2020-03-26 16:13:08.675952",
+ "modified": "2020-05-20 18:26:56.065543",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Healthcare Service Unit",
diff --git a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py
index 13cc43d..9720078 100644
--- a/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py
+++ b/erpnext/healthcare/doctype/healthcare_service_unit/healthcare_service_unit.py
@@ -27,5 +27,11 @@
self.allow_appointments = 0
self.overlap_appointments = 0
self.inpatient_occupancy = 0
- elif not self.allow_appointments:
- self.overlap_appointments = 0
+ elif self.service_unit_type:
+ service_unit_type = frappe.get_doc('Healthcare Service Unit Type', self.service_unit_type)
+ self.allow_appointments = service_unit_type.allow_appointments
+ self.overlap_appointments = service_unit_type.overlap_appointments
+ self.inpatient_occupancy = service_unit_type.inpatient_occupancy
+ if self.inpatient_occupancy:
+ self.occupancy_status = 'Vacant'
+ self.overlap_appointments = 0
diff --git a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json
index 5fa47d9..4b8503d 100644
--- a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json
+++ b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.json
@@ -31,6 +31,7 @@
"fieldtype": "Data",
"in_list_view": 1,
"label": "Service Unit Type",
+ "no_copy": 1,
"reqd": 1,
"unique": 1
},
@@ -40,8 +41,7 @@
"depends_on": "eval:doc.inpatient_occupancy != 1",
"fieldname": "allow_appointments",
"fieldtype": "Check",
- "label": "Allow Appointments",
- "no_copy": 1
+ "label": "Allow Appointments"
},
{
"bold": 1,
@@ -49,8 +49,7 @@
"depends_on": "eval:doc.allow_appointments == 1 && doc.inpatient_occupany != 1",
"fieldname": "overlap_appointments",
"fieldtype": "Check",
- "label": "Allow Overlap",
- "no_copy": 1
+ "label": "Allow Overlap"
},
{
"bold": 1,
@@ -58,8 +57,7 @@
"depends_on": "eval:doc.allow_appointments != 1",
"fieldname": "inpatient_occupancy",
"fieldtype": "Check",
- "label": "Inpatient Occupancy",
- "no_copy": 1
+ "label": "Inpatient Occupancy"
},
{
"bold": 1,
@@ -79,6 +77,7 @@
"fieldname": "item",
"fieldtype": "Link",
"label": "Item",
+ "no_copy": 1,
"options": "Item",
"read_only": 1
},
@@ -86,7 +85,8 @@
"fieldname": "item_code",
"fieldtype": "Data",
"label": "Item Code",
- "mandatory_depends_on": "eval: doc.is_billable == 1"
+ "mandatory_depends_on": "eval: doc.is_billable == 1",
+ "no_copy": 1
},
{
"fieldname": "item_group",
@@ -138,7 +138,7 @@
}
],
"links": [],
- "modified": "2020-01-30 16:06:00.624496",
+ "modified": "2020-05-20 15:31:09.627516",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Healthcare Service Unit Type",
diff --git a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py
index 286ecc0..a99358c 100644
--- a/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py
+++ b/erpnext/healthcare/doctype/healthcare_service_unit_type/healthcare_service_unit_type.py
@@ -10,6 +10,20 @@
class HealthcareServiceUnitType(Document):
def validate(self):
+ if self.allow_appointments and self.inpatient_occupancy:
+ frappe.msgprint(
+ _('Healthcare Service Unit Type cannot be both <b>Allow Appointments</b> and <b>Inpatient Occupancy</b>'),
+ raise_exception=1, title=_('Validation Error'), indicator='red'
+ )
+ elif not self.allow_appointments and not self.inpatient_occupancy:
+ frappe.msgprint(
+ _('Healthcare Service Unit Type cannot be both <b>Allow Appointments</b> and <b>Inpatient Occupancy</b>'),
+ raise_exception=1, title=_('Validation Error'), indicator='red'
+ )
+
+ if not self.allow_appointments:
+ self.overlap_appointments = 0
+
if self.is_billable:
if self.disabled:
frappe.db.set_value('Item', self.item, 'disabled', 1)