Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

fix: don't complete job on operation completion if job is not released

Brad Barbin841b5ef72f9d
diff --git a/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsx b/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsx
index d05d327475..987ae7c024 100644
--- a/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsx
+++ b/apps/erp/app/modules/production/ui/Jobs/JobOperationStatus.tsx
@@ -9,7 +9,7 @@ import {
DropdownMenuTrigger,
IconButton
} from "@carbon/react";
-import { useCallback } from "react";
+import { useCallback, useMemo } from "react";
import { useFetchers, useParams, useSubmit } from "react-router";
import { z } from "zod/v3";
import { Tags } from "~/components/Form";
@@ -20,6 +20,8 @@ import { path } from "~/utils/path";
import { jobOperationStatus } from "../../production.models";
import type { Job, JobOperation } from "../../types";
+const releasedJobStatuses = ["Ready", "In Progress", "Paused"] as const;
+
function useOptimisticJobStatus(operationId: string) {
const fetchers = useFetchers();
const pendingUpdate = fetchers.find(
@@ -51,6 +53,18 @@ export function JobOperationStatus({
const permissions = usePermissions();
const optimisticStatus = useOptimisticJobStatus(operation.id!);
+ // Only allow "Done" status if job has been released (scheduled)
+ const isJobReleased = releasedJobStatuses.includes(
+ routeData?.job?.status as (typeof releasedJobStatuses)[number]
+ );
+ const availableStatuses = useMemo(
+ () =>
+ isJobReleased
+ ? jobOperationStatus
+ : jobOperationStatus.filter((s) => s !== "Done"),
+ [isJobReleased]
+ );
+
const isDisabled = !permissions.can("update", "production");
const onOperationStatusChange = useCallback(
@@ -98,7 +112,7 @@ export function JobOperationStatus({
)
}
>
- {jobOperationStatus.map((status) => (
+ {availableStatuses.map((status) => (
<DropdownMenuRadioItem key={status} value={status}>
<DropdownMenuIcon
icon={<OperationStatusIcon status={status} />}
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 8e2e94ce03..f74d87589d 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -16689,6 +16689,177 @@ export default {
tags: ["jobOperationTool"],
},
},
+ "/suggestion": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.suggestion.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.suggestion",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.emoji",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.path",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.attachmentPath",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.tags",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.userId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.createdAt",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/suggestion",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["suggestion"],
+ },
+ post: {
+ parameters: [
+ {
+ $ref: "#/parameters/body.suggestion",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/preferPost",
+ },
+ ],
+ responses: {
+ "201": {
+ description: "Created",
+ },
+ },
+ tags: ["suggestion"],
+ },
+ delete: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.suggestion.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.suggestion",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.emoji",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.path",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.attachmentPath",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.tags",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.userId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.createdAt",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["suggestion"],
+ },
+ patch: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.suggestion.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.suggestion",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.emoji",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.path",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.attachmentPath",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.tags",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.userId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestion.createdAt",
+ },
+ {
+ $ref: "#/parameters/body.suggestion",
+ },
+ {
+ $ref: "#/parameters/preferReturn",
+ },
+ ],
+ responses: {
+ "204": {
+ description: "No Content",
+ },
+ },
+ tags: ["suggestion"],
+ },
+ },
"/demandActual": {
get: {
parameters: [
@@ -34536,6 +34707,9 @@ export default {
{
$ref: "#/parameters/rowFilter.userAttributeValue.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.userAttributeValue.valueFile",
+ },
{
$ref: "#/parameters/select",
},
@@ -34631,6 +34805,9 @@ export default {
{
$ref: "#/parameters/rowFilter.userAttributeValue.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.userAttributeValue.valueFile",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -34680,6 +34857,9 @@ export default {
{
$ref: "#/parameters/rowFilter.userAttributeValue.updatedBy",
},
+ {
+ $ref: "#/parameters/rowFilter.userAttributeValue.valueFile",
+ },
{
$ref: "#/parameters/body.userAttributeValue",
},
@@ -40836,6 +41016,9 @@ export default {
{
$ref: "#/parameters/rowFilter.attributeDataType.isSupplier",
},
+ {
+ $ref: "#/parameters/rowFilter.attributeDataType.isFile",
+ },
{
$ref: "#/parameters/select",
},
@@ -40925,6 +41108,9 @@ export default {
{
$ref: "#/parameters/rowFilter.attributeDataType.isSupplier",
},
+ {
+ $ref: "#/parameters/rowFilter.attributeDataType.isFile",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -40968,6 +41154,9 @@ export default {
{
$ref: "#/parameters/rowFilter.attributeDataType.isSupplier",
},
+ {
+ $ref: "#/parameters/rowFilter.attributeDataType.isFile",
+ },
{
$ref: "#/parameters/body.attributeDataType",
},
@@ -44232,6 +44421,9 @@ export default {
{
$ref: "#/parameters/rowFilter.company.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.company.suggestionNotificationGroup",
+ },
{
$ref: "#/parameters/select",
},
@@ -44360,6 +44552,9 @@ export default {
{
$ref: "#/parameters/rowFilter.company.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.company.suggestionNotificationGroup",
+ },
{
$ref: "#/parameters/preferReturn",
},
@@ -44442,6 +44637,9 @@ export default {
{
$ref: "#/parameters/rowFilter.company.createdAt",
},
+ {
+ $ref: "#/parameters/rowFilter.company.suggestionNotificationGroup",
+ },
{
$ref: "#/parameters/body.company",
},
@@ -55125,6 +55323,81 @@ export default {
tags: ["opportunity"],
},
},
+ "/suggestions": {
+ get: {
+ parameters: [
+ {
+ $ref: "#/parameters/rowFilter.suggestions.id",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.suggestion",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.emoji",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.path",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.attachmentPath",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.tags",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.userId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.companyId",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.createdAt",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.employeeName",
+ },
+ {
+ $ref: "#/parameters/rowFilter.suggestions.employeeAvatarUrl",
+ },
+ {
+ $ref: "#/parameters/select",
+ },
+ {
+ $ref: "#/parameters/order",
+ },
+ {
+ $ref: "#/parameters/range",
+ },
+ {
+ $ref: "#/parameters/rangeUnit",
+ },
+ {
+ $ref: "#/parameters/offset",
+ },
+ {
+ $ref: "#/parameters/limit",
+ },
+ {
+ $ref: "#/parameters/preferCount",
+ },
+ ],
+ responses: {
+ "200": {
+ description: "OK",
+ schema: {
+ items: {
+ $ref: "#/definitions/suggestions",
+ },
+ type: "array",
+ },
+ },
+ "206": {
+ description: "Partial Content",
+ },
+ },
+ tags: ["suggestions"],
+ },
+ },
"/customField": {
get: {
parameters: [
@@ -69489,6 +69762,59 @@ export default {
},
type: "object",
},
+ suggestion: {
+ required: ["id", "suggestion", "emoji", "path", "companyId", "createdAt"],
+ properties: {
+ id: {
+ default: "public.id()",
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ suggestion: {
+ format: "text",
+ type: "string",
+ },
+ emoji: {
+ default: "💡",
+ format: "text",
+ type: "string",
+ },
+ path: {
+ format: "text",
+ type: "string",
+ },
+ attachmentPath: {
+ format: "text",
+ type: "string",
+ },
+ tags: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ userId: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ createdAt: {
+ default: "now()",
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
demandActual: {
required: [
"itemId",
@@ -77659,6 +77985,10 @@ export default {
format: "text",
type: "string",
},
+ valueFile: {
+ format: "text",
+ type: "string",
+ },
},
type: "object",
},
@@ -80752,6 +81082,7 @@ export default {
"isUser",
"isCustomer",
"isSupplier",
+ "isFile",
],
properties: {
id: {
@@ -80803,6 +81134,11 @@ export default {
format: "boolean",
type: "boolean",
},
+ isFile: {
+ default: false,
+ format: "boolean",
+ type: "boolean",
+ },
},
type: "object",
},
@@ -82417,7 +82753,13 @@ export default {
type: "object",
},
company: {
- required: ["id", "name", "baseCurrencyCode", "createdAt"],
+ required: [
+ "id",
+ "name",
+ "baseCurrencyCode",
+ "createdAt",
+ "suggestionNotificationGroup",
+ ],
properties: {
id: {
default: "public.id()",
@@ -82517,6 +82859,13 @@ export default {
format: "timestamp with time zone",
type: "string",
},
+ suggestionNotificationGroup: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
},
type: "object",
},
@@ -87681,6 +88030,63 @@ export default {
},
type: "object",
},
+ suggestions: {
+ properties: {
+ id: {
+ description: "Note:\nThis is a Primary Key.<pk/>",
+ format: "text",
+ type: "string",
+ },
+ suggestion: {
+ format: "text",
+ type: "string",
+ },
+ emoji: {
+ format: "text",
+ type: "string",
+ },
+ path: {
+ format: "text",
+ type: "string",
+ },
+ attachmentPath: {
+ format: "text",
+ type: "string",
+ },
+ tags: {
+ format: "text[]",
+ items: {
+ type: "string",
+ },
+ type: "array",
+ },
+ userId: {
+ description:
+ "Note:\nThis is a Foreign Key to `user.id`.<fk table='user' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ companyId: {
+ description:
+ "Note:\nThis is a Foreign Key to `company.id`.<fk table='company' column='id'/>",
+ format: "text",
+ type: "string",
+ },
+ createdAt: {
+ format: "timestamp with time zone",
+ type: "string",
+ },
+ employeeName: {
+ format: "text",
+ type: "string",
+ },
+ employeeAvatarUrl: {
+ format: "text",
+ type: "string",
+ },
+ },
+ type: "object",
+ },
customField: {
required: [
"id",
@@ -97738,6 +98144,69 @@ export default {
in: "query",
type: "string",
},
+ "body.suggestion": {
+ name: "suggestion",
+ description: "suggestion",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/suggestion",
+ },
+ },
+ "rowFilter.suggestion.id": {
+ name: "id",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.suggestion": {
+ name: "suggestion",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.emoji": {
+ name: "emoji",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.path": {
+ name: "path",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.attachmentPath": {
+ name: "attachmentPath",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.tags": {
+ name: "tags",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.userId": {
+ name: "userId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.companyId": {
+ name: "companyId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestion.createdAt": {
+ name: "createdAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.demandActual": {
name: "demandActual",
description: "demandActual",
@@ -106969,6 +107438,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.userAttributeValue.valueFile": {
+ name: "valueFile",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.fiscalYearSettings": {
name: "fiscalYearSettings",
description: "fiscalYearSettings",
@@ -110635,6 +111110,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.attributeDataType.isFile": {
+ name: "isFile",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.qualityDocuments": {
name: "qualityDocuments",
description: "qualityDocuments",
@@ -112513,6 +112994,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.company.suggestionNotificationGroup": {
+ name: "suggestionNotificationGroup",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.salesOrderLocations": {
name: "salesOrderLocations",
description: "salesOrderLocations",
@@ -118267,6 +118754,81 @@ export default {
in: "query",
type: "string",
},
+ "body.suggestions": {
+ name: "suggestions",
+ description: "suggestions",
+ required: false,
+ in: "body",
+ schema: {
+ $ref: "#/definitions/suggestions",
+ },
+ },
+ "rowFilter.suggestions.id": {
+ name: "id",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.suggestion": {
+ name: "suggestion",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.emoji": {
+ name: "emoji",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.path": {
+ name: "path",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.attachmentPath": {
+ name: "attachmentPath",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.tags": {
+ name: "tags",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.userId": {
+ name: "userId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.companyId": {
+ name: "companyId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.createdAt": {
+ name: "createdAt",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.employeeName": {
+ name: "employeeName",
+ required: false,
+ in: "query",
+ type: "string",
+ },
+ "rowFilter.suggestions.employeeAvatarUrl": {
+ name: "employeeAvatarUrl",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"body.customField": {
name: "customField",
description: "customField",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index 0521ffd9ac..f4440c4ad8 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -38589,7 +38589,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"] | null
description: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -38776,13 +38775,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
]
}
contractors: {
@@ -41839,7 +41831,6 @@ export type Database = {
finish: string | null
grade: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -42031,13 +42022,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "material_materialFormId_fkey"
columns: ["materialFormId"]
@@ -42678,14 +42662,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -42738,7 +42722,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"] | null
description: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -42903,13 +42886,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
]
}
procedures: {
@@ -46578,14 +46554,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["invoiceCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["invoiceCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -47121,14 +47097,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -49333,7 +49309,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"] | null
description: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -49498,13 +49473,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
]
}
trainings: {
@@ -49975,7 +49943,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"]
description: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
modelName: string
modelPath: string
@@ -50373,7 +50340,6 @@ export type Database = {
grade: string
gradeId: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
materialForm: string
materialFormId: string
@@ -50488,7 +50454,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"]
description: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
modelId: string
modelName: string
@@ -50945,7 +50910,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"]
description: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
modelId: string
modelName: string
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index 0521ffd9ac..f4440c4ad8 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -38589,7 +38589,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"] | null
description: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -38776,13 +38775,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
]
}
contractors: {
@@ -41839,7 +41831,6 @@ export type Database = {
finish: string | null
grade: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -42031,13 +42022,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
{
foreignKeyName: "material_materialFormId_fkey"
columns: ["materialFormId"]
@@ -42678,14 +42662,14 @@ export type Database = {
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["id"]
+ columns: ["supplierLocationId"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
},
{
foreignKeyName: "partner_id_fkey"
- columns: ["supplierLocationId"]
+ columns: ["id"]
isOneToOne: false
referencedRelation: "supplierLocation"
referencedColumns: ["id"]
@@ -42738,7 +42722,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"] | null
description: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -42903,13 +42886,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
]
}
procedures: {
@@ -46578,14 +46554,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["invoiceCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["invoiceCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -47121,14 +47097,14 @@ export type Database = {
Relationships: [
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["customerCountryCode"]
+ columns: ["paymentCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
},
{
foreignKeyName: "address_countryCode_fkey"
- columns: ["paymentCountryCode"]
+ columns: ["customerCountryCode"]
isOneToOne: false
referencedRelation: "country"
referencedColumns: ["alpha2"]
@@ -49333,7 +49309,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"] | null
description: string | null
id: string | null
- itemPostingGroupId: string | null
itemTrackingType:
| Database["public"]["Enums"]["itemTrackingType"]
| null
@@ -49498,13 +49473,6 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
- {
- foreignKeyName: "itemCost_itemPostingGroupId_fkey"
- columns: ["itemPostingGroupId"]
- isOneToOne: false
- referencedRelation: "itemPostingGroup"
- referencedColumns: ["id"]
- },
]
}
trainings: {
@@ -49975,7 +49943,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"]
description: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
modelName: string
modelPath: string
@@ -50373,7 +50340,6 @@ export type Database = {
grade: string
gradeId: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
materialForm: string
materialFormId: string
@@ -50488,7 +50454,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"]
description: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
modelId: string
modelName: string
@@ -50945,7 +50910,6 @@ export type Database = {
defaultMethodType: Database["public"]["Enums"]["methodType"]
description: string
id: string
- itemPostingGroupId: string
itemTrackingType: Database["public"]["Enums"]["itemTrackingType"]
modelId: string
modelName: string
diff --git a/packages/database/supabase/migrations/20251214180817_prevent-premature-job-completion.sql b/packages/database/supabase/migrations/20251214180817_prevent-premature-job-completion.sql
new file mode 100644
index 0000000000..153db5396b
--- /dev/null
+++ b/packages/database/supabase/migrations/20251214180817_prevent-premature-job-completion.sql
@@ -0,0 +1,171 @@
+-- Prevent job completion when operation status is changed to Done before job is released
+-- This fixes a bug where changing an operation to Done before the job is scheduled
+-- would mark the entire job as Completed (because no dependencies exist yet)
+
+CREATE OR REPLACE FUNCTION finish_job_operation()
+RETURNS TRIGGER AS $$
+DECLARE
+ job_status TEXT;
+BEGIN
+ -- Get current job status
+ SELECT status INTO job_status FROM "job" WHERE id = NEW."jobId";
+
+ -- Only process job completion logic if job is in active state (has been released)
+ -- Jobs in Draft or Planned status should not trigger completion since dependencies
+ -- are only created during scheduling
+ IF job_status NOT IN ('Ready', 'In Progress', 'Paused') THEN
+ RETURN NEW;
+ END IF;
+
+ -- Set endTime for all open production events
+ UPDATE "productionEvent"
+ SET "endTime" = NOW()
+ WHERE "jobOperationId" = NEW.id AND "endTime" IS NULL;
+
+ -- Find all operations that depend on this one and might be ready
+ UPDATE "jobOperation" op
+ SET status = 'Ready'
+ WHERE EXISTS (
+ SELECT 1
+ FROM "jobOperationDependency" dep
+ WHERE dep."operationId" = op.id
+ AND dep."dependsOnId" = NEW.id
+ AND op.status = 'Waiting'
+ )
+ AND NOT EXISTS (
+ -- Check no other dependencies are incomplete
+ SELECT 1
+ FROM "jobOperationDependency" dep2
+ JOIN "jobOperation" jo2 ON jo2.id = dep2."dependsOnId"
+ WHERE dep2."operationId" = op.id
+ AND jo2.status != 'Done'
+ AND jo2.id != NEW.id
+ );
+
+ -- Set the job operation status to Done
+ NEW.status = 'Done';
+
+ -- If this is the last operation, mark the job as Done
+ IF is_last_job_operation(NEW.id) THEN
+ DECLARE
+ request_id TEXT;
+ notify_url TEXT;
+ api_url TEXT;
+ anon_key TEXT;
+ group_ids TEXT[];
+ assigned_to TEXT;
+ sales_order_id TEXT;
+ BEGIN
+ -- Get job details
+ DECLARE
+ job_item_id TEXT;
+ job_quantity_to_produce INTEGER;
+ job_location_id TEXT;
+ job_shelf_id TEXT;
+ job_quantity INTEGER;
+ quantity_complete INTEGER;
+
+ BEGIN
+
+
+ SELECT "locationId", "shelfId", "quantity"
+ INTO job_location_id, job_shelf_id, job_quantity
+ FROM "job"
+ WHERE "id" = NEW."jobId";
+
+ -- Use full job quantity if quantityComplete is 0
+ quantity_complete := CASE
+ WHEN NEW."quantityComplete" = 0 THEN job_quantity
+ ELSE NEW."quantityComplete"
+ END;
+
+
+
+ -- Get sales order info
+ SELECT "salesOrderId" INTO sales_order_id FROM "job" WHERE "id" = NEW."jobId";
+
+ IF sales_order_id IS NOT NULL THEN
+ -- Make-to-order: just update job status with quantityComplete
+ UPDATE "job"
+ SET status = 'Completed',
+ "completedDate" = NOW(),
+ "quantityComplete" = quantity_complete,
+ "updatedAt" = NOW(),
+ "updatedBy" = NEW."updatedBy"
+ WHERE id = NEW."jobId";
+ ELSE
+ -- Make-to-stock: update job status to Done and invoke edge function for inventory
+ UPDATE "job"
+ SET status = 'Completed',
+ "completedDate" = NOW(),
+ "updatedAt" = NOW(),
+ "updatedBy" = NEW."updatedBy"
+ WHERE id = NEW."jobId";
+
+ -- Invoke the issue edge function to handle inventory
+ PERFORM util.invoke_edge_function(
+ name => 'issue',
+ body => CASE
+ WHEN job_shelf_id IS NOT NULL THEN
+ jsonb_build_object(
+ 'type', 'jobCompleteInventory',
+ 'jobId', NEW."jobId",
+ 'companyId', NEW."companyId",
+ 'userId', NEW."updatedBy",
+ 'quantityComplete', quantity_complete,
+ 'locationId', job_location_id,
+ 'shelfId', job_shelf_id
+ )
+ ELSE
+ jsonb_build_object(
+ 'type', 'jobCompleteInventory',
+ 'jobId', NEW."jobId",
+ 'companyId', NEW."companyId",
+ 'userId', NEW."updatedBy",
+ 'quantityComplete', quantity_complete,
+ 'locationId', job_location_id
+ )
+ END
+ );
+ END IF;
+ END;
+
+ SELECT "apiUrl", "anonKey" INTO api_url, anon_key FROM "config" LIMIT 1;
+ notify_url := api_url || '/functions/v1/trigger';
+
+ SELECT "assignee", "salesOrderId" INTO assigned_to, sales_order_id FROM "job" WHERE "id" = NEW."jobId";
+
+ IF sales_order_id IS NULL THEN
+ SELECT "inventoryJobCompletedNotificationGroup" INTO group_ids FROM "companySettings" WHERE "id" = NEW."companyId";
+ ELSE
+ SELECT "salesJobCompletedNotificationGroup" INTO group_ids FROM "companySettings" WHERE "id" = NEW."companyId";
+ END IF;
+
+ IF assigned_to IS NOT NULL THEN
+ SELECT array_append(group_ids, assigned_to) INTO group_ids;
+ END IF;
+
+ IF array_length(group_ids, 1) > 0 THEN
+ SELECT net.http_post(
+ notify_url,
+ jsonb_build_object(
+ 'type', 'notify',
+ 'event', 'job-completed',
+ 'documentId', NEW."jobId",
+ 'companyId', NEW."companyId",
+ 'recipient', jsonb_build_object(
+ 'type', 'group',
+ 'groupIds', group_ids
+ )
+ )::jsonb,
+ '{}'::jsonb,
+ jsonb_build_object('Content-Type', 'application/json', 'Authorization', 'Bearer ' || anon_key)
+ ) INTO request_id;
+ END IF;
+
+ END;
+ END IF;
+
+ RETURN NEW;
+END;
+$$ LANGUAGE plpgsql SECURITY DEFINER;