From 37bd0f60a32a37481090abe640e18584e086cd82 Mon Sep 17 00:00:00 2001 From: rocketdebris Date: Sat, 24 Jan 2026 17:06:17 -0500 Subject: [PATCH] Added invoice dial API calls and a call to create an invoice from a sales order from a Job. --- custom_ui/api/db/invoices.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/custom_ui/api/db/invoices.py b/custom_ui/api/db/invoices.py index 4b7c3ef..b024808 100644 --- a/custom_ui/api/db/invoices.py +++ b/custom_ui/api/db/invoices.py @@ -1,11 +1,36 @@ import frappe, json from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response, build_error_response +from erpnext.selling.doctype.sales_order.sales_order import make_sales_invoice # =============================================================================== # INVOICES API METHODS # =============================================================================== +@frappe.whitelist() +def create_invoice_for_job(job_name): + """Create the invoice from a sales order of a job.""" + try: + project = frappe.get_doc("Project", job_name) + sales_order = project.sales_order + invoice = make_sales_invoice(sales_order) + invoice.save() + return build_success_response(invoice.as_dict()) + except Exception as e: + return build_error_response(str(e), 500) + + +@frappe.whitelist() +def get_invoices_late_count(): + """Return Due, 30-day late, 90-day late, and Lien-worthy late accounts.""" + try: + dummy_result = [10, 4, 5, 1] + print("DEBUG: DUMMY RESULT:", dummy_result) + return build_success_response(dummy_result) + except Exception as e: + return build_error_response(str(e), 500) + + @frappe.whitelist() def get_invoice_table_data(filters={}, sortings=[], page=1, page_size=10): """Get paginated invoice table data with filtering and sorting support.""" @@ -18,7 +43,7 @@ def get_invoice_table_data(filters={}, sortings=[], page=1, page_size=10): else: count = frappe.db.count("Sales Invoice", filters=processed_filters) - print(f"DEBUG: Number of invoice returned: {count}") + print(f"DEBUG: Number of invoices returned: {count}") invoices = frappe.db.get_all( "Sales Invoice",