Esempio n. 1
0
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')
    enable_free_follow_ups = frappe.db.get_single_value(
        'Healthcare Settings', 'enable_free_follow_ups')
    if enable_free_follow_ups:
        fee_validity = check_fee_validity(appointment_doc)
        if fee_validity and fee_validity.status == 'Completed':
            fee_validity = None
        elif not fee_validity:
            if frappe.db.exists('Fee Validity Reference',
                                {'appointment': appointment_doc.name}):
                return
            if check_is_new_patient(appointment_doc.patient,
                                    appointment_doc.name):
                return
    else:
        fee_validity = None

    if automate_invoicing and not appointment_invoiced and not fee_validity:
        sales_invoice = frappe.new_doc('Sales Invoice')
        sales_invoice.patient = appointment_doc.patient
        sales_invoice.customer = frappe.get_value('Patient',
                                                  appointment_doc.patient,
                                                  'customer')
        sales_invoice.appointment = appointment_doc.name
        sales_invoice.due_date = getdate()
        sales_invoice.company = appointment_doc.company
        sales_invoice.debit_to = get_receivable_account(
            appointment_doc.company)

        item = sales_invoice.append('items', {})
        item = get_appointment_item(appointment_doc, item)

        # Add payments if payment details are supplied else proceed to create invoice as Unpaid
        if appointment_doc.mode_of_payment and 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.flags.ignore_mandatory = True
        sales_invoice.save(ignore_permissions=True)
        sales_invoice.submit()
        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,
                            'ref_sales_invoice', sales_invoice.name)
Esempio n. 2
0
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')
	enable_free_follow_ups = frappe.db.get_single_value('Healthcare Settings', 'enable_free_follow_ups')
	if enable_free_follow_ups:
		fee_validity = check_fee_validity(appointment_doc)
		if fee_validity and fee_validity.status == 'Completed':
			fee_validity = None
		elif not fee_validity:
			if frappe.db.exists('Fee Validity Reference', {'appointment': appointment_doc.name}):
				return
			if check_is_new_patient(appointment_doc.patient, appointment_doc.name):
				return
	else:
		fee_validity = None

	if automate_invoicing and not appointment_invoiced and not fee_validity:
		create_sales_invoice(appointment_doc)
Esempio n. 3
0
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")
    enable_free_follow_ups = frappe.db.get_single_value(
        "Healthcare Settings", "enable_free_follow_ups")
    if enable_free_follow_ups:
        fee_validity = check_fee_validity(appointment_doc)
        if fee_validity and fee_validity.status == "Completed":
            fee_validity = None
        elif not fee_validity:
            if frappe.db.exists("Fee Validity Reference",
                                {"appointment": appointment_doc.name}):
                return
    else:
        fee_validity = None

    if automate_invoicing and not appointment_invoiced and not fee_validity:
        create_sales_invoice(appointment_doc)