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
feat: add method type to sales invoice line
Brad Barbin0d47654f8099
diff --git a/apps/erp/app/modules/invoicing/invoicing.models.ts b/apps/erp/app/modules/invoicing/invoicing.models.tsindex 47dd0d9edc..fcb50cd1d6 100644--- a/apps/erp/app/modules/invoicing/invoicing.models.ts+++ b/apps/erp/app/modules/invoicing/invoicing.models.ts@@ -1,6 +1,6 @@import { z } from "zod";import { zfd } from "zod-form-data";-import { methodItemType } from "../shared";+import { methodItemType, methodType } from "../shared";export const purchaseInvoiceLineType = ["Part",@@ -183,6 +183,11 @@ export const salesInvoiceLineValidator = zmessage: "Type is required",}),}),+ methodType: z.enum(methodType, {+ errorMap: (issue, ctx) => ({+ message: "Method is required",+ }),+ }),purchaseOrderId: zfd.text(z.string().optional()),purchaseOrderLineId: zfd.text(z.string().optional()),itemId: zfd.text(z.string().optional()),diff --git a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsxindex 1b7394b68b..00a64b1680 100644--- a/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx+++ b/apps/erp/app/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm.tsx@@ -19,6 +19,7 @@ import { ValidatedForm } from "@carbon/form";import { useParams } from "@remix-run/react";import { useEffect, useState } from "react";import type { z } from "zod";+import { MethodIcon } from "~/components";import {CustomFormFields,Hidden,@@ -26,6 +27,7 @@ import {Location,Number,NumberControlled,+ SelectControlled,Shelf,Submit,} from "~/components/Form";@@ -33,6 +35,7 @@ import { usePermissions, useRouteData, useUser } from "~/hooks";import type { SalesInvoice } from "~/modules/invoicing";import { salesInvoiceLineValidator } from "~/modules/invoicing";import type { MethodItemType } from "~/modules/shared";+import { methodType } from "~/modules/shared";import { path } from "~/utils/path";type SalesInvoiceLineFormProps = {@@ -69,6 +72,7 @@ const SalesInvoiceLineForm = ({const [itemData, setItemData] = useState<{itemId: string;itemReadableId: string;+ methodType: string;description: string;quantity: number;unitPrice: number;@@ -80,6 +84,7 @@ const SalesInvoiceLineForm = ({}>({itemId: initialValues.itemId ?? "",itemReadableId: initialValues.itemReadableId ?? "",+ methodType: initialValues.methodType ?? "",description: initialValues.description ?? "",quantity: initialValues.quantity ?? 1,unitPrice: initialValues.unitPrice ?? 0,@@ -123,6 +128,7 @@ const SalesInvoiceLineForm = ({setItemData({itemId: "",itemReadableId: "",+ methodType: "",description: "",quantity: 1,unitPrice: 0,@@ -147,7 +153,7 @@ const SalesInvoiceLineForm = ({carbon.from("item").select(- "name, readableId, type, unitOfMeasureCode, itemCost(unitCost)"+ "name, readableId, type, unitOfMeasureCode, defaultMethodType, itemCost(unitCost)").eq("id", itemId).eq("companyId", company.id)@@ -168,6 +174,7 @@ const SalesInvoiceLineForm = ({itemId: itemId,itemReadableId: item.data?.readableId ?? "",description: item.data?.name ?? "",+ methodType: item.data?.defaultMethodType ?? "",unitPrice:(itemCost?.unitCost ?? 0) /(routeData?.salesInvoice?.exchangeRate ?? 1),@@ -261,6 +268,7 @@ const SalesInvoiceLineForm = ({name="unitOfMeasureCode"value={itemData?.unitOfMeasureCode}/>+ <Hidden name="methodType" value={itemData?.methodType} /><VStack><div className="grid w-full gap-x-8 gap-y-4 grid-cols-1 lg:grid-cols-3">@@ -292,6 +300,30 @@ const SalesInvoiceLineForm = ({itemType) && (<>+ <SelectControlled+ name="methodType"+ label="Method"+ options={+ methodType.map((m) => ({+ label: (+ <span className="flex items-center gap-2">+ <MethodIcon type={m} />+ {m}+ </span>+ ),+ value: m,+ })) ?? []+ }+ value={itemData.methodType}+ onChange={(newValue) => {+ if (newValue)+ setItemData((d) => ({+ ...d,+ methodType: newValue?.value,+ }));+ }}+ />+<NumberControlledminValue={itemData.quantity}name="quantity"diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.tsindex ebc4fc034a..cd12067571 100644--- a/packages/database/src/swagger-docs-schema.ts+++ b/packages/database/src/swagger-docs-schema.ts@@ -26046,6 +26046,9 @@ export default {{$ref: "#/parameters/rowFilter.salesInvoiceLines.itemId",},+ {+ $ref: "#/parameters/rowFilter.salesInvoiceLines.methodType",+ },{$ref: "#/parameters/rowFilter.salesInvoiceLines.itemReadableId",},@@ -48978,6 +48981,9 @@ export default {{$ref: "#/parameters/rowFilter.salesInvoiceLine.itemId",},+ {+ $ref: "#/parameters/rowFilter.salesInvoiceLine.methodType",+ },{$ref: "#/parameters/rowFilter.salesInvoiceLine.itemReadableId",},@@ -49139,6 +49145,9 @@ export default {{$ref: "#/parameters/rowFilter.salesInvoiceLine.itemId",},+ {+ $ref: "#/parameters/rowFilter.salesInvoiceLine.methodType",+ },{$ref: "#/parameters/rowFilter.salesInvoiceLine.itemReadableId",},@@ -49254,6 +49263,9 @@ export default {{$ref: "#/parameters/rowFilter.salesInvoiceLine.itemId",},+ {+ $ref: "#/parameters/rowFilter.salesInvoiceLine.methodType",+ },{$ref: "#/parameters/rowFilter.salesInvoiceLine.itemReadableId",},@@ -66563,6 +66575,11 @@ export default {format: "text",type: "string",},+ methodType: {+ enum: ["Buy", "Make", "Pick"],+ format: 'public."methodType"',+ type: "string",+ },itemReadableId: {format: "text",type: "string",@@ -77671,6 +77688,7 @@ export default {"id","invoiceId","invoiceLineType",+ "methodType","quantity","unitOfMeasureCode","exchangeRate",@@ -77723,6 +77741,12 @@ export default {format: "text",type: "string",},+ methodType: {+ default: "Pick",+ enum: ["Buy", "Make", "Pick"],+ format: 'public."methodType"',+ type: "string",+ },itemReadableId: {format: "text",type: "string",@@ -91627,6 +91651,12 @@ export default {in: "query",type: "string",},+ "rowFilter.salesInvoiceLines.methodType": {+ name: "methodType",+ required: false,+ in: "query",+ type: "string",+ },"rowFilter.salesInvoiceLines.itemReadableId": {name: "itemReadableId",required: false,@@ -104263,6 +104293,12 @@ export default {in: "query",type: "string",},+ "rowFilter.salesInvoiceLine.methodType": {+ name: "methodType",+ required: false,+ in: "query",+ type: "string",+ },"rowFilter.salesInvoiceLine.itemReadableId": {name: "itemReadableId",required: false,diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex 071a4ff262..821a75611d 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -23638,6 +23638,7 @@ export type Database = {itemId: string | null;itemReadableId: string | null;locationId: string | null;+ methodType: Database["public"]["Enums"]["methodType"];modelUploadId: string | null;opportunityId: string | null;quantity: number;@@ -23674,6 +23675,7 @@ export type Database = {itemId?: string | null;itemReadableId?: string | null;locationId?: string | null;+ methodType?: Database["public"]["Enums"]["methodType"];modelUploadId?: string | null;opportunityId?: string | null;quantity?: number;@@ -23710,6 +23712,7 @@ export type Database = {itemId?: string | null;itemReadableId?: string | null;locationId?: string | null;+ methodType?: Database["public"]["Enums"]["methodType"];modelUploadId?: string | null;opportunityId?: string | null;quantity?: number;@@ -38927,6 +38930,7 @@ export type Database = {itemName: string | null;itemReadableId: string | null;locationId: string | null;+ methodType: Database["public"]["Enums"]["methodType"] | null;modelUploadId: string | null;opportunityId: string | null;quantity: number | null;diff --git a/packages/database/supabase/config.toml b/packages/database/supabase/config.tomlindex dc9cb9d140..8339771371 100644--- a/packages/database/supabase/config.toml+++ b/packages/database/supabase/config.toml@@ -130,10 +130,7 @@ verify_jwt = false[functions.sync]enabled = trueverify_jwt = true-import_map = "./functions/sync/deno.json"-# Uncomment to specify a custom file path to the entrypoint.-# Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx-entrypoint = "./functions/sync/index.ts"+# Specifies static files to be bundled with the function. Supports glob patterns.# For example, if you want to serve static HTML pages in your function:# static_files = [ "./functions/sync/*.html" ]@@ -141,10 +138,6 @@ entrypoint = "./functions/sync/index.ts"[functions.post-sales-invoice]enabled = trueverify_jwt = true-import_map = "./functions/post-sales-invoice/deno.json"-# Uncomment to specify a custom file path to the entrypoint.-# Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx-entrypoint = "./functions/post-sales-invoice/index.ts"# Specifies static files to be bundled with the function. Supports glob patterns.# For example, if you want to serve static HTML pages in your function:# static_files = [ "./functions/post-sales-invoice/*.html" ]@@ -152,10 +145,7 @@ entrypoint = "./functions/post-sales-invoice/index.ts"[functions.update-sales-prices]enabled = trueverify_jwt = true-import_map = "./functions/update-sales-prices/deno.json"-# Uncomment to specify a custom file path to the entrypoint.-# Supported file extensions are: .ts, .js, .mjs, .jsx, .tsx-entrypoint = "./functions/update-sales-prices/index.ts"+# Specifies static files to be bundled with the function. Supports glob patterns.# For example, if you want to serve static HTML pages in your function:# static_files = [ "./functions/update-sales-prices/*.html" ]diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex 071a4ff262..821a75611d 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -23638,6 +23638,7 @@ export type Database = {itemId: string | null;itemReadableId: string | null;locationId: string | null;+ methodType: Database["public"]["Enums"]["methodType"];modelUploadId: string | null;opportunityId: string | null;quantity: number;@@ -23674,6 +23675,7 @@ export type Database = {itemId?: string | null;itemReadableId?: string | null;locationId?: string | null;+ methodType?: Database["public"]["Enums"]["methodType"];modelUploadId?: string | null;opportunityId?: string | null;quantity?: number;@@ -23710,6 +23712,7 @@ export type Database = {itemId?: string | null;itemReadableId?: string | null;locationId?: string | null;+ methodType?: Database["public"]["Enums"]["methodType"];modelUploadId?: string | null;opportunityId?: string | null;quantity?: number;@@ -38927,6 +38930,7 @@ export type Database = {itemName: string | null;itemReadableId: string | null;locationId: string | null;+ methodType: Database["public"]["Enums"]["methodType"] | null;modelUploadId: string | null;opportunityId: string | null;quantity: number | null;diff --git a/packages/database/supabase/migrations/20250507143421_sales-invoice.sql b/packages/database/supabase/migrations/20250507143421_sales-invoice.sqlindex 96234508b0..7a2931c9e9 100644--- a/packages/database/supabase/migrations/20250507143421_sales-invoice.sql+++ b/packages/database/supabase/migrations/20250507143421_sales-invoice.sql@@ -92,6 +92,7 @@ CREATE TABLE "salesInvoiceLine" ("invoiceLineType" "salesInvoiceLineType" NOT NULL,"description" TEXT,"itemId" TEXT,+ "methodType" "methodType" NOT NULL DEFAULT 'Pick',"itemReadableId" TEXT,"accountNumber" TEXT,"assetId" TEXT,@@ -142,6 +143,28 @@ CREATE INDEX "salesInvoiceLine_invoiceId_idx" ON "salesInvoiceLine" ("invoiceId"CREATE INDEX "salesInvoiceLine_itemId_idx" ON "salesInvoiceLine" ("itemId");CREATE INDEX "salesInvoiceLine_locationId_idx" ON "salesInvoiceLine" ("locationId");+CREATE TABLE "salesInvoiceShipment" (+ "id" TEXT NOT NULL,+ "shippingCost" NUMERIC NOT NULL DEFAULT 0,+ "locationId" TEXT,+ "shippingMethodId" TEXT,+ "shippingTermId" TEXT,+ "customFields" JSONB NOT NULL DEFAULT '{}',+ "companyId" TEXT,+ "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,+ "createdBy" TEXT NOT NULL,+ "updatedAt" TIMESTAMP WITH TIME ZONE,+ "updatedBy" TEXT,++ CONSTRAINT "salesInvoiceShipment_pkey" PRIMARY KEY ("id"),+ CONSTRAINT "salesInvoiceShipment_id_fkey" FOREIGN KEY ("id") REFERENCES "salesInvoice"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "salesInvoiceShipment_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,+ CONSTRAINT "salesInvoiceShipment_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE,+ CONSTRAINT "salesInvoiceShipment_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE+);++CREATE INDEX "salesInvoiceShipment_companyId_idx" ON "salesInvoiceShipment" ("companyId");+DROP VIEW IF EXISTS "salesInvoices";CREATE OR REPLACE VIEW "salesInvoices" WITH(SECURITY_INVOKER=true) ASSELECT@@ -182,29 +205,6 @@ CREATE OR REPLACE VIEW "salesInvoices" WITH(SECURITY_INVOKER=true) ASJOIN "salesInvoiceShipment" ss ON ss."id" = si."id";-CREATE TABLE "salesInvoiceShipment" (- "id" TEXT NOT NULL,- "shippingCost" NUMERIC NOT NULL DEFAULT 0,- "locationId" TEXT,- "shippingMethodId" TEXT,- "shippingTermId" TEXT,- "customFields" JSONB NOT NULL DEFAULT '{}',- "companyId" TEXT,- "createdAt" TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,- "createdBy" TEXT NOT NULL,- "updatedAt" TIMESTAMP WITH TIME ZONE,- "updatedBy" TEXT,-- CONSTRAINT "salesInvoiceShipment_pkey" PRIMARY KEY ("id"),- CONSTRAINT "salesInvoiceShipment_id_fkey" FOREIGN KEY ("id") REFERENCES "salesInvoice"("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "salesInvoiceShipment_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company"("id") ON DELETE CASCADE ON UPDATE CASCADE,- CONSTRAINT "salesInvoiceShipment_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user"("id") ON UPDATE CASCADE,- CONSTRAINT "salesInvoiceShipment_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user"("id") ON UPDATE CASCADE-);--CREATE INDEX "salesInvoiceShipment_companyId_idx" ON "salesInvoiceShipment" ("companyId");--DROP VIEW IF EXISTS "salesInvoiceLines";CREATE OR REPLACE VIEW "salesInvoiceLines" WITH(SECURITY_INVOKER=true) AS (SELECT