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
Add lower tier notification and max amount to approvals
Gaurav Bhatt344a16958638
diff --git a/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleCard.tsx b/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleCard.tsxindex 1ba4d9400a..3cb05cd3d5 100644--- a/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleCard.tsx+++ b/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleCard.tsx@@ -78,7 +78,9 @@ const ApprovalRuleCard = memo({approvalDocumentTypesWithAmounts.includes(documentType) &&- ` over ${currencyFormatter.format(rule.lowerBoundAmount ?? 0)}`}+ (rule.upperBoundAmount != null+ ? ` ${currencyFormatter.format(rule.lowerBoundAmount ?? 0)} – ${currencyFormatter.format(rule.upperBoundAmount)}`+ : ` over ${currencyFormatter.format(rule.lowerBoundAmount ?? 0)}`)}</Heading><Statuscolor={rule.enabled ? "green" : "gray"}diff --git a/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleDetails.tsx b/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleDetails.tsxindex 36e6c871e8..c04b9fe0d5 100644--- a/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleDetails.tsx+++ b/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleDetails.tsx@@ -59,6 +59,15 @@ const ApprovalRuleDetails = memo(</FieldItem>)}+ {documentType === "purchaseOrder" &&+ rule.upperBoundAmount != null && (+ <FieldItem icon={LuDollarSign} label={t`Maximum Amount`}>+ <p className="text-sm font-semibold text-foreground leading-relaxed">+ {currencyFormatter.format(rule.upperBoundAmount)}+ </p>+ </FieldItem>+ )}+{/* Approver Groups */}<FieldItem icon={LuUsers} label={t`Who Can Approve`}>{rule.approverGroupIds && rule.approverGroupIds.length > 0 ? (diff --git a/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleForm.tsx b/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleForm.tsxindex 0b60740b50..75e0d3d68c 100644--- a/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleForm.tsx+++ b/apps/erp/app/modules/settings/ui/Approvals/ApprovalRuleForm.tsx@@ -56,6 +56,7 @@ const ApprovalRuleForm = ({: [],defaultApproverId: rule.defaultApproverId ?? undefined,lowerBoundAmount: rule.lowerBoundAmount ?? 0,+ upperBoundAmount: rule.upperBoundAmount ?? undefined,escalationDays: rule.escalationDays ?? undefined}: {@@ -64,6 +65,7 @@ const ApprovalRuleForm = ({enabled: true,approverGroupIds: [],lowerBoundAmount: 0,+ upperBoundAmount: undefined,escalationDays: undefined};@@ -103,14 +105,25 @@ const ApprovalRuleForm = ({approvalDocumentTypesWithAmounts.includes(effectiveDocumentType) && (- <FormNumber- name="lowerBoundAmount"- label={t`Minimum Amount`}- formatOptions={{- style: "currency",- currency: baseCurrencyCode- }}- />+ <>+ <FormNumber+ name="lowerBoundAmount"+ label={t`Minimum Amount`}+ formatOptions={{+ style: "currency",+ currency: baseCurrencyCode+ }}+ />+ <FormNumber+ name="upperBoundAmount"+ label={t`Maximum Amount`}+ helperText={t`Leave empty for no upper limit`}+ formatOptions={{+ style: "currency",+ currency: baseCurrencyCode+ }}+ />+ </>)}<Usersdiff --git a/apps/erp/app/modules/shared/shared.models.ts b/apps/erp/app/modules/shared/shared.models.tsindex 13d43bbad3..7225173daf 100644--- a/apps/erp/app/modules/shared/shared.models.ts+++ b/apps/erp/app/modules/shared/shared.models.ts@@ -49,18 +49,29 @@ export const approvalRequestValidator = z.object({approverGroupIds: zfd.repeatableOfType(z.string()).optional()});-export const approvalRuleValidator = z.object({- id: zfd.text(z.string().optional()),- documentType: z.enum(approvalDocumentType, {- errorMap: () => ({ message: "Document type is required" })- }),- approverGroupIds: z.array(- z.string().min(1, { message: "Invalid selection" })- ),- defaultApproverId: zfd.text(z.string().optional()),- lowerBoundAmount: zfd.numeric(z.number().gt(0).default(0)).optional(),- enabled: zfd.checkbox()-});+export const approvalRuleValidator = z+ .object({+ id: zfd.text(z.string().optional()),+ documentType: z.enum(approvalDocumentType, {+ errorMap: () => ({ message: "Document type is required" })+ }),+ approverGroupIds: z.array(+ z.string().min(1, { message: "Invalid selection" })+ ),+ defaultApproverId: zfd.text(z.string().optional()),+ lowerBoundAmount: zfd.numeric(z.number().gt(0).default(0)).optional(),+ upperBoundAmount: zfd.numeric(z.number().gt(0).optional()),+ enabled: zfd.checkbox()+ })+ .refine(+ (data) =>+ data.upperBoundAmount == null ||+ data.upperBoundAmount > (data.lowerBoundAmount ?? 0),+ {+ message: "Maximum amount must be greater than minimum amount",+ path: ["upperBoundAmount"]+ }+ );export const approvalStatusType = ["Pending",diff --git a/apps/erp/app/modules/shared/shared.service.ts b/apps/erp/app/modules/shared/shared.service.tsindex 8d67409555..fa6e2102c5 100644--- a/apps/erp/app/modules/shared/shared.service.ts+++ b/apps/erp/app/modules/shared/shared.service.ts@@ -423,7 +423,9 @@ export async function getApprovalRuleByAmount(.eq("enabled", true);if (amount !== undefined && amount !== null) {- query = query.lte("lowerBoundAmount", amount);+ query = query+ .lte("lowerBoundAmount", amount)+ .or(`upperBoundAmount.is.null,upperBoundAmount.gt.${amount}`);} else {query = query.eq("lowerBoundAmount", 0);}diff --git a/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx b/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsxindex 4e7c018138..8fe9beed64 100644--- a/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx+++ b/apps/erp/app/routes/x+/settings+/approval-rules.$id.tsx@@ -76,22 +76,6 @@ export async function action({ request, params }: ActionFunctionArgs) {);}- const rulesForType =- rules.data?.filter(- (r) => r.documentType === validation.data.documentType && r.id !== id- ) || [];- const duplicateRule = rulesForType.find(- (r) => r.lowerBoundAmount === (validation.data.lowerBoundAmount ?? 0)- );-- if (duplicateRule) {- return validationError({- fieldErrors: {- lowerBoundAmount: `A rule with this minimum amount already exists. The maximum for this rule would be set by the next higher rule.`- }- });- }-const result = await upsertApprovalRule(serviceRole, {id,updatedBy: userId,@@ -99,7 +83,8 @@ export async function action({ request, params }: ActionFunctionArgs) {enabled: validation.data.enabled,approverGroupIds: validation.data.approverGroupIds || [],defaultApproverId: validation.data.defaultApproverId,- lowerBoundAmount: validation.data.lowerBoundAmount ?? 0+ lowerBoundAmount: validation.data.lowerBoundAmount ?? 0,+ upperBoundAmount: validation.data.upperBoundAmount ?? null});if (result.error) {diff --git a/apps/erp/app/routes/x+/settings+/approval-rules.new.tsx b/apps/erp/app/routes/x+/settings+/approval-rules.new.tsxindex 20052776bd..79e29eba64 100644--- a/apps/erp/app/routes/x+/settings+/approval-rules.new.tsx+++ b/apps/erp/app/routes/x+/settings+/approval-rules.new.tsx@@ -9,7 +9,6 @@ import { ApprovalRuleForm } from "~/modules/settings";import {type ApprovalDocumentType,approvalRuleValidator,- getApprovalRules,upsertApprovalRule} from "~/modules/shared";import { path } from "~/utils/path";@@ -52,23 +51,6 @@ export async function action({ request }: ActionFunctionArgs) {return validationError(validation.error);}- const existingRules = await getApprovalRules(serviceRole, companyId);- const rulesForType =- existingRules.data?.filter(- (r) => r.documentType === validation.data.documentType- ) || [];- const duplicateRule = rulesForType.find(- (r) => r.lowerBoundAmount === (validation.data.lowerBoundAmount ?? 0)- );-- if (duplicateRule) {- return validationError({- fieldErrors: {- lowerBoundAmount: `A rule with this minimum amount already exists. The maximum for this rule would be set by the next higher rule.`- }- });- }-const result = await upsertApprovalRule(serviceRole, {createdBy: userId,companyId,@@ -76,7 +58,8 @@ export async function action({ request }: ActionFunctionArgs) {enabled: validation.data.enabled,approverGroupIds: validation.data.approverGroupIds || [],defaultApproverId: validation.data.defaultApproverId,- lowerBoundAmount: validation.data.lowerBoundAmount ?? 0+ lowerBoundAmount: validation.data.lowerBoundAmount ?? 0,+ upperBoundAmount: validation.data.upperBoundAmount ?? null});if (result.error) {diff --git a/packages/database/supabase/migrations/20260520000000_approval-rule-upper-bound.sql b/packages/database/supabase/migrations/20260520000000_approval-rule-upper-bound.sqlnew file mode 100644index 0000000000..9b8a571ad9--- /dev/null+++ b/packages/database/supabase/migrations/20260520000000_approval-rule-upper-bound.sql@@ -0,0 +1,12 @@+-- Add an optional upper bound to approval rules. With both bounds set,+-- a rule represents a half-open range [lowerBoundAmount, upperBoundAmount).+-- NULL upperBoundAmount preserves today's "unbounded above" behavior, so+-- existing rules continue working without backfill.++ALTER TABLE "approvalRule"+ ADD COLUMN "upperBoundAmount" NUMERIC,+ ADD CONSTRAINT "approvalRule_upperBoundAmount_check"+ CHECK (+ "upperBoundAmount" IS NULL+ OR "upperBoundAmount" > "lowerBoundAmount"+ );diff --git a/packages/locale/locales/de/erp.po b/packages/locale/locales/de/erp.poindex 91aa2f1e59..7b91bd861a 100644--- a/packages/locale/locales/de/erp.po+++ b/packages/locale/locales/de/erp.po@@ -4236,6 +4236,9 @@ msgstr "Alle zugehörigen Belege unverändert lassen"msgid "Leave empty for exact match"msgstr "Leer lassen für exakte Übereinstimmung"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "Linkes Element"@@ -4574,6 +4577,9 @@ msgstr "Max. Menge"msgid "Maximum"msgstr "Maximum"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "Maximale Bestandsmenge"diff --git a/packages/locale/locales/en/erp.po b/packages/locale/locales/en/erp.poindex 6530944298..ed4fde2831 100644--- a/packages/locale/locales/en/erp.po+++ b/packages/locale/locales/en/erp.po@@ -4236,6 +4236,9 @@ msgstr "Leave any related receipts untouched"msgid "Leave empty for exact match"msgstr "Leave empty for exact match"+msgid "Leave empty for no upper limit"+msgstr "Leave empty for no upper limit"+msgid "Left item"msgstr "Left item"@@ -4574,6 +4577,9 @@ msgstr "Max Quantity"msgid "Maximum"msgstr "Maximum"+msgid "Maximum Amount"+msgstr "Maximum Amount"+msgid "Maximum Inventory Quantity"msgstr "Maximum Inventory Quantity"diff --git a/packages/locale/locales/es/erp.po b/packages/locale/locales/es/erp.poindex 9501e205ac..ac14e6c38e 100644--- a/packages/locale/locales/es/erp.po+++ b/packages/locale/locales/es/erp.po@@ -4236,6 +4236,9 @@ msgstr "Dejar los recibos relacionados sin tocar"msgid "Leave empty for exact match"msgstr "Dejar vacío para coincidencia exacta"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "Elemento izquierdo"@@ -4574,6 +4577,9 @@ msgstr "Cantidad Máxima"msgid "Maximum"msgstr "Máximo"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "Cantidad Máxima de Inventario"diff --git a/packages/locale/locales/fr/erp.po b/packages/locale/locales/fr/erp.poindex 7e906f047c..1fa1767a60 100644--- a/packages/locale/locales/fr/erp.po+++ b/packages/locale/locales/fr/erp.po@@ -4236,6 +4236,9 @@ msgstr "Laisser les reçus connexes intacts"msgid "Leave empty for exact match"msgstr "Laisser vide pour une correspondance exacte"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "Élément de gauche"@@ -4574,6 +4577,9 @@ msgstr "Quantité Max"msgid "Maximum"msgstr "Maximum"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "Quantité d'inventaire maximale"diff --git a/packages/locale/locales/hi/erp.po b/packages/locale/locales/hi/erp.poindex 54981a459a..6b72c4fb66 100644--- a/packages/locale/locales/hi/erp.po+++ b/packages/locale/locales/hi/erp.po@@ -4236,6 +4236,9 @@ msgstr "किसी भी संबंधित रसीदों को अmsgid "Leave empty for exact match"msgstr "सटीक मिलान के लिए खाली छोड़ें"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "बाईं ओर की वस्तु"@@ -4574,6 +4577,9 @@ msgstr "अधिकतम मात्रा"msgid "Maximum"msgstr "अधिकतम"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "अधिकतम इन्वेंटरी मात्रा"diff --git a/packages/locale/locales/it/erp.po b/packages/locale/locales/it/erp.poindex 99bf184f99..5583422141 100644--- a/packages/locale/locales/it/erp.po+++ b/packages/locale/locales/it/erp.po@@ -4236,6 +4236,9 @@ msgstr "Lasciare le ricevute correlate intatte"msgid "Leave empty for exact match"msgstr "Lascia vuoto per una corrispondenza esatta"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "Elemento sinistro"@@ -4574,6 +4577,9 @@ msgstr "Quantità Massima"msgid "Maximum"msgstr "Massimo"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "Quantità Massima di Inventario"diff --git a/packages/locale/locales/ja/erp.po b/packages/locale/locales/ja/erp.poindex bb5b59ebb7..2303d35d6e 100644--- a/packages/locale/locales/ja/erp.po+++ b/packages/locale/locales/ja/erp.po@@ -4236,6 +4236,9 @@ msgstr "関連するすべての領収書はそのままにしておく"msgid "Leave empty for exact match"msgstr "正確な一致のために空のままにしてください"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "左側の項目"@@ -4574,6 +4577,9 @@ msgstr "最大数量"msgid "Maximum"msgstr "最大"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "最大在庫数量"diff --git a/packages/locale/locales/pl/erp.po b/packages/locale/locales/pl/erp.poindex ab10315472..45f4ec3726 100644--- a/packages/locale/locales/pl/erp.po+++ b/packages/locale/locales/pl/erp.po@@ -4236,6 +4236,9 @@ msgstr "Pozostaw wszelkie powiązane paragony bez zmian"msgid "Leave empty for exact match"msgstr "Pozostaw puste dla dokładnego dopasowania"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "Element po lewej stronie"@@ -4574,6 +4577,9 @@ msgstr "Maks. Ilość"msgid "Maximum"msgstr "Maksimum"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "Maksymalna Ilość Zapasów"diff --git a/packages/locale/locales/pt/erp.po b/packages/locale/locales/pt/erp.poindex 5f855fc681..cac4612d98 100644--- a/packages/locale/locales/pt/erp.po+++ b/packages/locale/locales/pt/erp.po@@ -4236,6 +4236,9 @@ msgstr "Deixar qualquer recebimento relacionado intocado"msgid "Leave empty for exact match"msgstr "Deixe vazio para correspondência exata"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "Item esquerdo"@@ -4574,6 +4577,9 @@ msgstr "Quantidade Máxima"msgid "Maximum"msgstr "Máximo"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "Quantidade Máxima de Inventário"diff --git a/packages/locale/locales/ru/erp.po b/packages/locale/locales/ru/erp.poindex 4859eac333..abd21ef6a8 100644--- a/packages/locale/locales/ru/erp.po+++ b/packages/locale/locales/ru/erp.po@@ -4236,6 +4236,9 @@ msgstr "Оставить все связанные квитанции без иmsgid "Leave empty for exact match"msgstr "Оставьте пустым для точного совпадения"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "Левый элемент"@@ -4574,6 +4577,9 @@ msgstr "Макс. Количество"msgid "Maximum"msgstr "Максимум"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "Максимальное количество запасов"diff --git a/packages/locale/locales/zh/erp.po b/packages/locale/locales/zh/erp.poindex c87ea39c0a..ac3bf0a299 100644--- a/packages/locale/locales/zh/erp.po+++ b/packages/locale/locales/zh/erp.po@@ -4236,6 +4236,9 @@ msgstr "保留任何相关收据不变"msgid "Leave empty for exact match"msgstr "留空以精确匹配"+msgid "Leave empty for no upper limit"+msgstr ""+msgid "Left item"msgstr "左项"@@ -4574,6 +4577,9 @@ msgstr "最大数量"msgid "Maximum"msgstr "最大值"+msgid "Maximum Amount"+msgstr ""+msgid "Maximum Inventory Quantity"msgstr "最大库存数量"