Skip to content

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.

fix(purchasing): compare supplier quotes in the base currency

sidgaikwadbca9011d5d40
diff --git a/apps/erp/app/modules/purchasing/purchasing.models.ts b/apps/erp/app/modules/purchasing/purchasing.models.ts
index 11cea52704..00e22fe491 100644
--- a/apps/erp/app/modules/purchasing/purchasing.models.ts
+++ b/apps/erp/app/modules/purchasing/purchasing.models.ts
@@ -322,6 +322,11 @@ export const selectedLineSchema = z.object({
supplierShippingCost: z.number(),
supplierUnitPrice: z.number(),
supplierTaxAmount: z.number(),
+ // The base-currency twin of supplierTaxAmount, matching the unitPrice /
+ // supplierUnitPrice and shippingCost / supplierShippingCost pairs above.
+ // Optional so the supplier portal and the to-order drawer keep working
+ // without it; only cross-supplier totals need a comparable tax figure.
+ taxAmount: z.number().optional().default(0),
// Same 0..1 fraction contract as purchaseOrderLineValidator — the two feed the
// same columns, so an unbounded rate here would bypass the form's bound.
taxPercent: z.number().min(0).max(1).optional().default(0),
diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx
index cb06bb7bfa..50db3c5ffc 100644
--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx
+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteCompareDrawer.tsx
@@ -160,14 +160,17 @@ const SupplierQuoteCompareDrawer = ({
setSelectedLines({});
};
- // Calculate order total from selected line items
+ // Calculate order total from selected line items. Base currency: the lines
+ // can come from suppliers quoting in different currencies, so the supplier*
+ // columns are not addable — unitPrice/shippingCost/taxAmount are each the
+ // supplier figure over the quote's exchangeRate.
const orderTotal = useMemo(() => {
let total = 0;
for (const pricing of Object.values(selectedLines)) {
total +=
- pricing.supplierUnitPrice * pricing.quantity +
- pricing.supplierShippingCost +
- pricing.supplierTaxAmount;
+ pricing.unitPrice * pricing.quantity +
+ pricing.shippingCost +
+ pricing.taxAmount;
}
return total;
}, [selectedLines]);
@@ -370,10 +373,14 @@ const ComparisonView = ({
if (matchingPrice) {
hasMatchingTier = true;
+ // Base currency — this total is compared against every other
+ // supplier's to pick `bestTotal`, and each supplier may quote in its
+ // own currency. Comparing raw supplier* amounts ranks by exchange
+ // rate rather than by price.
total +=
- (matchingPrice.supplierUnitPrice ?? 0) * matchingPrice.quantity +
- (matchingPrice.supplierShippingCost ?? 0) +
- (matchingPrice.supplierTaxAmount ?? 0);
+ (matchingPrice.unitPrice ?? 0) * matchingPrice.quantity +
+ (matchingPrice.shippingCost ?? 0) +
+ (matchingPrice.taxAmount ?? 0);
if (
matchingPrice.leadTime !== null &&
@@ -554,7 +561,9 @@ const ComparisonView = ({
)
: linePrices[0];
- return matchingPrice?.supplierUnitPrice ?? null;
+ // Base currency: these are min'd across suppliers below,
+ // and each may quote in its own.
+ return matchingPrice?.unitPrice ?? null;
});
const validPrices = itemPrices.filter(
@@ -609,7 +618,7 @@ const ComparisonView = ({
}
const isBest =
- linePrice.supplierUnitPrice === bestPrice &&
+ linePrice.unitPrice === bestPrice &&
bestPrice !== null;
return (
@@ -625,9 +634,7 @@ const ComparisonView = ({
isBest && "text-green-600"
)}
>
- {formatter.format(
- linePrice.supplierUnitPrice ?? 0
- )}
+ {formatter.format(linePrice.unitPrice ?? 0)}
/ea
</span>
</HStack>
@@ -761,6 +768,7 @@ const LinePricingOptions = ({
shippingCost: selectedOption.shippingCost ?? 0,
leadTime: selectedOption.leadTime ?? 0,
supplierTaxAmount: selectedOption.supplierTaxAmount ?? 0,
+ taxAmount: selectedOption.taxAmount ?? 0,
taxPercent: selectedOption.taxPercent ?? 0
}
}));
@@ -815,18 +823,18 @@ const LinePricingOptions = ({
</label>
</Td>
<Td>{option.quantity}</Td>
- <Td>{formatter.format(option.supplierUnitPrice ?? 0)}</Td>
- <Td>{formatter.format(option.supplierShippingCost ?? 0)}</Td>
+ <Td>{formatter.format(option.unitPrice ?? 0)}</Td>
+ <Td>{formatter.format(option.shippingCost ?? 0)}</Td>
<Td>
{option.leadTime ?? 0}{" "}
{pluralize(option.leadTime ?? 0, "day")}
</Td>
- <Td>{formatter.format(option.supplierTaxAmount ?? 0)}</Td>
+ <Td>{formatter.format(option.taxAmount ?? 0)}</Td>
<Td>
{formatter.format(
- (option.supplierUnitPrice ?? 0) * option.quantity +
- (option.supplierShippingCost ?? 0) +
- (option.supplierTaxAmount ?? 0)
+ (option.unitPrice ?? 0) * option.quantity +
+ (option.shippingCost ?? 0) +
+ (option.taxAmount ?? 0)
)}
</Td>
</Tr>
diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx
index 2ce43ad372..3702f7e20a 100644
--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx
+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteToOrderDrawer.tsx
@@ -278,6 +278,7 @@ const LinePricingOptions = ({
supplierShippingCost: 0,
shippingCost: 0,
supplierTaxAmount: 0,
+ taxAmount: 0,
taxPercent: 0
});
@@ -294,6 +295,7 @@ const LinePricingOptions = ({
shippingCost: overridePricing.shippingCost,
leadTime: overridePricing.leadTime,
supplierTaxAmount: overridePricing.supplierTaxAmount,
+ taxAmount: overridePricing.taxAmount,
// Override collects amounts only — seed the rate from the canonical
// denominator (unit price x quantity + shipping).
taxPercent: deriveRate(
@@ -337,6 +339,7 @@ const LinePricingOptions = ({
shippingCost: selectedOption.shippingCost ?? 0,
leadTime: selectedOption.leadTime,
supplierTaxAmount: selectedOption.supplierTaxAmount ?? 0,
+ taxAmount: selectedOption.taxAmount ?? 0,
taxPercent: selectedOption.taxPercent ?? 0
}
}));
@@ -536,7 +539,10 @@ const LinePricingOptions = ({
onChange={(taxAmount) =>
setOverridePricing((v) => ({
...v,
- supplierTaxAmount: taxAmount
+ supplierTaxAmount: taxAmount,
+ // Same conversion the unit price and shipping overrides
+ // above use, so the three stay consistent with each other.
+ taxAmount: taxAmount * quoteExchangeRate
}))
}
>