mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
fix: patient appointment
auto invoicing: record payment if payment mode and amount available test: fixes
This commit is contained in:
@@ -123,22 +123,24 @@ def invoice_appointment(appointment_doc):
|
|||||||
sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer')
|
sales_invoice.customer = frappe.get_value('Patient', appointment_doc.patient, 'customer')
|
||||||
sales_invoice.appointment = appointment_doc.name
|
sales_invoice.appointment = appointment_doc.name
|
||||||
sales_invoice.due_date = getdate()
|
sales_invoice.due_date = getdate()
|
||||||
sales_invoice.is_pos = 1
|
|
||||||
sales_invoice.company = appointment_doc.company
|
sales_invoice.company = appointment_doc.company
|
||||||
sales_invoice.debit_to = get_receivable_account(appointment_doc.company)
|
sales_invoice.debit_to = get_receivable_account(appointment_doc.company)
|
||||||
|
|
||||||
item = sales_invoice.append('items', {})
|
item = sales_invoice.append('items', {})
|
||||||
item = get_appointment_item(appointment_doc, item)
|
item = get_appointment_item(appointment_doc, item)
|
||||||
|
|
||||||
payment = sales_invoice.append('payments', {})
|
# Add payments if payment details are supplied else proceed to create invoice as Unpaid
|
||||||
payment.mode_of_payment = appointment_doc.mode_of_payment
|
if appointment_doc.mode_of_payment and appointment_doc.paid_amount:
|
||||||
payment.amount = appointment_doc.paid_amount
|
sales_invoice.is_pos = 1
|
||||||
|
payment = sales_invoice.append('payments', {})
|
||||||
|
payment.mode_of_payment = appointment_doc.mode_of_payment
|
||||||
|
payment.amount = appointment_doc.paid_amount
|
||||||
|
|
||||||
sales_invoice.set_missing_values(for_validate=True)
|
sales_invoice.set_missing_values(for_validate=True)
|
||||||
sales_invoice.flags.ignore_mandatory = True
|
sales_invoice.flags.ignore_mandatory = True
|
||||||
sales_invoice.save(ignore_permissions=True)
|
sales_invoice.save(ignore_permissions=True)
|
||||||
sales_invoice.submit()
|
sales_invoice.submit()
|
||||||
frappe.msgprint(_('Sales Invoice {0} created as paid'.format(sales_invoice.name)), alert=True)
|
frappe.msgprint(_('Sales Invoice {0} created'.format(sales_invoice.name)), alert=True)
|
||||||
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'invoiced', 1)
|
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'invoiced', 1)
|
||||||
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'ref_sales_invoice', sales_invoice.name)
|
frappe.db.set_value('Patient Appointment', appointment_doc.name, 'ref_sales_invoice', sales_invoice.name)
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ from frappe.utils.make_random import get_random
|
|||||||
class TestPatientAppointment(unittest.TestCase):
|
class TestPatientAppointment(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
frappe.db.sql("""delete from `tabPatient Appointment`""")
|
frappe.db.sql("""delete from `tabPatient Appointment`""")
|
||||||
frappe.db.sql("""delete from `tabFee Validity""")
|
frappe.db.sql("""delete from `tabFee Validity`""")
|
||||||
|
frappe.db.sql("""delete from `tabPatient Encounter`""")
|
||||||
|
|
||||||
def test_status(self):
|
def test_status(self):
|
||||||
patient, medical_department, practitioner = create_healthcare_docs()
|
patient, medical_department, practitioner = create_healthcare_docs()
|
||||||
@@ -25,11 +26,16 @@ class TestPatientAppointment(unittest.TestCase):
|
|||||||
|
|
||||||
def test_start_encounter(self):
|
def test_start_encounter(self):
|
||||||
patient, medical_department, practitioner = create_healthcare_docs()
|
patient, medical_department, practitioner = create_healthcare_docs()
|
||||||
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 3))
|
frappe.db.set_value('Healthcare Settings', None, 'automate_appointment_invoicing', 1)
|
||||||
encounter = create_encounter(appointment)
|
appointment = create_appointment(patient, practitioner, add_days(nowdate(), 4), invoice = 1)
|
||||||
self.assertEquals(frappe.db.get_value('Patient Encounter', encounter.name, 'company'), appointment.company)
|
self.assertEqual(frappe.db.get_value('Patient Appointment', appointment.name, 'invoiced'), 1)
|
||||||
self.assertEquals(frappe.db.get_value('Patient Encounter', encounter.name, 'practitioner'), appointment.practitioner)
|
encounter = make_encounter(appointment.name)
|
||||||
self.assertEquals(frappe.db.get_value('Patient Encounter', encounter.name, 'patient'), appointment.patient)
|
self.assertTrue(encounter)
|
||||||
|
self.assertEqual(encounter.company, appointment.company)
|
||||||
|
self.assertEqual(encounter.practitioner, appointment.practitioner)
|
||||||
|
self.assertEqual(encounter.patient, appointment.patient)
|
||||||
|
# invoiced flag mapped from appointment
|
||||||
|
self.assertEqual(encounter.invoiced, frappe.db.get_value('Patient Appointment', appointment.name, 'invoiced'))
|
||||||
|
|
||||||
def test_invoicing(self):
|
def test_invoicing(self):
|
||||||
patient, medical_department, practitioner = create_healthcare_docs()
|
patient, medical_department, practitioner = create_healthcare_docs()
|
||||||
@@ -104,7 +110,13 @@ def create_patient():
|
|||||||
|
|
||||||
def create_encounter(appointment):
|
def create_encounter(appointment):
|
||||||
if appointment:
|
if appointment:
|
||||||
encounter = make_encounter(appointment.name)
|
encounter = frappe.new_doc('Patient Encounter')
|
||||||
|
encounter.appointment = appointment.name
|
||||||
|
encounter.patient = appointment.patient
|
||||||
|
encounter.practitioner = appointment.practitioner
|
||||||
|
encounter.encounter_date = appointment.appointment_date
|
||||||
|
encounter.encounter_time = appointment.appointment_time
|
||||||
|
encounter.company = appointment.company
|
||||||
encounter.save()
|
encounter.save()
|
||||||
encounter.submit()
|
encounter.submit()
|
||||||
return encounter
|
return encounter
|
||||||
|
|||||||
Reference in New Issue
Block a user