fix: create fee validity for new patients only
diff --git a/erpnext/healthcare/doctype/fee_validity/fee_validity.json b/erpnext/healthcare/doctype/fee_validity/fee_validity.json
index e746b3c..b001bf0 100644
--- a/erpnext/healthcare/doctype/fee_validity/fee_validity.json
+++ b/erpnext/healthcare/doctype/fee_validity/fee_validity.json
@@ -29,6 +29,7 @@
"in_list_view": 1,
"label": "Healthcare Practitioner",
"options": "Healthcare Practitioner",
+ "read_only": 1,
"reqd": 1,
"search_index": 1
},
@@ -38,23 +39,27 @@
"in_list_view": 1,
"label": "Patient",
"options": "Patient",
+ "read_only": 1,
"reqd": 1,
"search_index": 1
},
{
"fieldname": "visited",
"fieldtype": "Int",
- "label": "Visited yet"
+ "label": "Visited yet",
+ "read_only": 1
},
{
"fieldname": "valid_till",
"fieldtype": "Date",
- "label": "Valid till"
+ "label": "Valid till",
+ "read_only": 1
},
{
"fieldname": "section_break_3",
"fieldtype": "Section Break",
- "label": "Validity"
+ "label": "Validity",
+ "read_only": 1
},
{
"fieldname": "column_break_6",
@@ -63,7 +68,8 @@
{
"fieldname": "max_visits",
"fieldtype": "Int",
- "label": "Max number of visit"
+ "label": "Max number of visit",
+ "read_only": 1
},
{
"fieldname": "column_break_3",
@@ -89,7 +95,8 @@
"fieldname": "ref_appointments",
"fieldtype": "Table MultiSelect",
"label": "Reference Appointments",
- "options": "Fee Validity Reference"
+ "options": "Fee Validity Reference",
+ "read_only": 1
},
{
"collapsible": 1,
@@ -97,8 +104,9 @@
"fieldtype": "Section Break"
}
],
+ "in_create": 1,
"links": [],
- "modified": "2020-03-17 18:29:01.163961",
+ "modified": "2020-03-17 20:25:06.487418",
"modified_by": "Administrator",
"module": "Healthcare",
"name": "Fee Validity",
diff --git a/erpnext/healthcare/doctype/fee_validity/fee_validity.py b/erpnext/healthcare/doctype/fee_validity/fee_validity.py
index b56b889..dcfc846 100644
--- a/erpnext/healthcare/doctype/fee_validity/fee_validity.py
+++ b/erpnext/healthcare/doctype/fee_validity/fee_validity.py
@@ -30,6 +30,9 @@
def create_fee_validity(appointment):
+ if not check_is_new_patient(appointment):
+ return
+
fee_validity = frappe.new_doc('Fee Validity')
fee_validity.practitioner = appointment.practitioner
fee_validity.patient = appointment.patient
@@ -42,3 +45,19 @@
})
fee_validity.save(ignore_permissions=True)
return fee_validity
+
+def check_is_new_patient(appointment):
+ validity_exists = frappe.db.exists('Fee Validity', {
+ 'practitioner': appointment.practitioner,
+ 'patient': appointment.patient
+ })
+ if validity_exists:
+ return False
+
+ appointment_exists = frappe.db.get_all('Patient Appointment', {
+ 'name': ('!=', appointment.name),
+ 'status': ('!=', 'Cancelled')
+ })
+ if len(appointment_exists) and appointment_exists[0]:
+ return False
+ return True
\ No newline at end of file