From f2574dde37e29565201592f32e4994b5b65eab57 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Tue, 17 Mar 2020 19:28:18 +0530 Subject: [PATCH] fix: set fee validity start date and set status as Completed or Pending --- .../doctype/fee_validity/fee_validity.json | 4 ++-- .../doctype/fee_validity/fee_validity.py | 23 ++++++++++--------- .../patient_appointment.py | 2 +- erpnext/healthcare/utils.py | 16 +++++++++---- erpnext/hooks.py | 3 +-- 5 files changed, 27 insertions(+), 21 deletions(-) diff --git a/erpnext/healthcare/doctype/fee_validity/fee_validity.json b/erpnext/healthcare/doctype/fee_validity/fee_validity.json index 84321694dd..e746b3c442 100644 --- a/erpnext/healthcare/doctype/fee_validity/fee_validity.json +++ b/erpnext/healthcare/doctype/fee_validity/fee_validity.json @@ -75,7 +75,7 @@ "in_list_view": 1, "in_standard_filter": 1, "label": "Status", - "options": "Ongoing\nCompleted\nExpired", + "options": "Completed\nPending", "read_only": 1 }, { @@ -98,7 +98,7 @@ } ], "links": [], - "modified": "2020-03-14 21:42:40.766973", + "modified": "2020-03-17 18:29:01.163961", "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 fc15410207..b56b8894b0 100644 --- a/erpnext/healthcare/doctype/fee_validity/fee_validity.py +++ b/erpnext/healthcare/doctype/fee_validity/fee_validity.py @@ -11,17 +11,23 @@ import datetime class FeeValidity(Document): def validate(self): self.update_status() + self.set_start_date() def update_status(self): valid_till = getdate(self.valid_till) - today = getdate() + start_date = getdate(self.start_date) if self.visited >= self.max_visits: self.status = 'Completed' - elif self.visited < self.max_visits: - if valid_till >= today: - self.status = 'Ongoing' - elif valid_till < today: - self.status = 'Expired' + else: + self.status = 'Pending' + + def set_start_date(self): + self.start_date = getdate() + for appointment in self.ref_appointments: + appointment_date = frappe.db.get_value('Patient Appointment', appointment.appointment, 'appointment_date') + if getdate(appointment_date) < self.start_date: + self.start_date = getdate(appointment_date) + def create_fee_validity(appointment): fee_validity = frappe.new_doc('Fee Validity') @@ -36,8 +42,3 @@ def create_fee_validity(appointment): }) fee_validity.save(ignore_permissions=True) return fee_validity - -def update_validity_status(): - docs = frappe.get_all('Fee Validity', filters={'status': ['not in', ['Completed', 'Expired']]}) - for doc in docs: - frappe.get_doc("Task", doc.name).update_status() diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py index 1cf90c6786..361a8d673e 100755 --- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py +++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.py @@ -95,7 +95,7 @@ def check_payment_fields_reqd(patient): free_follow_ups = frappe.db.get_single_value('Healthcare Settings', 'enable_free_follow_ups') if automate_invoicing: if free_follow_ups: - fee_validity = frappe.db.exists('Fee Validity', {'patient': patient, 'status': 'Ongoing'}) + fee_validity = frappe.db.exists('Fee Validity', {'patient': patient, 'status': 'Pending'}) if fee_validity: return {'fee_validity': fee_validity} return True diff --git a/erpnext/healthcare/utils.py b/erpnext/healthcare/utils.py index d1b5b7c04d..1912270e0e 100644 --- a/erpnext/healthcare/utils.py +++ b/erpnext/healthcare/utils.py @@ -42,6 +42,9 @@ def validate_customer_created(patient): frappe.throw(msg, title=_('Customer Not Found')) def get_fee_validity(patient_appointments): + if not frappe.db.get_single_value('Healthcare Settings', 'enable_free_follow_ups'): + return + fee_validity_details = [] items_to_invoice = [] valid_days = frappe.db.get_single_value('Healthcare Settings', 'valid_days') @@ -346,18 +349,21 @@ def manage_prescriptions(invoiced, ref_dt, ref_dn, dt, created_check_field): def check_fee_validity(appointment): + if not frappe.db.get_single_value('Healthcare Settings', 'enable_free_follow_ups'): + return + validity = frappe.db.exists('Fee Validity', { 'practitioner': appointment.practitioner, 'patient': appointment.patient, - 'status': 'Ongoing' + 'status': 'Pending', + 'valid_till': ('>=', appointment.appointment_date) }) if not validity: return - fee_validity = frappe.get_doc('Fee Validity', validity) - appointment_date = getdate(appointment.appointment_date) - if fee_validity.valid_till >= appointment_date and fee_validity.visited < fee_validity.max_visits: - return fee_validity + validity = frappe.get_doc('Fee Validity', validity) + return validity + def manage_fee_validity(appointment): fee_validity = check_fee_validity(appointment) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 7a938b6819..4e22ed5cdb 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -310,8 +310,7 @@ scheduler_events = { "erpnext.crm.doctype.email_campaign.email_campaign.send_email_to_leads_or_contacts", "erpnext.crm.doctype.email_campaign.email_campaign.set_email_campaign_status", "erpnext.selling.doctype.quotation.quotation.set_expired_status", - "erpnext.healthcare.doctype.patient_appointment.patient_appointment.update_appointment_status", - "erpnext.healthcare.doctype.fee_validity.fee_validity.update_validity_status" + "erpnext.healthcare.doctype.patient_appointment.patient_appointment.update_appointment_status" ], "daily_long": [ "erpnext.setup.doctype.email_digest.email_digest.send",