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: scan bar codes for serial/batch transfers
Brad Barbin266f12c2a83b
diff --git a/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferCompleteModal.tsx b/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferCompleteModal.tsxindex c9aa78e800..b35649e72d 100644--- a/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferCompleteModal.tsx+++ b/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferCompleteModal.tsx@@ -17,7 +17,6 @@ import {useMount,} from "@carbon/react";import { useRouteData } from "@carbon/remix";-import type { TrackedEntityAttributes } from "@carbon/utils";import { getItemReadableId } from "@carbon/utils";import { useFetcher, useNavigation, useParams } from "@remix-run/react";import { useEffect, useRef, useState } from "react";@@ -25,7 +24,6 @@ import { LuTriangleAlert } from "react-icons/lu";import { useUser } from "~/hooks";import { useItems } from "~/stores";import { path } from "~/utils/path";-import { getStockTransferTracking } from "../../inventory.service";import type { StockTransferLine } from "../../types";const StockTransferPostModal = ({ onClose }: { onClose: () => void }) => {@@ -65,12 +63,6 @@ const StockTransferPostModal = ({ onClose }: { onClose: () => void }) => {return;}- const stockTransferLineTracking = await getStockTransferTracking(- carbon,- id,- companyId- );-if (routeData?.stockTransferLines.length === 0 ||routeData?.stockTransferLines.every((line) => line.pickedQuantity === 0)@@ -84,44 +76,21 @@ const StockTransferPostModal = ({ onClose }: { onClose: () => void }) => {]);}- routeData?.stockTransferLines.forEach((line: StockTransferLine) => {- if (line.requiresBatchTracking) {- const trackedEntity = stockTransferLineTracking.data?.find(- (tracking) => {- const attributes = tracking.attributes as TrackedEntityAttributes;- return attributes["Stock Transfer Line"] === line.id;+ routeData?.stockTransferLines.forEach(async (line: StockTransferLine) => {+ if (line.requiresBatchTracking || line.requiresSerialTracking) {+ if (line.trackedEntityId) {+ const trackedEntity = await carbon+ .from("trackedEntity")+ .select("*")+ .eq("id", line.trackedEntityId)+ .single();+ if (trackedEntity.data?.status !== "Available") {+ errors.push({+ itemReadableId: getItemReadableId(items, line.itemId) ?? null,+ pickedQuantity: line.pickedQuantity ?? 0,+ pickedQuantityError: "Tracked entity is not available",+ });}- );-- if (trackedEntity?.status !== "Available") {- errors.push({- itemReadableId: getItemReadableId(items, line.itemId) ?? null,- pickedQuantity: line.pickedQuantity ?? 0,- pickedQuantityError: "Tracked entity is not available",- });- }- }-- if (line.requiresSerialTracking) {- const trackedEntities = stockTransferLineTracking.data?.filter(- (tracking) => {- const attributes = tracking.attributes as TrackedEntityAttributes;- return attributes["Stock Transfer Line"] === line.id;- }- );-- const quantityAvailable = trackedEntities?.reduce((acc, tracking) => {- const trackingQuantity = Number(tracking.quantity);-- return acc + (tracking.status === "Available" ? trackingQuantity : 0);- }, 0);-- if (quantityAvailable !== line.pickedQuantity) {- errors.push({- itemReadableId: getItemReadableId(items, line.itemId) ?? null,- pickedQuantity: line.pickedQuantity ?? 0,- pickedQuantityError: "Serial numbers are missing or unavailable",- });}}});diff --git a/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferHeader.tsx b/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferHeader.tsxindex e95ffb01df..3fc25c4b46 100644--- a/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferHeader.tsx+++ b/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferHeader.tsx@@ -22,11 +22,7 @@ import {} from "react-icons/lu";import ConfirmDelete from "~/components/Modals/ConfirmDelete";import { usePermissions, useRouteData } from "~/hooks";-import type {- ItemTracking,- StockTransfer,- StockTransferLine,-} from "~/modules/inventory";+import type { StockTransfer, StockTransferLine } from "~/modules/inventory";import type { Result } from "@carbon/auth";import Assignee, { useOptimisticAssignment } from "~/components/Assignee";@@ -41,7 +37,6 @@ const StockTransferHeader = () => {const routeData = useRouteData<{stockTransfer: StockTransfer;stockTransferLines: StockTransferLine[];- stockTransferLineTracking: ItemTracking[];}>(path.to.stockTransfer(id));if (!routeData?.stockTransfer)diff --git a/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferLines.tsx b/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferLines.tsxindex d716bd0bae..f48545b834 100644--- a/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferLines.tsx+++ b/apps/erp/app/modules/inventory/ui/StockTransfers/StockTransferLines.tsx@@ -42,7 +42,6 @@ import { usePermissions, useRouteData } from "~/hooks";import type { StockTransfer, StockTransferLine } from "~/modules/inventory";import { useItems } from "~/stores";import { path } from "~/utils/path";-import type { TrackedEntityAttributes } from "../../../../../../../packages/utils/src/types";interface StockTransferLineProps {line: StockTransferLine;@@ -104,6 +103,11 @@ function StockTransferLineComponent({<span className="text-xs text-muted-foreground truncate block w-full">{item?.readableIdWithRevision}</span>+ {line.trackedEntityId && (+ <span className="flex gap-1 text-xs text-muted-foreground truncate items-center w-full">+ <LuQrCode /> {line.trackedEntityId}+ </span>+ )}</div><div className="mt-2"><Enumerable@@ -224,24 +228,8 @@ export default function StockTransferLines() {const routeData = useRouteData<{stockTransfer: StockTransfer;stockTransferLines: StockTransferLine[];- stockTransferLineTracking: {- attributes: TrackedEntityAttributes;- trackedActivityInput: { trackedEntityId: string }[];- }[];}>(path.to.stockTransfer(id));- const trackedEntitiesByLineId = new Map<string, string>();- routeData?.stockTransferLineTracking.forEach((trackedEntity) => {- const attributes = trackedEntity.attributes as TrackedEntityAttributes;- const stockTransferLineId = attributes["Stock Transfer Line"];- if (stockTransferLineId) {- trackedEntitiesByLineId.set(- stockTransferLineId,- trackedEntity.trackedActivityInput.at(0)?.trackedEntityId ?? ""- );- }- });-const isPickable = ["Released", "In Progress"].includes(routeData?.stockTransfer?.status ?? "");@@ -295,9 +283,8 @@ export default function StockTransferLines() {formData.append("quantity", line.quantity!.toString());formData.append("locationId", routeData?.stockTransfer?.locationId ?? "");- const trackedEntityId = trackedEntitiesByLineId.get(line.id ?? "");- if (trackedEntityId) {- formData.append("trackedEntityId", trackedEntityId);+ if (line.trackedEntityId) {+ formData.append("trackedEntityId", line.trackedEntityId);}submit(formData, {@@ -313,9 +300,8 @@ export default function StockTransferLines() {formData.append("id", line.id!);formData.append("quantity", "0");formData.append("locationId", routeData?.stockTransfer?.locationId ?? "");- const trackedEntityId = trackedEntitiesByLineId.get(line.id ?? "");- if (trackedEntityId) {- formData.append("trackedEntityId", trackedEntityId);+ if (line.trackedEntityId) {+ formData.append("trackedEntityId", line.trackedEntityId);}submit(formData, {diff --git a/apps/erp/app/routes/api+/stock-transfer+/$lineId+/pick.tsx b/apps/erp/app/routes/api+/stock-transfer+/$lineId+/pick.tsxdeleted file mode 100644index f16bcb729a..0000000000--- a/apps/erp/app/routes/api+/stock-transfer+/$lineId+/pick.tsx+++ /dev/null@@ -1,30 +0,0 @@-import { assertIsPost, notFound, success } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { ActionFunctionArgs } from "@vercel/remix";-import { json } from "@vercel/remix";--export async function action({ request, params }: ActionFunctionArgs) {- assertIsPost(request);- const { client, companyId, userId } = await requirePermissions(request, {- update: "inventory",- });-- const { lineId } = params;- if (!lineId) throw notFound("lineId not found");-- // TODO: Implement pick functionality- // This would typically:- // 1. Get the stock transfer line- // 2. Update the pickedQuantity- // 3. Create inventory transactions- // 4. Update stock transfer status if needed-- return json(- {- success: true,- message: "Pick functionality not yet implemented",- },- await flash(request, success("Pick operation completed"))- );-}diff --git a/apps/erp/app/routes/api+/stock-transfer+/$lineId+/unpick.tsx b/apps/erp/app/routes/api+/stock-transfer+/$lineId+/unpick.tsxdeleted file mode 100644index 350fd2dc56..0000000000--- a/apps/erp/app/routes/api+/stock-transfer+/$lineId+/unpick.tsx+++ /dev/null@@ -1,30 +0,0 @@-import { assertIsPost, notFound, success } from "@carbon/auth";-import { requirePermissions } from "@carbon/auth/auth.server";-import { flash } from "@carbon/auth/session.server";-import type { ActionFunctionArgs } from "@vercel/remix";-import { json } from "@vercel/remix";--export async function action({ request, params }: ActionFunctionArgs) {- assertIsPost(request);- const { client, companyId, userId } = await requirePermissions(request, {- update: "inventory",- });-- const { lineId } = params;- if (!lineId) throw notFound("lineId not found");-- // TODO: Implement unpick functionality- // This would typically:- // 1. Get the stock transfer line- // 2. Decrease the pickedQuantity- // 3. Reverse inventory transactions- // 4. Update stock transfer status if needed-- return json(- {- success: true,- message: "Unpick functionality not yet implemented",- },- await flash(request, success("Unpick operation completed"))- );-}diff --git a/apps/erp/app/routes/api+/stock-transfer.$id.$lineId.pick.tsx b/apps/erp/app/routes/api+/stock-transfer.$id.$lineId.pick.tsxnew file mode 100644index 0000000000..e5dc3456a2--- /dev/null+++ b/apps/erp/app/routes/api+/stock-transfer.$id.$lineId.pick.tsx@@ -0,0 +1,98 @@+import { error, notFound, success } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import type { ActionFunctionArgs } from "@vercel/remix";+import { redirect } from "@vercel/remix";+import { path } from "~/utils/path";++export async function loader({ request, params }: ActionFunctionArgs) {+ const { client } = await requirePermissions(request, {+ update: "inventory",+ });++ const url = new URL(request.url);+ const type = url.searchParams.get("type");++ const { id, lineId } = params;+ if (!id) throw notFound("id not found");+ if (!lineId) throw notFound("lineId not found");++ if (type && ["serial", "batch"].includes(type)) {+ throw redirect(path.to.stockTransferScan(id, lineId));+ }++ const updateQuantityUrl = new URL(+ `${url.origin}${path.to.stockTransferLineQuantity(lineId)}`+ );++ const [stockTransferLine, stockTransfer] = await Promise.all([+ client.from("stockTransferLine").select("*").eq("id", lineId).single(),+ client.from("stockTransfer").select("*").eq("id", id).single(),+ ]);++ if (stockTransferLine.error || stockTransfer.error) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(+ request,+ error(+ stockTransferLine.error || stockTransfer.error,+ "Failed to load stock transfer line or stock transfer"+ )+ )+ );+ }++ if (!["In Progress", "Released"].includes(stockTransfer.data?.status ?? "")) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(+ request,+ error(+ "Stock transfer is not in progress or released",+ "Stock transfer is not in progress or released"+ )+ )+ );+ }++ if (stockTransferLine.data?.pickedQuantity > 0) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(request, error("Line already picked", "Line already picked"))+ );+ }++ const formData = new FormData();+ formData.append("id", lineId);+ formData.append(+ "quantity",+ stockTransferLine.data?.quantity?.toString() ?? "1"+ );+ formData.append("locationId", stockTransfer.data?.locationId ?? "");++ const result = await fetch(updateQuantityUrl.toString(), {+ method: "POST",+ headers: {+ ...Object.fromEntries(request.headers.entries()),+ },+ body: formData,+ });++ const { data } = await result.json();++ if (data?.success) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(request, success(data?.message))+ );+ }++ throw redirect(+ path.to.stockTransfer(id),+ await flash(+ request,+ error(data?.message, data?.message ?? "Failed to pick line")+ )+ );+}diff --git a/apps/erp/app/routes/api+/stock-transfer.$id.$lineId.unpick.tsx b/apps/erp/app/routes/api+/stock-transfer.$id.$lineId.unpick.tsxnew file mode 100644index 0000000000..8702a7a052--- /dev/null+++ b/apps/erp/app/routes/api+/stock-transfer.$id.$lineId.unpick.tsx@@ -0,0 +1,100 @@+import { error, notFound, success } from "@carbon/auth";+import { requirePermissions } from "@carbon/auth/auth.server";+import { flash } from "@carbon/auth/session.server";+import type { ActionFunctionArgs } from "@vercel/remix";+import { redirect } from "@vercel/remix";+import { path } from "~/utils/path";++export async function loader({ request, params }: ActionFunctionArgs) {+ const { client } = await requirePermissions(request, {+ update: "inventory",+ });++ const url = new URL(request.url);+ const type = url.searchParams.get("type");++ const { id, lineId } = params;+ if (!id) throw notFound("id not found");+ if (!lineId) throw notFound("lineId not found");++ const updateQuantityUrl = new URL(+ `${url.origin}${path.to.stockTransferLineQuantity(lineId)}`+ );++ const [stockTransferLine, stockTransfer] = await Promise.all([+ client.from("stockTransferLine").select("*").eq("id", lineId).single(),+ client.from("stockTransfer").select("*").eq("id", id).single(),+ ]);++ if (stockTransferLine.error || stockTransfer.error) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(+ request,+ error(+ stockTransferLine.error || stockTransfer.error,+ "Failed to load stock transfer line or stock transfer"+ )+ )+ );+ }++ if (!["In Progress", "Released"].includes(stockTransfer.data?.status ?? "")) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(+ request,+ error(+ "Stock transfer is not in progress or released",+ "Stock transfer is not in progress or released"+ )+ )+ );+ }++ if (stockTransferLine.data?.pickedQuantity > 0) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(request, error("Line already picked", "Line already picked"))+ );+ }++ const formData = new FormData();+ formData.append("id", lineId);+ formData.append("quantity", "0");+ formData.append("locationId", stockTransfer.data?.locationId ?? "");+ if (+ stockTransferLine.data?.requiresSerialTracking ||+ stockTransferLine.data?.requiresBatchTracking+ ) {+ formData.append(+ "trackedEntityId",+ stockTransferLine.data?.trackedEntityId ?? ""+ );+ }++ const result = await fetch(updateQuantityUrl.toString(), {+ method: "POST",+ headers: {+ ...Object.fromEntries(request.headers.entries()),+ },+ body: formData,+ });++ const { data } = await result.json();++ if (data?.success) {+ throw redirect(+ path.to.stockTransfer(id),+ await flash(request, success(data?.message))+ );+ }++ throw redirect(+ path.to.stockTransfer(id),+ await flash(+ request,+ error(data?.message, data?.message ?? "Failed to unpick line")+ )+ );+}diff --git a/apps/erp/app/routes/x+/stock-transfer+/$id.scan.$lineId.tsx b/apps/erp/app/routes/x+/stock-transfer+/$id.scan.$lineId.tsxindex a3da1168a9..1eafbb8860 100644--- a/apps/erp/app/routes/x+/stock-transfer+/$id.scan.$lineId.tsx+++ b/apps/erp/app/routes/x+/stock-transfer+/$id.scan.$lineId.tsx@@ -20,8 +20,8 @@ import {ModalTitle,toast,} from "@carbon/react";-import { useFetcher, useLoaderData, useNavigate } from "@remix-run/react";-import type { ActionFunctionArgs, LoaderFunctionArgs } from "@vercel/remix";+import { useFetcher, useNavigate, useParams } from "@remix-run/react";+import type { ActionFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";import { useEffect, useState } from "react";import {@@ -32,36 +32,11 @@ import {LuX,} from "react-icons/lu";import { useRouteData } from "~/hooks";-import type { StockTransfer } from "~/modules/inventory";-import {- getStockTransferLine,- stockTransferLineScanValidator,-} from "~/modules/inventory";+import type { StockTransfer, StockTransferLine } from "~/modules/inventory";+import { stockTransferLineScanValidator } from "~/modules/inventory";import { getItemShelfQuantities } from "~/modules/items";import { path } from "~/utils/path";-export async function loader({ request, params }: LoaderFunctionArgs) {- const { client } = await requirePermissions(request, {- view: "inventory",- });- const { id, lineId } = params;- if (!id) throw new Error("id not found");- if (!lineId) throw new Error("lineId not found");-- const stockTransferLine = await getStockTransferLine(client, lineId);- if (stockTransferLine.error) {- throw redirect(- path.to.stockTransfer(id),- await flash(- request,- error(stockTransferLine.error, "Failed to load stock transfer line")- )- );- }-- return json({ stockTransferLine: stockTransferLine.data });-}-export async function action({ request }: ActionFunctionArgs) {const { client, companyId, userId } = await requirePermissions(request, {update: "inventory",@@ -151,7 +126,20 @@ export async function action({ request }: ActionFunctionArgs) {}export default function StockTransferScan() {- const { stockTransferLine } = useLoaderData<typeof loader>();+ const { id, lineId } = useParams();+ if (!id) throw new Error("id not found");+ if (!lineId) throw new Error("lineId not found");+ const routeData = useRouteData<{+ stockTransfer: StockTransfer;+ stockTransferLines: StockTransferLine[];+ }>(path.to.stockTransfer(id));++ const stockTransferLine = routeData?.stockTransferLines.find(+ (line) => line.id === lineId+ );++ if (!stockTransferLine) throw new Error("stock transfer line not found");+const navigate = useNavigate();const onClose = () =>navigate(path.to.stockTransfer(stockTransferLine.stockTransferId!));@@ -199,6 +187,16 @@ export default function StockTransferScan() {return;}+ if (+ routeData?.stockTransferLines.some(+ (line) => line.trackedEntityId === trackedEntityId+ )+ ) {+ setValidationError("Tracked entity already picked");+ setIsValid(false);+ return;+ }+setIsLoading(true);setValidationError(null);setIsValid(null);diff --git a/apps/erp/app/routes/x+/stock-transfer+/$id.tsx b/apps/erp/app/routes/x+/stock-transfer+/$id.tsxindex a056fd3233..2a9605ef4b 100644--- a/apps/erp/app/routes/x+/stock-transfer+/$id.tsx+++ b/apps/erp/app/routes/x+/stock-transfer+/$id.tsx@@ -7,11 +7,7 @@ import { Outlet, useLoaderData, useParams } from "@remix-run/react";import type { LoaderFunctionArgs } from "@vercel/remix";import { json, redirect } from "@vercel/remix";import { PanelProvider } from "~/components/Layout";-import {- getStockTransfer,- getStockTransferLines,- getStockTransferTracking,-} from "~/modules/inventory";+import { getStockTransfer, getStockTransferLines } from "~/modules/inventory";import StockTransferHeader from "~/modules/inventory/ui/StockTransfers/StockTransferHeader";import StockTransferLines from "~/modules/inventory/ui/StockTransfers/StockTransferLines";import StockTransferNotes from "~/modules/inventory/ui/StockTransfers/StockTransferNotes";@@ -31,12 +27,10 @@ export async function loader({ request, params }: LoaderFunctionArgs) {const { id } = params;if (!id) throw new Error("Could not find id");- const [stockTransfer, stockTransferLines, stockTransferLineTracking] =- await Promise.all([- getStockTransfer(client, id),- getStockTransferLines(client, id),- getStockTransferTracking(client, id, companyId),- ]);+ const [stockTransfer, stockTransferLines] = await Promise.all([+ getStockTransfer(client, id),+ getStockTransferLines(client, id),+ ]);if (stockTransfer.error) {throw redirect(@@ -55,7 +49,6 @@ export async function loader({ request, params }: LoaderFunctionArgs) {return json({stockTransfer: stockTransfer.data,stockTransferLines: stockTransferLines.data ?? [],- stockTransferLineTracking: stockTransferLineTracking.data ?? [],});}diff --git a/packages/database/src/types.ts b/packages/database/src/types.tsindex e291a0d433..67101deb28 100644--- a/packages/database/src/types.ts+++ b/packages/database/src/types.ts@@ -31022,6 +31022,7 @@ export type Database = {requiresSerialTracking: booleanstockTransferId: stringtoShelfId: string | null+ trackedEntityId: string | nullupdatedAt: string | nullupdatedBy: string | null}@@ -31041,6 +31042,7 @@ export type Database = {requiresSerialTracking?: booleanstockTransferId: stringtoShelfId?: string | null+ trackedEntityId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null}@@ -31060,6 +31062,7 @@ export type Database = {requiresSerialTracking?: booleanstockTransferId?: stringtoShelfId?: string | null+ trackedEntityId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null}@@ -31225,6 +31228,13 @@ export type Database = {referencedRelation: "shelf"referencedColumns: ["id"]},+ {+ foreignKeyName: "stockTransferLine_trackedEntityId_fkey"+ columns: ["trackedEntityId"]+ isOneToOne: false+ referencedRelation: "trackedEntity"+ referencedColumns: ["id"]+ },{foreignKeyName: "stockTransferLine_updatedBy_fkey"columns: ["updatedBy"]@@ -45968,14 +45978,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -47064,6 +47074,7 @@ export type Database = {thumbnailPath: string | nulltoShelfId: string | nulltoShelfName: string | null+ trackedEntityId: string | nullunitOfMeasure: string | nullupdatedAt: string | nullupdatedBy: string | null@@ -47230,6 +47241,13 @@ export type Database = {referencedRelation: "shelf"referencedColumns: ["id"]},+ {+ foreignKeyName: "stockTransferLine_trackedEntityId_fkey"+ columns: ["trackedEntityId"]+ isOneToOne: false+ referencedRelation: "trackedEntity"+ referencedColumns: ["id"]+ },{foreignKeyName: "stockTransferLine_updatedBy_fkey"columns: ["updatedBy"]diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.tsindex e291a0d433..67101deb28 100644--- a/packages/database/supabase/functions/lib/types.ts+++ b/packages/database/supabase/functions/lib/types.ts@@ -31022,6 +31022,7 @@ export type Database = {requiresSerialTracking: booleanstockTransferId: stringtoShelfId: string | null+ trackedEntityId: string | nullupdatedAt: string | nullupdatedBy: string | null}@@ -31041,6 +31042,7 @@ export type Database = {requiresSerialTracking?: booleanstockTransferId: stringtoShelfId?: string | null+ trackedEntityId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null}@@ -31060,6 +31062,7 @@ export type Database = {requiresSerialTracking?: booleanstockTransferId?: stringtoShelfId?: string | null+ trackedEntityId?: string | nullupdatedAt?: string | nullupdatedBy?: string | null}@@ -31225,6 +31228,13 @@ export type Database = {referencedRelation: "shelf"referencedColumns: ["id"]},+ {+ foreignKeyName: "stockTransferLine_trackedEntityId_fkey"+ columns: ["trackedEntityId"]+ isOneToOne: false+ referencedRelation: "trackedEntity"+ referencedColumns: ["id"]+ },{foreignKeyName: "stockTransferLine_updatedBy_fkey"columns: ["updatedBy"]@@ -45968,14 +45978,14 @@ export type Database = {Relationships: [{foreignKeyName: "address_countryCode_fkey"- columns: ["paymentCountryCode"]+ columns: ["customerCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]},{foreignKeyName: "address_countryCode_fkey"- columns: ["customerCountryCode"]+ columns: ["paymentCountryCode"]isOneToOne: falsereferencedRelation: "country"referencedColumns: ["alpha2"]@@ -47064,6 +47074,7 @@ export type Database = {thumbnailPath: string | nulltoShelfId: string | nulltoShelfName: string | null+ trackedEntityId: string | nullunitOfMeasure: string | nullupdatedAt: string | nullupdatedBy: string | null@@ -47230,6 +47241,13 @@ export type Database = {referencedRelation: "shelf"referencedColumns: ["id"]},+ {+ foreignKeyName: "stockTransferLine_trackedEntityId_fkey"+ columns: ["trackedEntityId"]+ isOneToOne: false+ referencedRelation: "trackedEntity"+ referencedColumns: ["id"]+ },{foreignKeyName: "stockTransferLine_updatedBy_fkey"columns: ["updatedBy"]diff --git a/packages/database/supabase/functions/post-stock-transfer/index.ts b/packages/database/supabase/functions/post-stock-transfer/index.tsindex 505271e086..db1da9d6a5 100644--- a/packages/database/supabase/functions/post-stock-transfer/index.ts+++ b/packages/database/supabase/functions/post-stock-transfer/index.ts@@ -223,6 +223,7 @@ serve(async (req: Request) => {await trx.updateTable("stockTransferLine").set({+ trackedEntityId: null,pickedQuantity: 0,updatedBy: userId,updatedAt: new Date().toISOString(),@@ -333,6 +334,7 @@ serve(async (req: Request) => {await trx.updateTable("stockTransferLine").set({+ trackedEntityId,fromShelfId: fromShelfId,pickedQuantity: (stockTransferLine.pickedQuantity ?? 0) + 1,updatedBy: userId,@@ -598,6 +600,7 @@ serve(async (req: Request) => {await trx.updateTable("stockTransferLine").set({+ trackedEntityId,fromShelfId: fromShelfId,pickedQuantity: transferQuantity,updatedBy: userId,@@ -724,6 +727,7 @@ serve(async (req: Request) => {await trx.updateTable("stockTransferLine").set({+ trackedEntityId: null,pickedQuantity: Math.max(0,(stockTransferLine.pickedQuantity ?? 0) - 1@@ -968,6 +972,7 @@ serve(async (req: Request) => {await trx.updateTable("stockTransferLine").set({+ trackedEntityId: null,pickedQuantity: Math.max(0,(stockTransferLine.pickedQuantity ?? 0) - transferQuantitydiff --git a/packages/database/supabase/migrations/20251007014240_stock-transfers.sql b/packages/database/supabase/migrations/20251007014240_stock-transfers.sqlindex e095a83c2b..73b39b4830 100644--- a/packages/database/supabase/migrations/20251007014240_stock-transfers.sql+++ b/packages/database/supabase/migrations/20251007014240_stock-transfers.sql@@ -152,6 +152,7 @@ CREATE TABLE "stockTransferLine" ("quantity" NUMERIC NOT NULL DEFAULT 0,"pickedQuantity" NUMERIC NOT NULL DEFAULT 0,"outstandingQuantity" NUMERIC GENERATED ALWAYS AS (CASE WHEN "quantity" >= "pickedQuantity" THEN "quantity" - "pickedQuantity" ELSE 0 END) STORED,+ "trackedEntityId" TEXT,"requiresBatchTracking" BOOLEAN NOT NULL DEFAULT false,"requiresSerialTracking" BOOLEAN NOT NULL DEFAULT false,"companyId" TEXT NOT NULL,@@ -167,11 +168,14 @@ CREATE TABLE "stockTransferLine" (CONSTRAINT "stockTransferLine_itemId_fkey" FOREIGN KEY ("itemId") REFERENCES "item" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "stockTransferLine_fromShelfId_fkey" FOREIGN KEY ("fromShelfId") REFERENCES "shelf" ("id") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "stockTransferLine_toShelfId_fkey" FOREIGN KEY ("toShelfId") REFERENCES "shelf" ("id") ON DELETE SET NULL ON UPDATE CASCADE,+ CONSTRAINT "stockTransferLine_trackedEntityId_fkey" FOREIGN KEY ("trackedEntityId") REFERENCES "trackedEntity" ("id") ON DELETE SET NULL ON UPDATE CASCADE,CONSTRAINT "stockTransferLine_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "company" ("id") ON DELETE CASCADE ON UPDATE CASCADE,CONSTRAINT "stockTransferLine_createdBy_fkey" FOREIGN KEY ("createdBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,CONSTRAINT "stockTransferLine_updatedBy_fkey" FOREIGN KEY ("updatedBy") REFERENCES "user" ("id") ON DELETE RESTRICT ON UPDATE CASCADE);++CREATE INDEX "stockTransferLine_stockTransferId_idx" ON "stockTransferLine" ("stockTransferId");CREATE INDEX "stockTransferLine_jobId_idx" ON "stockTransferLine" ("jobId");CREATE INDEX "stockTransferLine_itemId_idx" ON "stockTransferLine" ("itemId");diff --git a/packages/documents/src/pdf/StockTransferPDF.tsx b/packages/documents/src/pdf/StockTransferPDF.tsxindex 8a226a6590..95164b0f4c 100644--- a/packages/documents/src/pdf/StockTransferPDF.tsx+++ b/packages/documents/src/pdf/StockTransferPDF.tsx@@ -99,9 +99,12 @@ const StockTransferPDF = ({}).map((line) => {const barcodeDataUrl = generateBarcode(line.itemReadableId);- const pickUrl = `${getAppUrl()}/api/stock-transfer/${- line.id- }/pick`;+ let pickUrl = `${getAppUrl()}/api/stock-transfer/${line.id}/pick`;+ if (line.requiresSerialTracking) {+ pickUrl += "?type=serial";+ } else if (line.requiresBatchTracking) {+ pickUrl += "?type=batch";+ }const pickQRCode = generateQRCode(pickUrl, 4);return (