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: update status of gauge if date is equal to last calibration

Brad Barbin7c46db31289c
diff --git a/apps/erp/app/modules/quality/quality.service.ts b/apps/erp/app/modules/quality/quality.service.ts
index 5afb728867..2975a07350 100644
--- a/apps/erp/app/modules/quality/quality.service.ts
+++ b/apps/erp/app/modules/quality/quality.service.ts
@@ -756,7 +756,7 @@ export async function upsertGaugeCalibrationRecord(
if (
!gauge.data?.lastCalibrationDate ||
- parseDate(gauge.data.lastCalibrationDate) <
+ parseDate(gauge.data.lastCalibrationDate) <=
parseDate(gaugeCalibrationRecord.dateCalibrated)
) {
const nextCalibrationDate = parseDate(gaugeCalibrationRecord.dateCalibrated)
diff --git a/apps/erp/app/routes/x+/quality+/calibrations.$id.tsx b/apps/erp/app/routes/x+/quality+/calibrations.$id.tsx
index ce0e4e5838..4d3287f6a5 100644
--- a/apps/erp/app/routes/x+/quality+/calibrations.$id.tsx
+++ b/apps/erp/app/routes/x+/quality+/calibrations.$id.tsx
@@ -68,7 +68,7 @@ export async function action({ request }: ActionFunctionArgs) {
? "Fail"
: "Pass";
- const updateGuage = await upsertGaugeCalibrationRecord(client, {
+ const updateGauge = await upsertGaugeCalibrationRecord(client, {
id,
...data,
inspectionStatus,
@@ -77,10 +77,13 @@ export async function action({ request }: ActionFunctionArgs) {
customFields: setCustomFields(formData),
});
- if (updateGuage.error || !updateGuage.data) {
+ if (updateGauge.error) {
throw redirect(
`${path.to.calibrations}?${getParams(request)}`,
- await flash(request, error(updateGuage.error, "Failed to insert gauge"))
+ await flash(
+ request,
+ error(updateGauge.error, "Failed to update gauge calibration record")
+ )
);
}
diff --git a/apps/erp/app/routes/x+/quality+/calibrations.new.tsx b/apps/erp/app/routes/x+/quality+/calibrations.new.tsx
index 75db3141de..28f0ed8ebd 100644
--- a/apps/erp/app/routes/x+/quality+/calibrations.new.tsx
+++ b/apps/erp/app/routes/x+/quality+/calibrations.new.tsx
@@ -56,7 +56,10 @@ export async function action({ request }: ActionFunctionArgs) {
if (createGauge.error || !createGauge.data) {
throw redirect(
path.to.gauges,
- await flash(request, error(createGauge.error, "Failed to insert gauge"))
+ await flash(
+ request,
+ error(createGauge.error, "Failed to insert gauge calibration record")
+ )
);
}
diff --git a/packages/database/src/swagger-docs-schema.ts b/packages/database/src/swagger-docs-schema.ts
index 452473d72a..afc6909db6 100644
--- a/packages/database/src/swagger-docs-schema.ts
+++ b/packages/database/src/swagger-docs-schema.ts
@@ -7860,6 +7860,9 @@ export default {
{
$ref: "#/parameters/rowFilter.gaugeCalibrationRecords.id",
},
+ {
+ $ref: "#/parameters/rowFilter.gaugeCalibrationRecords.gaugeId",
+ },
{
$ref: "#/parameters/rowFilter.gaugeCalibrationRecords.dateCalibrated",
},
@@ -7897,7 +7900,7 @@ export default {
$ref: "#/parameters/rowFilter.gaugeCalibrationRecords.updatedBy",
},
{
- $ref: "#/parameters/rowFilter.gaugeCalibrationRecords.gaugeId",
+ $ref: "#/parameters/rowFilter.gaugeCalibrationRecords.gaugeReadableId",
},
{
$ref: "#/parameters/rowFilter.gaugeCalibrationRecords.gaugeTypeId",
@@ -56899,6 +56902,12 @@ export default {
format: "text",
type: "string",
},
+ gaugeId: {
+ description:
+ "Note:\nThis is a Foreign Key to `gauge.id`.<fk table='gauge' column='id'/>",
+ format: "text",
+ type: "string",
+ },
dateCalibrated: {
format: "date",
type: "string",
@@ -56952,7 +56961,7 @@ export default {
format: "text",
type: "string",
},
- gaugeId: {
+ gaugeReadableId: {
format: "text",
type: "string",
},
@@ -80127,6 +80136,12 @@ export default {
in: "query",
type: "string",
},
+ "rowFilter.gaugeCalibrationRecords.gaugeId": {
+ name: "gaugeId",
+ required: false,
+ in: "query",
+ type: "string",
+ },
"rowFilter.gaugeCalibrationRecords.dateCalibrated": {
name: "dateCalibrated",
required: false,
@@ -80199,8 +80214,8 @@ export default {
in: "query",
type: "string",
},
- "rowFilter.gaugeCalibrationRecords.gaugeId": {
- name: "gaugeId",
+ "rowFilter.gaugeCalibrationRecords.gaugeReadableId": {
+ name: "gaugeReadableId",
required: false,
in: "query",
type: "string",
diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts
index fb530c9c94..ee952877ea 100644
--- a/packages/database/src/types.ts
+++ b/packages/database/src/types.ts
@@ -32936,6 +32936,7 @@ export type Database = {
dateCalibrated: string | null
description: string | null
gaugeId: string | null
+ gaugeReadableId: string | null
gaugeTypeId: string | null
id: string | null
inspectionStatus:
@@ -33019,6 +33020,20 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "gaugeCalibrationRecord_gaugeId_fkey"
+ columns: ["gaugeId"]
+ isOneToOne: false
+ referencedRelation: "gauge"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "gaugeCalibrationRecord_gaugeId_fkey"
+ columns: ["gaugeId"]
+ isOneToOne: false
+ referencedRelation: "gauges"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "gaugeCalibrationRecord_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/functions/lib/types.ts b/packages/database/supabase/functions/lib/types.ts
index fb530c9c94..ee952877ea 100644
--- a/packages/database/supabase/functions/lib/types.ts
+++ b/packages/database/supabase/functions/lib/types.ts
@@ -32936,6 +32936,7 @@ export type Database = {
dateCalibrated: string | null
description: string | null
gaugeId: string | null
+ gaugeReadableId: string | null
gaugeTypeId: string | null
id: string | null
inspectionStatus:
@@ -33019,6 +33020,20 @@ export type Database = {
referencedRelation: "userDefaults"
referencedColumns: ["userId"]
},
+ {
+ foreignKeyName: "gaugeCalibrationRecord_gaugeId_fkey"
+ columns: ["gaugeId"]
+ isOneToOne: false
+ referencedRelation: "gauge"
+ referencedColumns: ["id"]
+ },
+ {
+ foreignKeyName: "gaugeCalibrationRecord_gaugeId_fkey"
+ columns: ["gaugeId"]
+ isOneToOne: false
+ referencedRelation: "gauges"
+ referencedColumns: ["id"]
+ },
{
foreignKeyName: "gaugeCalibrationRecord_updatedBy_fkey"
columns: ["updatedBy"]
diff --git a/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql b/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql
index 9243925ed8..b7282d9bf5 100644
--- a/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql
+++ b/packages/database/supabase/migrations/20250502132738_gauge-calibration.sql
@@ -184,6 +184,47 @@ SELECT
FROM "company";
+CREATE POLICY "SELECT" ON "public"."gauge"
+FOR SELECT USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_role()
+ )::text[]
+ )
+);
+
+CREATE POLICY "INSERT" ON "public"."gauge"
+FOR INSERT WITH CHECK (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('quality_create')
+ )::text[]
+ )
+);
+
+CREATE POLICY "UPDATE" ON "public"."gauge"
+FOR UPDATE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('quality_update')
+ )::text[]
+ )
+);
+
+CREATE POLICY "DELETE" ON "public"."gauge"
+FOR DELETE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('quality_delete')
+ )::text[]
+ )
+);
+
+
CREATE TYPE "inspectionStatus" AS ENUM (
'Pass',
'Fail'
@@ -236,3 +277,45 @@ SELECT
g."description"
FROM "gaugeCalibrationRecord" gcr
JOIN "gauge" g ON gcr."gaugeId" = g."id";
+
+
+
+CREATE POLICY "SELECT" ON "public"."gaugeCalibrationRecord"
+FOR SELECT USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('quality_view')
+ )::text[]
+ )
+);
+
+CREATE POLICY "INSERT" ON "public"."gaugeCalibrationRecord"
+FOR INSERT WITH CHECK (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('quality_create')
+ )::text[]
+ )
+);
+
+CREATE POLICY "UPDATE" ON "public"."gaugeCalibrationRecord"
+FOR UPDATE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('quality_update')
+ )::text[]
+ )
+);
+
+CREATE POLICY "DELETE" ON "public"."gaugeCalibrationRecord"
+FOR DELETE USING (
+ "companyId" = ANY (
+ (
+ SELECT
+ get_companies_with_employee_permission ('quality_delete')
+ )::text[]
+ )
+);
\ No newline at end of file