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
resolve UX audit bugs across production, sales, purchasing, and items
aashu3112e9bd634c
diff --git a/apps/erp/app/modules/items/items.models.ts b/apps/erp/app/modules/items/items.models.tsindex 8fa9f00e97..33882e5cf8 100644--- a/apps/erp/app/modules/items/items.models.ts+++ b/apps/erp/app/modules/items/items.models.ts@@ -345,44 +345,55 @@ export const materialValidatorWithGeneratedIds = z.object({sizes: z.array(z.string()).optional()});-export const methodMaterialValidator = z.object({- id: z.string().min(1, { message: "Material ID is required" }),- makeMethodId: z.string().min(1, { message: "Make method is required" }),- order: zfd.numeric(z.number().min(0)),- itemType: z.enum(methodItemType, {- errorMap: (issue, ctx) => ({- message: "Item type is required"- })- }),- kit: zfd.text(z.string().optional()).transform((value) => value === "true"),- methodType: z.enum(methodType, {- errorMap: (issue, ctx) => ({- message: "Method type is required"- })- }),- sourcingType: z.enum(sourcingType, {- errorMap: (issue, ctx) => ({- message: "Sourcing type is required"- })- }),- itemId: z.string().optional(),- methodOperationId: zfd.text(z.string().optional()),- // description: z.string().min(1, { message: "Description is required" }),- quantity: zfd.numeric(z.number().min(0)),- unitOfMeasureCode: z- .string()- .min(1, { message: "Unit of Measure is required" }),- storageUnitIds: z.string().transform((val) => {- try {- return JSON.parse(val) as Record<string, string>;- } catch {- return {};+export const methodMaterialValidator = z+ .object({+ id: z.string().min(1, { message: "Material ID is required" }),+ makeMethodId: z.string().min(1, { message: "Make method is required" }),+ order: zfd.numeric(z.number().min(0)),+ itemType: z.enum(methodItemType, {+ errorMap: (issue, ctx) => ({+ message: "Item type is required"+ })+ }),+ kit: zfd.text(z.string().optional()).transform((value) => value === "true"),+ methodType: z.enum(methodType, {+ errorMap: (issue, ctx) => ({+ message: "Method type is required"+ })+ }),+ sourcingType: z.enum(sourcingType, {+ errorMap: (issue, ctx) => ({+ message: "Sourcing type is required"+ })+ }),+ itemId: z.string().optional(),+ methodOperationId: zfd.text(z.string().optional()),+ // description: z.string().min(1, { message: "Description is required" }),+ quantity: zfd.numeric(z.number().min(0)),+ unitOfMeasureCode: z+ .string()+ .min(1, { message: "Unit of Measure is required" }),+ storageUnitIds: z.string().transform((val) => {+ try {+ return JSON.parse(val) as Record<string, string>;+ } catch {+ return {};+ }+ }),+ // BOM line-item effectivity: the build-date window this line applies to.+ effectiveFrom: zfd.text(z.string().optional()),+ effectiveTo: zfd.text(z.string().optional())+ })+ .refine(+ (data) =>+ !data.effectiveFrom ||+ !data.effectiveTo ||+ data.effectiveFrom <= data.effectiveTo,+ {+ message: "Effective From must be on or before Effective To",+ path: ["effectiveTo"]}- }),- // BOM line-item effectivity: the build-date window this line applies to.- effectiveFrom: zfd.text(z.string().optional()),- effectiveTo: zfd.text(z.string().optional())-});+ );export const methodOperationValidator = z.object({diff --git a/apps/erp/app/modules/items/items.service.ts b/apps/erp/app/modules/items/items.service.tsindex fb61d9a686..1a575fdb3c 100644--- a/apps/erp/app/modules/items/items.service.ts+++ b/apps/erp/app/modules/items/items.service.ts@@ -246,44 +246,74 @@ export async function deleteItem(client: SupabaseClient<Database>, id: string) {export async function deleteItemPostingGroup(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("itemPostingGroup").delete().eq("id", id);+ return client+ .from("itemPostingGroup")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function deleteMaterialDimension(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("materialDimension").delete().eq("id", id);+ return client+ .from("materialDimension")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function deleteMaterialFinish(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("materialFinish").delete().eq("id", id);+ return client+ .from("materialFinish")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function deleteMaterialForm(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("materialForm").delete().eq("id", id);+ return client+ .from("materialForm")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function deleteMaterialGrade(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("materialGrade").delete().eq("id", id);+ return client+ .from("materialGrade")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function deleteMaterialSubstance(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("materialSubstance").delete().eq("id", id);+ return client+ .from("materialSubstance")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function deleteMethodMaterial(@@ -345,9 +375,14 @@ export async function deleteMethodOperationTool(export async function deleteUnitOfMeasure(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("unitOfMeasure").delete().eq("id", id);+ return client+ .from("unitOfMeasure")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function getConfigurationParameters(@@ -4285,9 +4320,14 @@ export async function upsertMaterialGrade(export async function deleteMaterialType(client: SupabaseClient<Database>,- id: string+ id: string,+ companyId: string) {- return client.from("materialType").delete().eq("id", id);+ return client+ .from("materialType")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);}export async function getMaterialTypes(diff --git a/apps/erp/app/modules/items/ui/ItemPostingGroups/ItemPostingGroupForm.tsx b/apps/erp/app/modules/items/ui/ItemPostingGroups/ItemPostingGroupForm.tsxindex ed8e6a1232..8f944df6ef 100644--- a/apps/erp/app/modules/items/ui/ItemPostingGroups/ItemPostingGroupForm.tsx+++ b/apps/erp/app/modules/items/ui/ItemPostingGroups/ItemPostingGroupForm.tsx@@ -93,7 +93,7 @@ const ItemPostingGroupForm = ({<Hidden name="id" /><Hidden name="type" value={type} /><VStack spacing={4}>- <Input name="name" label={t`Name`} />+ <Input name="name" label={t`Name`} characterLimit={255} /><TextArea name="description" label={t`Description`} /><CustomFormFields table="itemPostingGroup" /></VStack>diff --git a/apps/erp/app/modules/items/ui/MaterialShapes/MaterialShapeForm.tsx b/apps/erp/app/modules/items/ui/MaterialShapes/MaterialShapeForm.tsxindex a310601415..623c86f168 100644--- a/apps/erp/app/modules/items/ui/MaterialShapes/MaterialShapeForm.tsx+++ b/apps/erp/app/modules/items/ui/MaterialShapes/MaterialShapeForm.tsx@@ -98,7 +98,7 @@ const MaterialShapeForm = ({<Hidden name="id" /><Hidden name="type" value={type} /><VStack spacing={4}>- <Input name="name" label={t`Name`} />+ <Input name="name" label={t`Name`} characterLimit={255} /><InputControlledname="code"label={t`Code`}@@ -106,7 +106,8 @@ const MaterialShapeForm = ({onChange={(value) =>setCode(value.toUpperCase().replace(/\s/g, ""))}- helperText={t`Unique, uppercase, without spaces`}+ characterLimit={10}+ helperText={t`Unique, uppercase, without spaces (max 10 characters)`}/><CustomFormFields table="materialForm" /></VStack>diff --git a/apps/erp/app/modules/items/ui/MaterialSubstances/MaterialSubstanceForm.tsx b/apps/erp/app/modules/items/ui/MaterialSubstances/MaterialSubstanceForm.tsxindex 6b6e6bcf55..8677ee345b 100644--- a/apps/erp/app/modules/items/ui/MaterialSubstances/MaterialSubstanceForm.tsx+++ b/apps/erp/app/modules/items/ui/MaterialSubstances/MaterialSubstanceForm.tsx@@ -98,7 +98,7 @@ const MaterialSubstanceForm = ({<Hidden name="id" /><Hidden name="type" value={type} /><VStack spacing={4}>- <Input name="name" label={t`Name`} />+ <Input name="name" label={t`Name`} characterLimit={255} /><InputControlledname="code"label={t`Code`}@@ -106,7 +106,8 @@ const MaterialSubstanceForm = ({onChange={(value) =>setCode(value.toUpperCase().replace(/\s/g, ""))}- helperText={t`Unique, uppercase, without spaces`}+ characterLimit={10}+ helperText={t`Unique, uppercase, without spaces (max 10 characters)`}/><CustomFormFields table="materialSubstance" /></VStack>diff --git a/apps/erp/app/modules/items/ui/MaterialTypes/MaterialTypeForm.tsx b/apps/erp/app/modules/items/ui/MaterialTypes/MaterialTypeForm.tsxindex 855e0a49df..95089ed58d 100644--- a/apps/erp/app/modules/items/ui/MaterialTypes/MaterialTypeForm.tsx+++ b/apps/erp/app/modules/items/ui/MaterialTypes/MaterialTypeForm.tsx@@ -96,7 +96,7 @@ const MaterialTypeForm = ({<VStack spacing={4}><Substance name="materialSubstanceId" label={t`Substance`} /><Shape name="materialFormId" label={t`Shape`} />- <Input name="name" label={t`Name`} />+ <Input name="name" label={t`Name`} characterLimit={255} /><InputControlledname="code"label={t`Code`}@@ -104,7 +104,8 @@ const MaterialTypeForm = ({onChange={(value) =>setCode(value.toUpperCase().replace(/\s/g, ""))}- helperText={t`Unique, uppercase, without spaces`}+ characterLimit={10}+ helperText={t`Unique, uppercase, without spaces (max 10 characters)`}/></VStack></ModalDrawerBody>diff --git a/apps/erp/app/modules/items/ui/UnitOfMeasure/UnitOfMeasureForm.tsx b/apps/erp/app/modules/items/ui/UnitOfMeasure/UnitOfMeasureForm.tsxindex dc55f80213..ef1ab09eb7 100644--- a/apps/erp/app/modules/items/ui/UnitOfMeasure/UnitOfMeasureForm.tsx+++ b/apps/erp/app/modules/items/ui/UnitOfMeasure/UnitOfMeasureForm.tsx@@ -90,7 +90,11 @@ const UnitOfMeasureForm = ({<Hidden name="id" /><Hidden name="type" value={type} /><VStack spacing={4}>- <Input name="name" label={t`Unit of Measure`} />+ <Input+ name="name"+ label={t`Unit of Measure`}+ characterLimit={50}+ /><InputControlledname="code"label={t`Code`}@@ -98,7 +102,8 @@ const UnitOfMeasureForm = ({onChange={(value) =>setCode(value.toUpperCase().replace(/\s/g, ""))}- helperText={t`Unique, uppercase, without spaces`}+ characterLimit={10}+ helperText={t`Unique, uppercase, without spaces (max 10 characters)`}/><CustomFormFields table="unitOfMeasure" /></VStack>diff --git a/apps/erp/app/modules/production/production.models.ts b/apps/erp/app/modules/production/production.models.tsindex ce89d86261..2542bb8a03 100644--- a/apps/erp/app/modules/production/production.models.ts+++ b/apps/erp/app/modules/production/production.models.ts@@ -890,17 +890,22 @@ export const productionOrderValidator = z.object({export type ProductionOrder = z.infer<typeof productionOrderValidator>;-export const productionQuantityValidator = z.object({- id: zfd.text(z.string().optional()),- jobOperationId: z.string().min(1, { message: "Operation is required" }),- type: z.enum(["Rework", "Scrap", "Production"], {- errorMap: () => ({ message: "Quantity type is required" })- }),- scrapReasonId: zfd.text(z.string().optional()),- notes: zfd.text(z.string().optional()),- createdBy: zfd.text(z.string().optional()),- quantity: zfd.numeric(z.number().min(0))-});+export const productionQuantityValidator = z+ .object({+ id: zfd.text(z.string().optional()),+ jobOperationId: z.string().min(1, { message: "Operation is required" }),+ type: z.enum(["Rework", "Scrap", "Production"], {+ errorMap: () => ({ message: "Quantity type is required" })+ }),+ scrapReasonId: zfd.text(z.string().optional()),+ notes: zfd.text(z.string().optional()),+ createdBy: zfd.text(z.string().optional()),+ quantity: zfd.numeric(z.number().min(0))+ })+ .refine((data) => data.type !== "Scrap" || !!data.scrapReasonId, {+ message: "Scrap reason is required",+ path: ["scrapReasonId"]+ });export const scheduleOperationUpdateValidator = z.object({id: z.string().min(1, { message: "ID is required" }),diff --git a/apps/erp/app/modules/production/production.service.ts b/apps/erp/app/modules/production/production.service.tsindex d4e0bd05fb..41769d5c37 100644--- a/apps/erp/app/modules/production/production.service.ts+++ b/apps/erp/app/modules/production/production.service.ts@@ -1,5 +1,6 @@import type { Database, Json } from "@carbon/database";import { fetchAllFromTable } from "@carbon/database";+import type { Kysely, KyselyDatabase } from "@carbon/database/client";import type { JSONContent } from "@carbon/react";import { parseDate } from "@internationalized/date";import type { FileObject, StorageError } from "@supabase/storage-js";@@ -2316,48 +2317,66 @@ export async function updateJobStatus(}export async function updateJobMaterialOrder(- client: SupabaseClient<Database>,+ db: Kysely<KyselyDatabase>,+ companyId: string,updates: {id: string;order: number;updatedBy: string;}[]) {- const updatePromises = updates.map(({ id, order, updatedBy }) =>- client.from("jobMaterial").update({ order, updatedBy }).eq("id", id)- );- return Promise.all(updatePromises);+ return db.transaction().execute(async (trx) => {+ for (const { id, order, updatedBy } of updates) {+ await trx+ .updateTable("jobMaterial")+ .set({ order, updatedBy })+ .where("id", "=", id)+ .where("companyId", "=", companyId)+ .execute();+ }+ });}export async function updateJobOperationOrder(- client: SupabaseClient<Database>,+ db: Kysely<KyselyDatabase>,+ companyId: string,updates: {id: string;order: number;updatedBy: string;}[]) {- const updatePromises = updates.map(({ id, order, updatedBy }) =>- client.from("jobOperation").update({ order, updatedBy }).eq("id", id)- );- return Promise.all(updatePromises);+ return db.transaction().execute(async (trx) => {+ for (const { id, order, updatedBy } of updates) {+ await trx+ .updateTable("jobOperation")+ .set({ order, updatedBy })+ .where("id", "=", id)+ .where("companyId", "=", companyId)+ .execute();+ }+ });}export async function updateJobOperationStepOrder(- client: SupabaseClient<Database>,+ db: Kysely<KyselyDatabase>,+ companyId: string,updates: {id: string;sortOrder: number;updatedBy: string;}[]) {- const updatePromises = updates.map(({ id, sortOrder, updatedBy }) =>- client- .from("jobOperationStep")- .update({ sortOrder, updatedBy })- .eq("id", id)- );- return Promise.all(updatePromises);+ return db.transaction().execute(async (trx) => {+ for (const { id, sortOrder, updatedBy } of updates) {+ await trx+ .updateTable("jobOperationStep")+ .set({ sortOrder, updatedBy })+ .where("id", "=", id)+ .where("companyId", "=", companyId)+ .execute();+ }+ });}export async function updateKanbanJob(diff --git a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsxindex 2a2bb68150..9a63868586 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobBillOfProcess.tsx@@ -421,13 +421,23 @@ const JobBillOfProcess = ({// biome-ignore lint/correctness/noUnusedVariables: suppressed due to migrationconst { carbon, accessToken } = useCarbon();const sortOrderFetcher = useFetcher<{}>();- const deleteOperationFetcher = useFetcher<{ success: boolean }>();+ const deleteOperationFetcher = useFetcher<{+ success: boolean;+ error?: string;+ }>();const permissions = usePermissions();const {id: userId,company: { id: companyId }} = useUser();+ useEffect(() => {+ const result = deleteOperationFetcher.data;+ if (result && !result.success && result.error) {+ toast.error(result.error);+ }+ }, [deleteOperationFetcher.data]);+const [params] = useUrlParams();const selected = params.get("selectedOperation");const [selectedItemId, setSelectedItemId] = useState<string | null>(diff --git a/apps/erp/app/modules/production/ui/Jobs/JobForm.tsx b/apps/erp/app/modules/production/ui/Jobs/JobForm.tsxindex 83126b6712..ac4956f8c8 100644--- a/apps/erp/app/modules/production/ui/Jobs/JobForm.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/JobForm.tsx@@ -105,7 +105,7 @@ const JobForm = ({ initialValues }: JobFormProps) => {scrapPercentage:(initialValues.quantity ?? 0) === 0? 0- : (initialValues.scrapQuantity ?? 0) / initialValues.scrapQuantity,+ : (initialValues.scrapQuantity ?? 0) / initialValues.quantity,uom: initialValues.unitOfMeasureCode ?? "",modelUploadId: initialValues.modelUploadId ?? null});diff --git a/apps/erp/app/modules/production/ui/Jobs/ProductionQuantityForm.tsx b/apps/erp/app/modules/production/ui/Jobs/ProductionQuantityForm.tsxindex 4f1ec67497..bf98115a38 100644--- a/apps/erp/app/modules/production/ui/Jobs/ProductionQuantityForm.tsx+++ b/apps/erp/app/modules/production/ui/Jobs/ProductionQuantityForm.tsx@@ -111,6 +111,7 @@ const ProductionQuantityForm = ({name="scrapReasonId"label={t`Scrap Reason`}termId="production-quantity-scrap-reason"+ isOptional={false}/>)}<TextArea name="notes" label={t`Notes`} />diff --git a/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsx b/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsxindex ccc7c809e1..c3f4b13656 100644--- a/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsx+++ b/apps/erp/app/modules/production/ui/Procedures/ProcedureExplorer.tsx@@ -595,8 +595,8 @@ function DeleteProcedureStep({return (<ConfirmDeleteaction={path.to.deleteProcedureStep(id, attribute.id)}- name={attribute.name ?? "this attribute"}- text={`Are you sure you want to delete the attribute: ${attribute.name}? This cannot be undone.`}+ name={attribute.name ?? "this step"}+ text={`Are you sure you want to delete the step: ${attribute.name}? This cannot be undone.`}onCancel={onCancel}onSubmit={onCancel}/>diff --git a/apps/erp/app/modules/production/ui/ScrapReasons/ScrapReasonsTable.tsx b/apps/erp/app/modules/production/ui/ScrapReasons/ScrapReasonsTable.tsxindex 96478dc84f..f6d9883ff4 100644--- a/apps/erp/app/modules/production/ui/ScrapReasons/ScrapReasonsTable.tsx+++ b/apps/erp/app/modules/production/ui/ScrapReasons/ScrapReasonsTable.tsx@@ -55,7 +55,7 @@ const ScrapReasonsTable = memo(({ data, count }: ScrapReasonsTableProps) => {</MenuItem><MenuItemdestructive- disabled={!permissions.can("delete", "sales")}+ disabled={!permissions.can("delete", "production")}onClick={() => {navigate(`${path.to.deleteScrapReason(row.id)}?${params.toString()}`@@ -77,7 +77,7 @@ const ScrapReasonsTable = memo(({ data, count }: ScrapReasonsTableProps) => {columns={columns}count={count}primaryAction={- permissions.can("create", "sales") && (+ permissions.can("create", "production") && (<Newlabel={t`Scrap Reason`}to={`${path.to.newScrapReason}?${params.toString()}`}diff --git a/apps/erp/app/modules/purchasing/purchasing.service.ts b/apps/erp/app/modules/purchasing/purchasing.service.tsindex 51469b1ae8..912e6d89b3 100644--- a/apps/erp/app/modules/purchasing/purchasing.service.ts+++ b/apps/erp/app/modules/purchasing/purchasing.service.ts@@ -244,11 +244,7 @@ export async function deleteSupplierProcess(client: SupabaseClient<Database>,supplierProcessId: string) {- return client- .from("supplierProcess")- .delete()- .eq("id", supplierProcessId)- .single();+ return client.from("supplierProcess").delete().eq("id", supplierProcessId);}export async function deleteSupplierQuote(diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsxindex fc01fb0641..70e970b85f 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm.tsx@@ -82,6 +82,22 @@ type PurchaseOrderLineFormProps = {onClose?: () => void;};+const getLineSubtotal = (+ unitPrice: number,+ quantity: number,+ shippingCost: number+) => unitPrice * quantity + shippingCost;++const getLineTaxPercent = (+ unitPrice: number,+ quantity: number,+ shippingCost: number,+ taxAmount: number+) => {+ const subtotal = getLineSubtotal(unitPrice, quantity, shippingCost);+ return subtotal > 0 ? taxAmount / subtotal : 0;+};+const PurchaseOrderLineForm = ({initialValues,type,@@ -142,23 +158,21 @@ const PurchaseOrderLineForm = ({supplierShippingCost: initialValues.supplierShippingCost ?? 0,supplierTaxAmount: initialValues.supplierTaxAmount ?? 0,supplierUnitPrice: initialValues.supplierUnitPrice ?? 0,- taxPercent:- (initialValues.supplierUnitPrice ?? 0) *- (initialValues.purchaseQuantity ?? 1) +- (initialValues.supplierShippingCost ?? 0) >- 0- ? (initialValues.supplierTaxAmount ?? 0) /- ((initialValues.supplierUnitPrice ?? 0) *- (initialValues.purchaseQuantity ?? 1) +- (initialValues.supplierShippingCost ?? 0))- : 0+ taxPercent: getLineTaxPercent(+ initialValues.supplierUnitPrice ?? 0,+ initialValues.purchaseQuantity ?? 1,+ initialValues.supplierShippingCost ?? 0,+ initialValues.supplierTaxAmount ?? 0+ )});// update tax amount when quantity or unit price changesuseEffect(() => {- const subtotal =- itemData.supplierUnitPrice * itemData.purchaseQuantity +- itemData.supplierShippingCost;+ const subtotal = getLineSubtotal(+ itemData.supplierUnitPrice,+ itemData.purchaseQuantity,+ itemData.supplierShippingCost+ );if (itemData.taxPercent !== 0) {setItemData((d) => ({...d,@@ -200,22 +214,20 @@ const PurchaseOrderLineForm = ({supplierUnitPrice: initialValues.supplierUnitPrice ?? 0,supplierShippingCost: initialValues.supplierShippingCost ?? 0,supplierTaxAmount: initialValues.supplierTaxAmount ?? 0,- taxPercent:- (initialValues.supplierUnitPrice ?? 0) *- (initialValues.purchaseQuantity ?? 1) +- (initialValues.supplierShippingCost ?? 0) >- 0- ? (initialValues.supplierTaxAmount ?? 0) /- ((initialValues.supplierUnitPrice ?? 0) *- (initialValues.purchaseQuantity ?? 1) +- (initialValues.supplierShippingCost ?? 0))- : 0+ taxPercent: getLineTaxPercent(+ initialValues.supplierUnitPrice ?? 0,+ initialValues.purchaseQuantity ?? 1,+ initialValues.supplierShippingCost ?? 0,+ initialValues.supplierTaxAmount ?? 0+ )});useEffect(() => {- const subtotal =- indirectData.supplierUnitPrice * indirectData.purchaseQuantity +- indirectData.supplierShippingCost;+ const subtotal = getLineSubtotal(+ indirectData.supplierUnitPrice,+ indirectData.purchaseQuantity,+ indirectData.supplierShippingCost+ );if (indirectData.taxPercent !== 0) {setIndirectData((d) => ({...d,@@ -446,6 +458,13 @@ const PurchaseOrderLineForm = ({}));};+ const collapsedTaxPercent = getLineTaxPercent(+ initialValues?.supplierUnitPrice ?? 0,+ initialValues?.purchaseQuantity ?? 1,+ initialValues?.supplierShippingCost ?? 0,+ initialValues?.supplierTaxAmount ?? 0+ );+return (<><Tabs@@ -539,13 +558,9 @@ const PurchaseOrderLineForm = ({)}{" "}{initialValues?.purchaseUnitOfMeasureCode}</Badge>- {/* @ts-expect-error TS2339 */}- {initialValues?.taxPercent > 0 ? (+ {collapsedTaxPercent > 0 ? (<Badge variant="red">- {percentFormatter.format(- /* @ts-expect-error TS2339 */- initialValues?.taxPercent ?? 0- )}{" "}+ {percentFormatter.format(collapsedTaxPercent)}{" "}Tax</Badge>) : null}diff --git a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/usePurchaseOrder.ts b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/usePurchaseOrder.tsindex 864b4a08ce..dbbb5c7e03 100644--- a/apps/erp/app/modules/purchasing/ui/PurchaseOrder/usePurchaseOrder.ts+++ b/apps/erp/app/modules/purchasing/ui/PurchaseOrder/usePurchaseOrder.ts@@ -27,9 +27,10 @@ export const usePurchaseOrder = () => {const receive = useCallback((purchaseOrder: PurchaseOrder) => {+ if (!purchaseOrder.id) return;const formData = new FormData();formData.set("sourceDocument", "Purchase Order");- formData.set("sourceDocumentId", purchaseOrder.id!);+ formData.set("sourceDocumentId", purchaseOrder.id);submit(formData, { method: "post", action: path.to.newReceipt });},[submit]@@ -37,9 +38,10 @@ export const usePurchaseOrder = () => {const ship = useCallback((purchaseOrder: PurchaseOrder) => {+ if (!purchaseOrder.id) return;const formData = new FormData();formData.set("sourceDocument", "Purchase Order");- formData.set("sourceDocumentId", purchaseOrder.id!);+ formData.set("sourceDocumentId", purchaseOrder.id);submit(formData, { method: "post", action: path.to.newShipment });},[submit]diff --git a/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQLineForm.tsx b/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQLineForm.tsxindex c7959ae092..1e4b735da5 100644--- a/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQLineForm.tsx+++ b/apps/erp/app/modules/purchasing/ui/PurchasingRfq/PurchasingRFQLineForm.tsx@@ -204,7 +204,9 @@ const PurchasingRFQLineForm = ({<Hidden name="order" /><Hiddenname="inventoryUnitOfMeasureCode"- value={itemData?.inventoryUom}+ value={+ itemData?.inventoryUom || itemData?.purchaseUom || "EA"+ }/><VStack><div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">diff --git a/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionDocuments.tsx b/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionDocuments.tsxindex 8352bd64c8..ef0ea1e269 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionDocuments.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionDocuments.tsx@@ -208,7 +208,7 @@ export const useSupplierInteractionDocuments = ({const revalidator = useRevalidator();const submit = useSubmit();- const canDelete = permissions.can("delete", "sales"); // TODO: or is document owner+ const canDelete = permissions.can("delete", "purchasing"); // TODO: or is document ownerconst getPath = useCallback((attachment: { name: string }) => {@@ -347,7 +347,7 @@ const SupplierInteractionDocumentForm = (return (<File- isDisabled={!permissions.can("update", "sales")}+ isDisabled={!permissions.can("update", "purchasing")}leftIcon={<LuUpload />}onChange={uploadFiles}multiplediff --git a/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionLineDocuments.tsx b/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionLineDocuments.tsxindex 7f3b1f4db4..0b2aa714be 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionLineDocuments.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionLineDocuments.tsx@@ -58,8 +58,8 @@ const useSupplierInteractionLineDocuments = ({const { company } = useUser();const submit = useSubmit();- const canDelete = permissions.can("delete", "sales");- const canUpdate = permissions.can("update", "sales");+ const canDelete = permissions.can("delete", "purchasing");+ const canUpdate = permissions.can("update", "purchasing");const getPath = useCallback((file: { name: string }) => {@@ -372,7 +372,7 @@ const SupplierInteractionLineDocumentForm = ({return (<File- isDisabled={!permissions.can("update", "sales")}+ isDisabled={!permissions.can("update", "purchasing")}leftIcon={<LuUpload />}onChange={uploadFiles}multiplediff --git a/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionNotes.tsx b/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionNotes.tsxindex c6408cee62..554d6fb5e7 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionNotes.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierInteraction/SupplierInteractionNotes.tsx@@ -136,7 +136,7 @@ const SupplierInteractionNotes = ({</HStack><CardContent><TabsContent value="internal">- {!isReadOnly && permissions.can("update", "sales") ? (+ {!isReadOnly && permissions.can("update", "purchasing") ? (<EditorinitialValue={(internalNotes ?? {}) as JSONContent}onUpload={onUploadImage}@@ -156,7 +156,7 @@ const SupplierInteractionNotes = ({</TabsContent>{["purchaseOrder", "purchaseInvoice"].includes(table) && (<TabsContent value="external">- {!isReadOnly && permissions.can("update", "sales") ? (+ {!isReadOnly && permissions.can("update", "purchasing") ? (<EditorinitialValue={(externalNotes ?? {}) as JSONContent}onUpload={onUploadImage}diff --git a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsxindex 704282c404..e1e961efab 100644--- a/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx+++ b/apps/erp/app/modules/purchasing/ui/SupplierQuote/SupplierQuoteLinePricing.tsx@@ -119,7 +119,8 @@ const SupplierQuoteLinePricing = ({.update({[key]: value,supplierQuoteLineId: lineId,- quantity+ quantity,+ updatedBy: userId}).eq("supplierQuoteLineId", lineId).eq("quantity", quantity);@@ -127,6 +128,7 @@ const SupplierQuoteLinePricing = ({if (update?.error) {console.error(update.error);toast.error(t`Failed to update supplier quote line`);+ setEditableFields((prev) => ({ ...prev, prices: oldPrices }));}} else {const insert = await carbon?.from("supplierQuoteLinePrice").insert({@@ -138,6 +140,7 @@ const SupplierQuoteLinePricing = ({if (insert?.error) {console.error(insert.error);toast.error(t`Failed to insert supplier quote line`);+ setEditableFields((prev) => ({ ...prev, prices: oldPrices }));}}},diff --git a/apps/erp/app/modules/sales/sales.models.ts b/apps/erp/app/modules/sales/sales.models.tsindex 748e6d8f8d..ec4e22317d 100644--- a/apps/erp/app/modules/sales/sales.models.ts+++ b/apps/erp/app/modules/sales/sales.models.ts@@ -741,8 +741,8 @@ export const salesOrderShipmentValidator = zreturn true;},{- message: "Drop shipment requires supplier and location",- path: ["dropShipment"] // path of error+ message: "Drop shipment requires customer and location",+ path: ["customerLocationId"]});diff --git a/apps/erp/app/modules/sales/ui/Quotes/QuoteFinalizeModal.tsx b/apps/erp/app/modules/sales/ui/Quotes/QuoteFinalizeModal.tsxindex 459e9dfa38..0ba25b50f3 100644--- a/apps/erp/app/modules/sales/ui/Quotes/QuoteFinalizeModal.tsx+++ b/apps/erp/app/modules/sales/ui/Quotes/QuoteFinalizeModal.tsx@@ -12,6 +12,7 @@ import {ModalFooter,ModalHeader,ModalTitle,+ toast,useMount,VStack} from "@carbon/react";@@ -72,14 +73,18 @@ const QuotationFinalizeModal = ({const fetchQuoteData = async () => {if (!carbon) return;- const [lines, prices] = await Promise.all([- getQuoteLines(carbon, quoteId),- getQuoteLinePricesByQuoteId(carbon, quoteId)- ]);- setLines(lines.data ?? []);- setPrices(prices.data ?? []);-- setLoading(false);+ try {+ const [lines, prices] = await Promise.all([+ getQuoteLines(carbon, quoteId),+ getQuoteLinePricesByQuoteId(carbon, quoteId)+ ]);+ setLines(lines.data ?? []);+ setPrices(prices.data ?? []);+ } catch {+ toast.error("Failed to load quote data");+ } finally {+ setLoading(false);+ }};useMount(() => {diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsxindex 2485d99905..31752bc959 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderLineForm.tsx@@ -34,6 +34,7 @@ import {TabsContent,TabsList,TabsTrigger,+ toast,useDebounce,useDisclosure,useMount,@@ -281,8 +282,10 @@ const SalesOrderLineForm = ({trace: result.trace ?? null};}+ toast.error("Couldn't apply pricing rules — using base price");} catch {// Fall back to itemUnitSalePrice on any error+ toast.error("Couldn't apply pricing rules — using base price");}return null;},diff --git a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsxindex ff3cc75678..4aa920e472 100644--- a/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx+++ b/apps/erp/app/modules/sales/ui/SalesOrder/SalesOrderShipmentForm.tsx@@ -155,7 +155,7 @@ const SalesOrderShipmentForm = forwardRef<termId="sales-order-shipment-receipt-promised-date"/><DatePicker- name="shipmentDate"+ name="deliveryDate"label={t`Shipment Date`}termId="sales-order-shipment-date"/>diff --git a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.jsonindex ddc21bbce1..3685e8b92d 100644--- a/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json+++ b/apps/erp/app/routes/api+/mcp+/lib/tool-metadata.json@@ -1,5 +1,5 @@{- "generated": "2026-07-04T10:15:13.582Z",+ "generated": "2026-07-06T06:36:29.066Z","totalTools": 1254,"modules": 15,"tools": [@@ -9464,7 +9464,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -9489,7 +9490,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -9514,7 +9516,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -9539,7 +9542,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -9564,7 +9568,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -9589,7 +9594,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -9764,7 +9770,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -13042,7 +13049,7 @@"module": "items","classification": "WRITE","description": "upsert method material",- "paramCount": 4,+ "paramCount": 1,"serviceParams": ["client","methodMaterial"@@ -13055,22 +13062,10 @@"schema": {"type": "object","properties": {- "id": {- "type": "string"- },- "makeMethodId": {- "type": "string"- },- "order": {- "type": "number"- },- "itemType": {- "type": "string"- }+ "methodMaterial": {}},"required": [- "id",- "makeMethodId"+ "methodMaterial"]}},@@ -13343,7 +13338,8 @@"paramCount": 1,"serviceParams": ["client",- "id"+ "id",+ "companyId"],"injectAuth": ["companyId"@@ -17912,7 +17908,8 @@"description": "update job material order","paramCount": 2,"serviceParams": [- "client",+ "db",+ "companyId","updates"],"injectAuth": [@@ -17942,7 +17939,8 @@"description": "update job operation order","paramCount": 2,"serviceParams": [- "client",+ "db",+ "companyId","updates"],"injectAuth": [@@ -17972,7 +17970,8 @@"description": "update job operation step order","paramCount": 2,"serviceParams": [- "client",+ "db",+ "companyId","updates"],"injectAuth": [@@ -18215,7 +18214,7 @@"module": "production","classification": "WRITE","description": "update production quantity",- "paramCount": 3,+ "paramCount": 1,"serviceParams": ["client","productionQuantity"@@ -18227,18 +18226,10 @@"schema": {"type": "object","properties": {- "id": {- "type": "string"- },- "jobOperationId": {- "type": "string"- },- "type": {- "type": "number"- }+ "productionQuantity": {}},"required": [- "jobOperationId"+ "productionQuantity"]}},@@ -18247,7 +18238,7 @@"module": "production","classification": "WRITE","description": "upsert production quantity",- "paramCount": 3,+ "paramCount": 1,"serviceParams": ["client","productionQuantity"@@ -18260,18 +18251,10 @@"schema": {"type": "object","properties": {- "id": {- "type": "string"- },- "jobOperationId": {- "type": "string"- },- "type": {- "type": "number"- }+ "productionQuantity": {}},"required": [- "jobOperationId"+ "productionQuantity"]}},diff --git a/apps/erp/app/routes/x+/items+/dimensions.delete.$id.tsx b/apps/erp/app/routes/x+/items+/dimensions.delete.$id.tsxindex 6228ebbbd9..92df8d28c6 100644--- a/apps/erp/app/routes/x+/items+/dimensions.delete.$id.tsx+++ b/apps/erp/app/routes/x+/items+/dimensions.delete.$id.tsx@@ -30,7 +30,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -45,7 +45,11 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const { error: deleteTypeError } = await deleteMaterialDimension(client, id);+ const { error: deleteTypeError } = await deleteMaterialDimension(+ client,+ id,+ companyId+ );if (deleteTypeError) {throw redirect(`${path.to.materialDimensions}?${getParams(request)}`,diff --git a/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsx b/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsxindex e9ff3793db..5e2094d551 100644--- a/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsx+++ b/apps/erp/app/routes/x+/items+/finishes.delete.$id.tsx@@ -30,7 +30,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -42,7 +42,11 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const { error: deleteTypeError } = await deleteMaterialFinish(client, id);+ const { error: deleteTypeError } = await deleteMaterialFinish(+ client,+ id,+ companyId+ );if (deleteTypeError) {throw redirect(`${path.to.materialFinishes}?${getParams(request)}`,diff --git a/apps/erp/app/routes/x+/items+/forms.delete.$formId.tsx b/apps/erp/app/routes/x+/items+/forms.delete.$formId.tsxindex 325412f427..5355f103c0 100644--- a/apps/erp/app/routes/x+/items+/forms.delete.$formId.tsx+++ b/apps/erp/app/routes/x+/items+/forms.delete.$formId.tsx@@ -30,7 +30,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -42,7 +42,11 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const { error: deleteTypeError } = await deleteMaterialForm(client, formId);+ const { error: deleteTypeError } = await deleteMaterialForm(+ client,+ formId,+ companyId+ );if (deleteTypeError) {throw redirect(`${path.to.materialForms}?${getParams(request)}`,diff --git a/apps/erp/app/routes/x+/items+/grades.delete.$id.tsx b/apps/erp/app/routes/x+/items+/grades.delete.$id.tsxindex 091989b077..b8d0e0cdb9 100644--- a/apps/erp/app/routes/x+/items+/grades.delete.$id.tsx+++ b/apps/erp/app/routes/x+/items+/grades.delete.$id.tsx@@ -30,7 +30,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -42,7 +42,11 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const { error: deleteTypeError } = await deleteMaterialGrade(client, id);+ const { error: deleteTypeError } = await deleteMaterialGrade(+ client,+ id,+ companyId+ );if (deleteTypeError) {throw redirect(`${path.to.materialGrades}?${getParams(request)}`,diff --git a/apps/erp/app/routes/x+/items+/groups.delete.$groupId.tsx b/apps/erp/app/routes/x+/items+/groups.delete.$groupId.tsxindex 727f5d99f7..40b8a758e3 100644--- a/apps/erp/app/routes/x+/items+/groups.delete.$groupId.tsx+++ b/apps/erp/app/routes/x+/items+/groups.delete.$groupId.tsx@@ -35,7 +35,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -49,7 +49,8 @@ export async function action({ request, params }: ActionFunctionArgs) {const { error: deleteTypeError } = await deleteItemPostingGroup(client,- groupId+ groupId,+ companyId);if (deleteTypeError) {throw redirect(diff --git a/apps/erp/app/routes/x+/items+/substances.delete.$substanceId.tsx b/apps/erp/app/routes/x+/items+/substances.delete.$substanceId.tsxindex f90553c022..329580e71a 100644--- a/apps/erp/app/routes/x+/items+/substances.delete.$substanceId.tsx+++ b/apps/erp/app/routes/x+/items+/substances.delete.$substanceId.tsx@@ -30,7 +30,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -47,7 +47,8 @@ export async function action({ request, params }: ActionFunctionArgs) {const { error: deleteTypeError } = await deleteMaterialSubstance(client,- substanceId+ substanceId,+ companyId);if (deleteTypeError) {throw redirect(diff --git a/apps/erp/app/routes/x+/items+/types.delete.$id.tsx b/apps/erp/app/routes/x+/items+/types.delete.$id.tsxindex 91b8cb2436..72753167e2 100644--- a/apps/erp/app/routes/x+/items+/types.delete.$id.tsx+++ b/apps/erp/app/routes/x+/items+/types.delete.$id.tsx@@ -30,7 +30,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -42,7 +42,11 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const { error: deleteTypeError } = await deleteMaterialType(client, id);+ const { error: deleteTypeError } = await deleteMaterialType(+ client,+ id,+ companyId+ );if (deleteTypeError) {throw redirect(`${path.to.materialTypes}?${getParams(request)}`,diff --git a/apps/erp/app/routes/x+/items+/uom.delete.$uomId.tsx b/apps/erp/app/routes/x+/items+/uom.delete.$uomId.tsxindex d2496c422e..300a2ef191 100644--- a/apps/erp/app/routes/x+/items+/uom.delete.$uomId.tsx+++ b/apps/erp/app/routes/x+/items+/uom.delete.$uomId.tsx@@ -36,7 +36,7 @@ export async function loader({ request, params }: LoaderFunctionArgs) {}export async function action({ request, params }: ActionFunctionArgs) {- const { client } = await requirePermissions(request, {+ const { client, companyId } = await requirePermissions(request, {delete: "parts"});@@ -48,7 +48,11 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const { error: deleteTypeError } = await deleteUnitOfMeasure(client, uomId);+ const { error: deleteTypeError } = await deleteUnitOfMeasure(+ client,+ uomId,+ companyId+ );if (deleteTypeError) {throw redirect(path.to.uoms,diff --git a/apps/erp/app/routes/x+/job+/$jobId.delete.tsx b/apps/erp/app/routes/x+/job+/$jobId.delete.tsxindex 8b82d5a55d..2026bdb239 100644--- a/apps/erp/app/routes/x+/job+/$jobId.delete.tsx+++ b/apps/erp/app/routes/x+/job+/$jobId.delete.tsx@@ -2,7 +2,7 @@ import { assertIsPost, error } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { flash } from "@carbon/auth/session.server";import type { ActionFunctionArgs } from "react-router";-import { data, redirect } from "react-router";+import { redirect } from "react-router";import { deleteJob } from "~/modules/production";import { path } from "~/utils/path";@@ -18,7 +18,7 @@ export async function action({ request, params }: ActionFunctionArgs) {const jobDelete = await deleteJob(client, jobId);if (jobDelete.error) {- return data(+ throw redirect(path.to.jobs,await flash(request, error(jobDelete.error, jobDelete.error.message)));diff --git a/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.delete.tsx b/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.delete.tsxindex a6c368c737..35aada045b 100644--- a/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.delete.tsx+++ b/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.delete.tsx@@ -1,3 +1,4 @@+import { assertIsPost } from "@carbon/auth";import { requirePermissions } from "@carbon/auth/auth.server";import { getCarbonServiceRole } from "@carbon/auth/client.server";import type { ActionFunctionArgs } from "react-router";@@ -5,6 +6,7 @@ import { data } from "react-router";import { recalculateJobOperationDependencies } from "~/modules/production/production.service";export async function action({ request, params }: ActionFunctionArgs) {+ assertIsPost(request);const { client, companyId, userId } = await requirePermissions(request, {delete: "production"});@@ -29,7 +31,25 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const { error } = await client.from("jobOperation").delete().eq("id", id);+ const events = await client+ .from("productionEvent")+ .select("id", { count: "exact", head: true })+ .eq("jobOperationId", id);+ if ((events.count ?? 0) > 0) {+ return data(+ {+ success: false,+ error: "Cannot delete an operation that has recorded production events"+ },+ { status: 400 }+ );+ }++ const { error } = await client+ .from("jobOperation")+ .delete()+ .eq("id", id)+ .eq("companyId", companyId);if (error) {return data(diff --git a/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.order.tsx b/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.order.tsxindex a0c85569a2..7aaf6e32a4 100644--- a/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.order.tsx+++ b/apps/erp/app/routes/x+/job+/methods+/$jobId.operation.order.tsx@@ -8,10 +8,11 @@ import {recalculateJobOperationDependencies,updateJobOperationOrder} from "~/modules/production";+import { getDatabaseClient } from "~/services/database.server";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client, companyId, userId } = await requirePermissions(request, {+ const { companyId, userId } = await requirePermissions(request, {update: "production"});@@ -41,15 +42,14 @@ export async function action({ request, params }: ActionFunctionArgs) {}));- const updateSortOrders = await updateJobOperationOrder(client, updates);- if (updateSortOrders.some((update) => update.error))+ try {+ await updateJobOperationOrder(getDatabaseClient(), companyId, updates);+ } catch (err) {return data({},- await flash(- request,- error(updateSortOrders, "Failed to update sort order")- )+ await flash(request, error(err, "Failed to update sort order")));+ }if (jobId) {const recalculateDependencies = await recalculateJobOperationDependencies(diff --git a/apps/erp/app/routes/x+/job+/methods+/material.order.tsx b/apps/erp/app/routes/x+/job+/methods+/material.order.tsxindex c2d56222dd..07d7297e96 100644--- a/apps/erp/app/routes/x+/job+/methods+/material.order.tsx+++ b/apps/erp/app/routes/x+/job+/methods+/material.order.tsx@@ -4,10 +4,11 @@ import { flash } from "@carbon/auth/session.server";import type { ActionFunctionArgs } from "react-router";import { data } from "react-router";import { updateJobMaterialOrder } from "~/modules/production";+import { getDatabaseClient } from "~/services/database.server";export async function action({ request }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { companyId, userId } = await requirePermissions(request, {update: "production"});@@ -27,15 +28,14 @@ export async function action({ request }: ActionFunctionArgs) {}));- const updateSortOrders = await updateJobMaterialOrder(client, updates);- if (updateSortOrders.some((update) => update.error))+ try {+ await updateJobMaterialOrder(getDatabaseClient(), companyId, updates);+ } catch (err) {return data({},- await flash(- request,- error(updateSortOrders, "Failed to update sort order")- )+ await flash(request, error(err, "Failed to update sort order")));+ }return null;}diff --git a/apps/erp/app/routes/x+/job+/methods+/operation.$operationId.step.order.tsx b/apps/erp/app/routes/x+/job+/methods+/operation.$operationId.step.order.tsxindex b59916121d..bdfd98a5ff 100644--- a/apps/erp/app/routes/x+/job+/methods+/operation.$operationId.step.order.tsx+++ b/apps/erp/app/routes/x+/job+/methods+/operation.$operationId.step.order.tsx@@ -4,10 +4,11 @@ import { flash } from "@carbon/auth/session.server";import type { ActionFunctionArgs } from "react-router";import { data } from "react-router";import { updateJobOperationStepOrder } from "~/modules/production";+import { getDatabaseClient } from "~/services/database.server";export async function action({ request, params }: ActionFunctionArgs) {assertIsPost(request);- const { client, userId } = await requirePermissions(request, {+ const { companyId, userId } = await requirePermissions(request, {update: "production"});@@ -37,15 +38,14 @@ export async function action({ request, params }: ActionFunctionArgs) {}));- const updateSortOrders = await updateJobOperationStepOrder(client, updates);- if (updateSortOrders.some((update) => update.error))+ try {+ await updateJobOperationStepOrder(getDatabaseClient(), companyId, updates);+ } catch (err) {return data({},- await flash(- request,- error(updateSortOrders, "Failed to update sort order")- )+ await flash(request, error(err, "Failed to update sort order")));+ }return { success: true };}diff --git a/apps/erp/app/routes/x+/sales+/pricing-rules.$ruleId.tsx b/apps/erp/app/routes/x+/sales+/pricing-rules.$ruleId.tsxindex 89b5b15fe3..9a5279ae98 100644--- a/apps/erp/app/routes/x+/sales+/pricing-rules.$ruleId.tsx+++ b/apps/erp/app/routes/x+/sales+/pricing-rules.$ruleId.tsx@@ -23,8 +23,17 @@ export async function loader({ request, params }: LoaderFunctionArgs) {if (!ruleId) throw notFound("ruleId not found");const pricingRule = await getPricingRule(client, ruleId);+ if (pricingRule.error) {+ throw redirect(+ path.to.salesPricingRules,+ await flash(+ request,+ error(pricingRule.error, "Failed to load pricing rule")+ )+ );+ }- return { pricingRule: pricingRule?.data ?? null };+ return { pricingRule: pricingRule.data };}export async function action({ request, params }: ActionFunctionArgs) {diff --git a/packages/locale/locales/de/erp.po b/packages/locale/locales/de/erp.poindex d52929c45c..6b2f3533e4 100644--- a/packages/locale/locales/de/erp.po+++ b/packages/locale/locales/de/erp.po@@ -12428,8 +12428,8 @@ msgstr "Rückgängig machen"msgid "Uninstall"msgstr "Deinstallieren"-msgid "Unique, uppercase, without spaces"-msgstr "Eindeutig, Großbuchstaben, ohne Leerzeichen"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Einheit"diff --git a/packages/locale/locales/en/erp.po b/packages/locale/locales/en/erp.poindex bb5e49ad78..b373adc5ca 100644--- a/packages/locale/locales/en/erp.po+++ b/packages/locale/locales/en/erp.po@@ -12428,8 +12428,8 @@ msgstr "Undo"msgid "Uninstall"msgstr "Uninstall"-msgid "Unique, uppercase, without spaces"-msgstr "Unique, uppercase, without spaces"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr "Unique, uppercase, without spaces (max 10 characters)"msgid "Unit"msgstr "Unit"diff --git a/packages/locale/locales/es/erp.po b/packages/locale/locales/es/erp.poindex 2ca1f2b563..cde9bdfdea 100644--- a/packages/locale/locales/es/erp.po+++ b/packages/locale/locales/es/erp.po@@ -12428,8 +12428,8 @@ msgstr "Deshacer"msgid "Uninstall"msgstr "Desinstalar"-msgid "Unique, uppercase, without spaces"-msgstr "Único, mayúsculas, sin espacios"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Unidad"diff --git a/packages/locale/locales/fr/erp.po b/packages/locale/locales/fr/erp.poindex e18d97978f..00782477ee 100644--- a/packages/locale/locales/fr/erp.po+++ b/packages/locale/locales/fr/erp.po@@ -12428,8 +12428,8 @@ msgstr "Annuler"msgid "Uninstall"msgstr "Désinstaller"-msgid "Unique, uppercase, without spaces"-msgstr "Unique, majuscules, sans espaces"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Unité"diff --git a/packages/locale/locales/hi/erp.po b/packages/locale/locales/hi/erp.poindex ade72679ed..4184d0cf14 100644--- a/packages/locale/locales/hi/erp.po+++ b/packages/locale/locales/hi/erp.po@@ -12428,8 +12428,8 @@ msgstr "पूर्ववत करें"msgid "Uninstall"msgstr "अनइंस्टॉल करें"-msgid "Unique, uppercase, without spaces"-msgstr "अद्वितीय, बड़े अक्षर, बिना रिक्त स्थान के"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "इकाई"diff --git a/packages/locale/locales/it/erp.po b/packages/locale/locales/it/erp.poindex 60e5099e47..a0fa402b62 100644--- a/packages/locale/locales/it/erp.po+++ b/packages/locale/locales/it/erp.po@@ -12428,8 +12428,8 @@ msgstr "Annulla"msgid "Uninstall"msgstr "Disinstalla"-msgid "Unique, uppercase, without spaces"-msgstr "Univoco, maiuscolo, senza spazi"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Unità"diff --git a/packages/locale/locales/ja/erp.po b/packages/locale/locales/ja/erp.poindex 203f42f215..69a346e6fe 100644--- a/packages/locale/locales/ja/erp.po+++ b/packages/locale/locales/ja/erp.po@@ -12428,8 +12428,8 @@ msgstr "元に戻す"msgid "Uninstall"msgstr "アンインストール"-msgid "Unique, uppercase, without spaces"-msgstr "ユニーク、大文字、スペースなし"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "単位"diff --git a/packages/locale/locales/pl/erp.po b/packages/locale/locales/pl/erp.poindex fb610e1c34..792369ae8f 100644--- a/packages/locale/locales/pl/erp.po+++ b/packages/locale/locales/pl/erp.po@@ -12428,8 +12428,8 @@ msgstr "Cofnij"msgid "Uninstall"msgstr "Odinstaluj"-msgid "Unique, uppercase, without spaces"-msgstr "Unikalne, wielkie litery, bez spacji"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Jednostka"diff --git a/packages/locale/locales/pt/erp.po b/packages/locale/locales/pt/erp.poindex 8e9244f7b6..f53449c3f7 100644--- a/packages/locale/locales/pt/erp.po+++ b/packages/locale/locales/pt/erp.po@@ -12428,8 +12428,8 @@ msgstr "Desfazer"msgid "Uninstall"msgstr "Desinstalar"-msgid "Unique, uppercase, without spaces"-msgstr "Único, maiúsculas, sem espaços"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Unidade"diff --git a/packages/locale/locales/ru/erp.po b/packages/locale/locales/ru/erp.poindex d4aa4ea43b..5b1b3cbe2e 100644--- a/packages/locale/locales/ru/erp.po+++ b/packages/locale/locales/ru/erp.po@@ -12428,8 +12428,8 @@ msgstr "Отменить"msgid "Uninstall"msgstr "Удалить"-msgid "Unique, uppercase, without spaces"-msgstr "Уникальный, прописные буквы, без пробелов"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Единица"diff --git a/packages/locale/locales/tr/erp.po b/packages/locale/locales/tr/erp.poindex 6037d6524e..32f272e77a 100644--- a/packages/locale/locales/tr/erp.po+++ b/packages/locale/locales/tr/erp.po@@ -12428,8 +12428,8 @@ msgstr "Geri Al"msgid "Uninstall"msgstr "Kaldır"-msgid "Unique, uppercase, without spaces"-msgstr "Benzersiz, büyük harfli, boşluksuz"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "Birim"diff --git a/packages/locale/locales/zh/erp.po b/packages/locale/locales/zh/erp.poindex 39c1de367a..1652a46ef7 100644--- a/packages/locale/locales/zh/erp.po+++ b/packages/locale/locales/zh/erp.po@@ -12428,8 +12428,8 @@ msgstr "撤销"msgid "Uninstall"msgstr "卸载"-msgid "Unique, uppercase, without spaces"-msgstr "唯一、大写、无空格"+msgid "Unique, uppercase, without spaces (max 10 characters)"+msgstr ""msgid "Unit"msgstr "单位"