Added the functional Estimates page showing the list of estimates in the system.
This commit is contained in:
parent
888b135fe0
commit
a1e9de489d
5 changed files with 252 additions and 2 deletions
|
|
@ -1,10 +1,52 @@
|
|||
import frappe, json
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_response, get_count_or_filters
|
||||
from custom_ui.db_utils import process_query_conditions, build_datatable_dict, get_count_or_filters, build_success_response
|
||||
|
||||
# ===============================================================================
|
||||
# ESTIMATES & INVOICES API METHODS
|
||||
# ===============================================================================
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_estimate_table_data(filters={}, sortings=[], page=1, page_size=10):
|
||||
"""Get paginated estimate table data with filtering and sorting support."""
|
||||
print("DEBUG: Raw estimate options received:", filters, sortings, page, page_size)
|
||||
|
||||
processed_filters, processed_sortings, is_or, page, page_size = process_query_conditions(filters, sortings, page, page_size)
|
||||
|
||||
if is_or:
|
||||
count = frappe.db.sql(*get_count_or_filters("Quotation", processed_filters))[0][0]
|
||||
else:
|
||||
count = frappe.db.count("Quotation", filters=processed_filters)
|
||||
|
||||
print(f"DEBUG: Number of estimates returned: {count}")
|
||||
|
||||
estimates = frappe.db.get_all(
|
||||
"Quotation",
|
||||
fields=["*"],
|
||||
filters=processed_filters if not is_or else None,
|
||||
or_filters=processed_filters if is_or else None,
|
||||
limit=page_size,
|
||||
start=(page - 1) * page_size,
|
||||
order_by=processed_sortings
|
||||
)
|
||||
|
||||
tableRows = []
|
||||
for estimate in estimates:
|
||||
tableRow = {}
|
||||
tableRow["id"] = estimate["name"]
|
||||
tableRow["name"] = estimate["name"]
|
||||
tableRow["quotation_to"] = estimate.get("quotation_to", "")
|
||||
tableRow["customer"] = estimate.get("party_name", "")
|
||||
tableRow["status"] = estimate.get("custom_current_status", "")
|
||||
tableRow["date"] = estimate.get("transaction_date", "")
|
||||
tableRow["order_type"] = estimate.get("order_type", "")
|
||||
tableRow["items"] = estimate.get("items", "")
|
||||
tableRows.append(tableRow)
|
||||
|
||||
table_data_dict = build_datatable_dict(data=tableRows, count=count, page=page, page_size=page_size)
|
||||
return build_success_response(table_data_dict)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def upsert_estimate(data):
|
||||
"""Create or update an estimate."""
|
||||
|
|
@ -16,4 +58,4 @@ def upsert_estimate(data):
|
|||
def upsert_invoice(data):
|
||||
"""Create or update an invoice."""
|
||||
# TODO: Implement invoice creation/update logic
|
||||
pass
|
||||
pass
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue