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(items): show the stored conversion factor when units of measure match (#1534)

Siddharth Gaikwadebcade173cf5
diff --git a/apps/erp/app/components/Form/ConversionFactor.tsx b/apps/erp/app/components/Form/ConversionFactor.tsx
index 1c9d1ecd76..8abc18ace6 100644
--- a/apps/erp/app/components/Form/ConversionFactor.tsx
+++ b/apps/erp/app/components/Form/ConversionFactor.tsx
@@ -171,12 +171,18 @@ const ConversionFactor = forwardRef<
t
]);
+ // Equal codes force the factor to 1 only when a unit of measure CHANGES
+ // into equality — never on mount, where the codes can already be equal
+ // and the stored factor must be displayed (and submitted) as stored.
+ const wasEqual = useRef(inventoryCode === purchasingCode);
useEffect(() => {
- if (inventoryCode === purchasingCode) {
+ const isEqual = inventoryCode === purchasingCode;
+ if (isEqual && !wasEqual.current) {
setConversionFactor(1);
setControlValue(1);
initialValue.current = 1;
}
+ wasEqual.current = isEqual;
}, [inventoryCode, purchasingCode, setControlValue]);
const onPurchaseUnitChange = (v: number) => {