Added invoice dial API calls and a call to create an invoice from a sales order from a Job.

This commit is contained in:
rocketdebris 2026-01-24 17:06:17 -05:00
parent 81f3489a24
commit 37bd0f60a3

View file

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