fix: set fee validity start date and set status as Completed or Pending

This commit is contained in:
Rucha Mahabal 2020-03-17 19:28:18 +05:30
parent 2f2c09bd98
commit f2574dde37
5 changed files with 27 additions and 21 deletions

View File

@ -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",

View File

@ -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()

View File

@ -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

View File

@ -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)

View File

@ -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",