fix: tests
This commit is contained in:
parent
0eeaad8ce7
commit
4f9a1471e4
@ -11,21 +11,32 @@ from frappe.utils import nowdate, add_days, getdate
|
||||
test_dependencies = ["Company"]
|
||||
|
||||
class TestFeeValidity(unittest.TestCase):
|
||||
def test_fee_validity(self):
|
||||
def setUp(self):
|
||||
frappe.db.sql("""delete from `tabPatient Appointment`""")
|
||||
frappe.db.sql("""delete from `tabFee Validity`""")
|
||||
|
||||
def test_fee_validity(self):
|
||||
patient = get_random("Patient")
|
||||
practitioner = get_random("Healthcare Practitioner")
|
||||
department = get_random("Medical Department")
|
||||
medical_department = get_random("Medical Department")
|
||||
|
||||
item = create_healthcare_service_items()
|
||||
healthcare_settings = frappe.get_single("Healthcare Settings")
|
||||
healthcare_settings.enable_free_follow_ups = 1
|
||||
healthcare_settings.max_visits = 2
|
||||
healthcare_settings.valid_days = 7
|
||||
healthcare_settings.automate_appointment_invoicing = 1
|
||||
healthcare_settings.op_consulting_charge_item = item
|
||||
healthcare_settings.save(ignore_permissions=True)
|
||||
|
||||
if not patient:
|
||||
patient = frappe.new_doc("Patient")
|
||||
patient.patient_name = "_Test Patient"
|
||||
patient.first_name = "_Test Patient"
|
||||
patient.sex = "Male"
|
||||
patient.save(ignore_permissions=True)
|
||||
patient = patient.name
|
||||
|
||||
if not department:
|
||||
if not medical_department:
|
||||
medical_department = frappe.new_doc("Medical Department")
|
||||
medical_department.department = "_Test Medical Department"
|
||||
medical_department.save(ignore_permissions=True)
|
||||
@ -34,71 +45,53 @@ class TestFeeValidity(unittest.TestCase):
|
||||
if not practitioner:
|
||||
practitioner = frappe.new_doc("Healthcare Practitioner")
|
||||
practitioner.first_name = "_Test Healthcare Practitioner"
|
||||
practitioner.gender = 'Female'
|
||||
practitioner.department = department
|
||||
practitioner.op_consulting_charge = 500
|
||||
practitioner.save(ignore_permissions=True)
|
||||
practitioner = practitioner.name
|
||||
|
||||
|
||||
|
||||
frappe.db.set_value("Healthcare Settings", None, "max_visits", 2)
|
||||
frappe.db.set_value("Healthcare Settings", None, "valid_days", 7)
|
||||
|
||||
appointment = create_appointment(patient, practitioner, nowdate(), department)
|
||||
# appointment should not be invoiced as it is within fee validity
|
||||
appointment = create_appointment(patient, practitioner, nowdate())
|
||||
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
|
||||
self.assertEqual(invoiced, 0)
|
||||
|
||||
invoice_appointment(appointment)
|
||||
|
||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4), department)
|
||||
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
|
||||
self.assertTrue(invoiced)
|
||||
|
||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 5), department)
|
||||
# appointment should not be invoiced as it is within fee validity
|
||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4))
|
||||
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
|
||||
self.assertEqual(invoiced, 0)
|
||||
|
||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 10), department)
|
||||
# appointment should be invoiced as it is within fee validity but the max_visits are exceeded
|
||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 5), invoice=1)
|
||||
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
|
||||
self.assertEqual(invoiced, 0)
|
||||
self.assertEqual(invoiced, 1)
|
||||
|
||||
def create_appointment(patient, practitioner, appointment_date, department):
|
||||
# appointment should be invoiced as it is not within fee validity and the max_visits are exceeded
|
||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 10), invoice=1)
|
||||
invoiced = frappe.db.get_value("Patient Appointment", appointment.name, "invoiced")
|
||||
self.assertEqual(invoiced, 1)
|
||||
|
||||
def create_appointment(patient, practitioner, appointment_date, invoice=0):
|
||||
appointment = frappe.new_doc("Patient Appointment")
|
||||
appointment.patient = patient
|
||||
appointment.practitioner = practitioner
|
||||
appointment.department = department
|
||||
appointment.department = "_Test Medical Department"
|
||||
appointment.appointment_date = appointment_date
|
||||
appointment.company = "_Test Company"
|
||||
appointment.duration = 15
|
||||
if invoice:
|
||||
appointment.mode_of_payment = "Cash"
|
||||
appointment.paid_amount = 500
|
||||
appointment.save(ignore_permissions=True)
|
||||
return appointment
|
||||
|
||||
def invoice_appointment(appointment_doc):
|
||||
if not appointment_doc.name:
|
||||
return False
|
||||
sales_invoice = frappe.new_doc("Sales Invoice")
|
||||
sales_invoice.customer = frappe.get_value("Patient", appointment_doc.patient, "customer")
|
||||
sales_invoice.due_date = getdate()
|
||||
sales_invoice.is_pos = 0
|
||||
sales_invoice.company = appointment_doc.company
|
||||
sales_invoice.debit_to = "_Test Receivable - _TC"
|
||||
|
||||
create_invoice_items(appointment_doc, sales_invoice)
|
||||
|
||||
sales_invoice.save(ignore_permissions=True)
|
||||
sales_invoice.submit()
|
||||
|
||||
def create_invoice_items(appointment, invoice):
|
||||
item_line = invoice.append("items")
|
||||
item_line.item_name = "Consulting Charges"
|
||||
item_line.description = "Consulting Charges: " + appointment.practitioner
|
||||
item_line.uom = "Nos"
|
||||
item_line.conversion_factor = 1
|
||||
item_line.income_account = "_Test Account Cost for Goods Sold - _TC"
|
||||
item_line.cost_center = "_Test Cost Center - _TC"
|
||||
item_line.rate = 250
|
||||
item_line.amount = 250
|
||||
item_line.qty = 1
|
||||
item_line.reference_dt = "Patient Appointment"
|
||||
item_line.reference_dn = appointment.name
|
||||
|
||||
return invoice
|
||||
def create_healthcare_service_items():
|
||||
if frappe.db.exists("Item", "HLC-SI-001"):
|
||||
return "HLC-SI-001"
|
||||
item = frappe.new_doc("Item")
|
||||
item.item_code = "HLC-SI-001"
|
||||
item.item_name = "Consulting Charges"
|
||||
item.item_group = "Services"
|
||||
item.is_stock_item = 0
|
||||
item.save()
|
||||
return item.name
|
@ -61,8 +61,7 @@
|
||||
{
|
||||
"fieldname": "last_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Last Name",
|
||||
"reqd": 1
|
||||
"label": "Last Name"
|
||||
},
|
||||
{
|
||||
"fieldname": "image",
|
||||
@ -278,7 +277,7 @@
|
||||
],
|
||||
"image_field": "image",
|
||||
"links": [],
|
||||
"modified": "2020-02-01 00:39:49.455988",
|
||||
"modified": "2020-03-20 15:13:13.382212",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Healthcare Practitioner",
|
||||
|
@ -44,7 +44,10 @@ class HealthcarePractitioner(Document):
|
||||
frappe.permissions.add_user_permission('Healthcare Practitioner', self.name, self.user_id)
|
||||
|
||||
def set_full_name(self):
|
||||
self.practitioner_name = ' '.join(filter(None, [self.first_name, self.last_name]))
|
||||
if self.last_name:
|
||||
self.practitioner_name = ' '.join(filter(None, [self.first_name, self.last_name]))
|
||||
else:
|
||||
self.practitioner_name = self.first_name
|
||||
|
||||
def validate_user_id(self):
|
||||
if not frappe.db.exists('User', self.user_id):
|
||||
|
@ -79,7 +79,7 @@ def get_patient():
|
||||
patient = get_random("Patient")
|
||||
if not patient:
|
||||
patient = frappe.new_doc("Patient")
|
||||
patient.patient_name = "Test Patient"
|
||||
patient.first_name = "_Test Patient"
|
||||
patient.sex = "Male"
|
||||
patient.save(ignore_permissions=True)
|
||||
return patient.name
|
||||
|
@ -342,8 +342,7 @@
|
||||
{
|
||||
"fieldname": "last_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Last Name",
|
||||
"reqd": 1
|
||||
"label": "Last Name"
|
||||
},
|
||||
{
|
||||
"fieldname": "first_name",
|
||||
@ -362,7 +361,7 @@
|
||||
"image_field": "image",
|
||||
"links": [],
|
||||
"max_attachments": 50,
|
||||
"modified": "2020-02-25 17:56:46.351080",
|
||||
"modified": "2020-03-20 14:59:53.945849",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Healthcare",
|
||||
"name": "Patient",
|
||||
|
@ -27,7 +27,10 @@ class Patient(Document):
|
||||
self.reload()
|
||||
|
||||
def set_full_name(self):
|
||||
self.patient_name = ' '.join(filter(None, [self.first_name, self.last_name]))
|
||||
if self.last_name:
|
||||
self.patient_name = ' '.join(filter(None, [self.first_name, self.last_name]))
|
||||
else:
|
||||
self.patient_name = self.first_name
|
||||
|
||||
def add_as_website_user(self):
|
||||
if self.email:
|
||||
|
@ -23,9 +23,9 @@ class PatientAppointment(Document):
|
||||
self.set_status()
|
||||
|
||||
def after_insert(self):
|
||||
invoice_appointment(self)
|
||||
self.update_prescription_details()
|
||||
self.update_fee_validity()
|
||||
invoice_appointment(self)
|
||||
send_confirmation_msg(self)
|
||||
|
||||
def set_status(self):
|
||||
@ -105,6 +105,10 @@ def invoice_appointment(appointment_doc):
|
||||
automate_invoicing = frappe.db.get_single_value('Healthcare Settings', 'automate_appointment_invoicing')
|
||||
appointment_invoiced = frappe.db.get_value('Patient Appointment', appointment_doc.name, 'invoiced')
|
||||
fee_validity = check_fee_validity(appointment_doc)
|
||||
if not fee_validity:
|
||||
if frappe.db.exists('Fee Validity Reference', {'appointment': appointment_doc.name}):
|
||||
return
|
||||
|
||||
if automate_invoicing and not appointment_invoiced and not fee_validity:
|
||||
sales_invoice = frappe.new_doc('Sales Invoice')
|
||||
sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer')
|
||||
|
@ -232,11 +232,11 @@ def get_service_item_and_practitioner_charge(doc):
|
||||
|
||||
|
||||
def throw_config_service_item(is_inpatient):
|
||||
service_item_lable = 'Out Patient Consulting Charge Item'
|
||||
service_item_label = 'Out Patient Consulting Charge Item'
|
||||
if is_inpatient:
|
||||
service_item_lable = 'Inpatient Visit Charge Item'
|
||||
service_item_label = 'Inpatient Visit Charge Item'
|
||||
|
||||
msg = _(('Please Configure {0} in ').format(service_item_lable) \
|
||||
msg = _(('Please Configure {0} in ').format(service_item_label) \
|
||||
+ '''<b><a href='#Form/Healthcare Settings'>Healthcare Settings</a></b>''')
|
||||
frappe.throw(msg, title=_('Missing Configuration'))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user