Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix(sales): exclude voided invoices and count partial payments on sales order (#1615)
Brad Barbin404dd0bfe4a1
diff --git a/apps/erp/app/modules/sales/sales.service.ts b/apps/erp/app/modules/sales/sales.service.tsindex dc38a0756b..b22b32079e 100644--- a/apps/erp/app/modules/sales/sales.service.ts+++ b/apps/erp/app/modules/sales/sales.service.ts@@ -1776,7 +1776,7 @@ export async function getSalesOrderInvoicesByIds() {return client.from("salesInvoices")- .select("id, invoiceTotal, status, currencyCode")+ .select("id, invoiceTotal, balance, status, currencyCode").in("id", invoiceIds);}diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.jsonindex 71478185c8..fd06411ca7 100644--- a/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-manifest.digest.json@@ -1283,7 +1283,7 @@{"name":"sales_getSalesOrderCustomerDetails","classification":"READ","paramCount":1,"schema":"d160a49d6787","response":"141326b70f84","injectAuth":"companyId","permission":"sales:view","paginates":false},{"name":"sales_getSalesOrderCustomers","classification":"READ","paramCount":0,"schema":"efddc7bd8bbc","response":"fc7a0345fc53","injectAuth":"companyId","permission":"sales:view","paginates":false},{"name":"sales_getSalesOrderInvoiceLines","classification":"READ","paramCount":1,"schema":"d160a49d6787","response":"1ff852ae9154","injectAuth":"companyId","permission":"sales:view","paginates":false},- {"name":"sales_getSalesOrderInvoicesByIds","classification":"READ","paramCount":1,"schema":"d51ae9969843","response":"b06c9fe383e6","injectAuth":"companyId","permission":"sales:view","paginates":false},+ {"name":"sales_getSalesOrderInvoicesByIds","classification":"READ","paramCount":1,"schema":"d51ae9969843","response":"7b2008a52299","injectAuth":"companyId","permission":"sales:view","paginates":false},{"name":"sales_getSalesOrderLine","classification":"READ","paramCount":1,"schema":"58e3c9762923","response":"680c6abfc2c8","injectAuth":"companyId","permission":"sales:view","paginates":false},{"name":"sales_getSalesOrderLines","classification":"READ","paramCount":1,"schema":"d160a49d6787","response":"12480eaf2ca4","injectAuth":"companyId","permission":"sales:view","paginates":false},{"name":"sales_getSalesOrderLinesByItemId","classification":"READ","paramCount":1,"schema":"623ca47a6c74","response":"12480eaf2ca4","injectAuth":"companyId","permission":"sales:view","paginates":false},diff --git a/apps/erp/app/routes/x+/sales-order+/$orderId.tsx b/apps/erp/app/routes/x+/sales-order+/$orderId.tsxindex a8ff587169..184a87d4f0 100644--- a/apps/erp/app/routes/x+/sales-order+/$orderId.tsx+++ b/apps/erp/app/routes/x+/sales-order+/$orderId.tsx@@ -133,6 +133,12 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const orderCurrency = salesOrder.data?.currencyCode;for (const invoice of invoices.data ?? []) {+ // A voided invoice was never billed — it must not inflate the invoiced+ // total, nor contribute any payments to the paid total.+ if (invoice.status === "Voided") {+ continue;+ }+const invoiceTotal = invoice.invoiceTotal ?? 0;const invoiceCurrency = invoice.currencyCode;@@ -147,9 +153,13 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}invoicedAmount += invoiceTotal;- if (invoice.status === "Paid") {- paidAmount += invoiceTotal;- }++ // Paid = the settled portion in document currency (invoiceTotal - balance+ // from the salesInvoices view, which only counts posted payments/memos).+ // A fully-Paid invoice reports balance 0, a partially-paid one reports its+ // outstanding remainder — so partial payments are counted, not ignored.+ const balance = invoice.balance ?? 0;+ paidAmount += invoiceTotal - balance;}}