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.

- biome changes

Gaurav Bhattea8596e2aa20
diff --git a/.gitignore b/.gitignore
index ccbc8074a9..54b3bb9633 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,5 +38,12 @@ packages/database/supabase/seed.sql
.react-router
-packages/cad-rust
-packages/cad-engine
+# Rust
+**/target/
+**/*.rs.bk
+**/pkg/
+**/pkg/
+
+# C++ (cad-engine)
+**/build/
+!**/build/.gitkeep
diff --git a/apps/erp/app/modules/items/ui/Item/SupplierPartForm.tsx b/apps/erp/app/modules/items/ui/Item/SupplierPartForm.tsx
index f82c018c18..d77d79faa6 100644
--- a/apps/erp/app/modules/items/ui/Item/SupplierPartForm.tsx
+++ b/apps/erp/app/modules/items/ui/Item/SupplierPartForm.tsx
@@ -136,7 +136,7 @@ const SupplierPartForm = ({
currency: baseCurrency
}}
/>
- {/* Show last purchase info if available (read-only) */}
+ {/* last purchase info (read-only) */}
{initialValues.lastPurchaseDate && (
<div className="text-sm text-muted-foreground bg-muted/50 rounded-md p-3 space-y-1">
<div className="font-medium text-foreground">
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
index 903cf383c3..035a132eec 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteBillOfMaterial.tsx
@@ -687,8 +687,6 @@ function MaterialForm({
});
};
- // Lookup the best (lowest) price for a Buy item at a given quantity
- // from supplierPartPrice across all vendors (SAP behavior)
const lookupBuyPrice = useCallback(
async (itemId: string, qty: number, fallbackCost: number) => {
if (!carbon) return fallbackCost;
@@ -702,8 +700,6 @@ function MaterialForm({
const supplierPartIds = supplierParts.data.map((sp) => sp.id);
- // Find the lowest price across all vendors for applicable qty tiers
- // (SAP behavior: lowest valid PIR price wins)
const priceBreak = await carbon
.from("supplierPartPrice")
.select("unitPrice")
@@ -717,7 +713,6 @@ function MaterialForm({
return priceBreak.data.unitPrice;
}
- // Fall back to supplierPart.unitPrice (lowest across vendors)
const lowestSupplierPrice = supplierParts.data
.filter((sp) => sp.unitPrice != null)
.sort((a, b) => (a.unitPrice ?? 0) - (b.unitPrice ?? 0))[0];
@@ -778,7 +773,6 @@ function MaterialForm({
}
};
- // Re-lookup price when quantity changes for Buy parts
const onQuantityChange = useCallback(
async (newQty: number) => {
setItemData((d) => ({ ...d, quantity: newQty }));
diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
index 8e427c5f06..0b12d98807 100644
--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteMaterialForm.tsx
@@ -86,8 +86,6 @@ const QuoteMaterialForm = ({
});
};
- // Lookup the best (lowest) price for a Buy item at a given quantity
- // from supplierPartPrice across all vendors (SAP behavior)
const lookupBuyPrice = useCallback(
async (itemId: string, qty: number, fallbackCost: number) => {
if (!carbon) return fallbackCost;
@@ -101,8 +99,6 @@ const QuoteMaterialForm = ({
const supplierPartIds = supplierParts.data.map((sp) => sp.id);
- // Find the lowest price across all vendors for applicable qty tiers
- // (SAP behavior: lowest valid PIR price wins)
const priceBreak = await carbon
.from("supplierPartPrice")
.select("unitPrice")
@@ -116,7 +112,6 @@ const QuoteMaterialForm = ({
return priceBreak.data.unitPrice;
}
- // Fall back to supplierPart.unitPrice (lowest across vendors)
const lowestSupplierPrice = supplierParts.data
.filter((sp) => sp.unitPrice != null)
.sort((a, b) => (a.unitPrice ?? 0) - (b.unitPrice ?? 0))[0];
@@ -166,7 +161,6 @@ const QuoteMaterialForm = ({
}));
};
- // Re-lookup price when quantity changes for Buy parts
const onQuantityChange = useCallback(
async (newQty: number) => {
setItemData((d) => ({ ...d, quantity: newQty }));
diff --git a/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsx b/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsx
index 4d00899e95..5dc26ff22f 100644
--- a/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsx
+++ b/apps/erp/app/routes/x+/supplier-quote+/$id.finalize.tsx
@@ -128,8 +128,6 @@ export async function action(args: ActionFunctionArgs) {
);
}
- // Copy price breaks from supplierQuoteLinePrice → supplierPartPrice
- // This makes prices available for customer quote costing immediately
const supplierId = quote.data.supplierId;
if (!supplierId) throw new Error("Supplier quote has no supplier");
@@ -141,7 +139,6 @@ export async function action(args: ActionFunctionArgs) {
);
if (linePrices.length === 0) continue;
- // Find or create the supplierPart record for this item+supplier
const existingPart = await client
.from("supplierPart")
.select("id")
@@ -155,7 +152,6 @@ export async function action(args: ActionFunctionArgs) {
if (existingPart.data?.id) {
supplierPartId = existingPart.data.id;
} else {
- // Create a new supplierPart record
const newPart = await client
.from("supplierPart")
.insert({
@@ -180,15 +176,11 @@ export async function action(args: ActionFunctionArgs) {
if (!supplierPartId) continue;
- // Upsert price breaks into supplierPartPrice
const conversionFactor = line.conversionFactor ?? 1;
for (const price of linePrices) {
if (!price.supplierUnitPrice || price.supplierUnitPrice === 0) continue;
- // Use the pre-computed unitPrice (= supplierUnitPrice / exchangeRate)
- // which is already in company currency but still in purchase units.
- // Divide by conversionFactor to get inventory unit price.
const unitPriceInInventoryUnit =
(price.unitPrice ?? 0) / conversionFactor;
@@ -216,8 +208,6 @@ export async function action(args: ActionFunctionArgs) {
}
}
- // Update supplierPart.unitPrice with the best (lowest) unit price
- // across all tiers — gives purchasing a quick "best available" reference
const bestPrice = linePrices
.filter((p) => p.unitPrice != null && p.unitPrice !== 0)
.sort(
diff --git a/packages/database/supabase/functions/convert/index.ts b/packages/database/supabase/functions/convert/index.ts
index f702924949..6e993a9f7b 100644
--- a/packages/database/supabase/functions/convert/index.ts
+++ b/packages/database/supabase/functions/convert/index.ts
@@ -1503,16 +1503,11 @@ serve(async (req: Request) => {
.forEach((line) => {
const key = `${line.itemId}-${quote.data.supplierId}`;
const selectedLine = selectedLines![line.id!];
- // Calculate unit price in inventory unit (company currency)
- // exchangeRate = supplier currency per 1 company currency (e.g., 130 JPY/USD)
- // So: company price = supplierUnitPrice / exchangeRate
- // Then divide by conversionFactor to get inventory unit price
const exchangeRate = quote.data.exchangeRate ?? 1;
const unitPriceInInventoryUnit =
(selectedLine.supplierUnitPrice /
(exchangeRate === 0 ? 1 : exchangeRate)) /
(line.conversionFactor ?? 1);
- // Calculate quantity in inventory units
const quantityInInventoryUnits =
selectedLine.quantity * (line.conversionFactor ?? 1);
@@ -1524,7 +1519,6 @@ serve(async (req: Request) => {
conversionFactor: line.conversionFactor,
itemId: line.itemId!,
createdBy: userId,
- // New pricing fields
unitPrice: unitPriceInInventoryUnit,
lastPurchaseDate: new Date().toISOString(),
lastPOQuantity: quantityInInventoryUnits,
@@ -1545,7 +1539,6 @@ serve(async (req: Request) => {
.columns(["itemId", "supplierId", "companyId"])
.doUpdateSet((eb) => ({
supplierPartId: eb.ref("excluded.supplierPartId"),
- // Update pricing fields on conflict
unitPrice: eb.ref("excluded.unitPrice"),
lastPurchaseDate: eb.ref("excluded.lastPurchaseDate"),
lastPOQuantity: eb.ref("excluded.lastPOQuantity"),
@@ -1554,8 +1547,6 @@ serve(async (req: Request) => {
)
.execute();
- // Also upsert into supplierPartPrice with sourceType='PurchaseOrder'
- // This confirms the price tier for the specific quantity ordered
const supplierParts = await trx
.selectFrom("supplierPart")
.select(["id", "itemId"])
@@ -1585,8 +1576,6 @@ serve(async (req: Request) => {
const selectedLine = selectedLines![line.id!];
const exchangeRate = quote.data.exchangeRate ?? 1;
const conversionFactor = line.conversionFactor ?? 1;
- // exchangeRate = supplier currency per 1 company currency
- // Divide to convert to company currency, then divide by conversionFactor
const unitPriceInInventoryUnit =
(selectedLine.supplierUnitPrice /
(exchangeRate === 0 ? 1 : exchangeRate)) /
@@ -1621,8 +1610,6 @@ serve(async (req: Request) => {
.execute();
}
- // Update each supplierPart with the best (lowest) price and its
- // corresponding MOQ across all tiers (quotes + POs + manual)
for (const [, spId] of supplierPartIdByItemId) {
const bestTier = await trx
.selectFrom("supplierPartPrice")
diff --git a/packages/documents/src/pdf/PackingSlipPDF.tsx b/packages/documents/src/pdf/PackingSlipPDF.tsx
index 419993391a..51b830f2ae 100644
--- a/packages/documents/src/pdf/PackingSlipPDF.tsx
+++ b/packages/documents/src/pdf/PackingSlipPDF.tsx
@@ -202,9 +202,9 @@ const PackingSlipPDF = ({
{/* Rows */}
{shipmentLines
- .filter((line) => line.shippedQuantity > 0)
+ .filter((line) => line?.shippedQuantity ?? 0 > 0)
.map((line) => {
- const barcodeDataUrl = generateBarcode(line.itemReadableId);
+ const barcodeDataUrl = generateBarcode(line?.itemReadableId || "");
const trackedEntitiesForLine = trackedEntities.filter(
(entity) =>
(entity.attributes as TrackedEntityAttributes)?.[