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
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.
import type { SalesOrderData } from "./types";
/**
* Merge-field variable map for a Sales Order. Tokens mirror
* `SALES_ORDER_MERGE_FIELDS` in template/merge.ts.
*/
export function buildSalesOrderVars(
data: Pick<
SalesOrderData,
"salesOrder" | "salesOrderLocations" | "company" | "currencyCode"
>
): Record<string, string> {
const so = data.salesOrder;
const loc = data.salesOrderLocations;
const str = (v: unknown): string => (v == null ? "" : String(v));
return {
"order.number": str(so?.salesOrderId),
"order.date": str(so?.orderDate),
"order.customerReference": str(so?.customerReference),
"order.currency": str(data.currencyCode),
"customer.name": str(loc?.customerName),
"customer.addressLine1": str(loc?.customerAddressLine1),
"customer.city": str(loc?.customerCity),
"customer.country": str(loc?.customerCountryName),
"company.name": str(data.company?.name),
"company.city": str(data.company?.city),
"company.country": str(data.company?.countryCode),
"company.taxId": str(data.company?.taxId),
"company.eori": str(data.company?.eori),
"company.vatNumber": str(data.company?.vatNumber),
"company.registrationNumber": str(data.company?.registrationNumber)
};
}