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.

feat: add supplier quote notification functionality

Bakuto72d5e578e93c
diff --git a/apps/erp/app/components/Layout/Topbar/Notifications.tsx b/apps/erp/app/components/Layout/Topbar/Notifications.tsx
index 87fd3a9677..a44da2402b 100644
--- a/apps/erp/app/components/Layout/Topbar/Notifications.tsx
+++ b/apps/erp/app/components/Layout/Topbar/Notifications.tsx
@@ -322,6 +322,14 @@ function GenericNotification({
{...props}
/>
);
+ case NotificationEvent.SupplierQuoteResponse:
+ return (
+ <Notification
+ icon={<LuMailCheck />}
+ to={path.to.supplierQuoteDetails(id)}
+ {...props}
+ />
+ );
case NotificationEvent.TrainingAssignment:
return (
<Notification
diff --git a/apps/erp/app/modules/settings/settings.models.ts b/apps/erp/app/modules/settings/settings.models.ts
index 0c01fdfb4d..cc1d687a6d 100644
--- a/apps/erp/app/modules/settings/settings.models.ts
+++ b/apps/erp/app/modules/settings/settings.models.ts
@@ -120,6 +120,12 @@ export const suggestionNotificationValidator = z.object({
.optional()
});
+export const supplierQuoteNotificationValidator = z.object({
+ supplierQuoteNotificationGroup: z
+ .array(z.string().min(1, { message: "Invalid selection" }))
+ .optional()
+});
+
export const sequenceValidator = z.object({
table: z.string().min(1, { message: "Table is required" }),
prefix: zfd.text(z.string().optional()),
diff --git a/apps/erp/app/modules/settings/settings.service.ts b/apps/erp/app/modules/settings/settings.service.ts
index 5df6c1a960..8757a4b020 100644
--- a/apps/erp/app/modules/settings/settings.service.ts
+++ b/apps/erp/app/modules/settings/settings.service.ts
@@ -588,6 +588,17 @@ export async function updateSuggestionNotificationSetting(
.eq("id", companyId);
}
+export async function updateSupplierQuoteNotificationSetting(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ supplierQuoteNotificationGroup: string[]
+) {
+ return client
+ .from("companySettings")
+ .update(sanitize({ supplierQuoteNotificationGroup }))
+ .eq("id", companyId);
+}
+
export async function updatePurchasePriceUpdateTimingSetting(
client: SupabaseClient<Database>,
companyId: string,
diff --git a/apps/erp/app/novu/workflows.ts b/apps/erp/app/novu/workflows.ts
index ba098d1528..d184085358 100644
--- a/apps/erp/app/novu/workflows.ts
+++ b/apps/erp/app/novu/workflows.ts
@@ -29,6 +29,7 @@ const payloadSchema = z.object({
NotificationEvent.StockTransferAssignment,
NotificationEvent.SuggestionResponse,
NotificationEvent.SupplierQuoteAssignment,
+ NotificationEvent.SupplierQuoteResponse,
NotificationEvent.TrainingAssignment
]),
from: z.string().optional()
@@ -114,3 +115,14 @@ export const suggestionResponseWorkflow = workflow(
},
{ payloadSchema }
);
+
+export const supplierQuoteResponseWorkflow = workflow(
+ NotificationWorkflow.SupplierQuoteResponse,
+ async ({ payload, step }) => {
+ await step.inApp(NotificationType.SupplierQuoteResponseInApp, () => ({
+ body: "Supplier Quote Response",
+ payload
+ }));
+ },
+ { payloadSchema }
+);
diff --git a/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx b/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx
index 1c7ebde728..3a7996eb74 100644
--- a/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx
+++ b/apps/erp/app/routes/api+/purchasing.digital-quote.$id.tsx
@@ -1,5 +1,8 @@
import { assertIsPost, getCarbonServiceRole, notFound } from "@carbon/auth";
import { validationError, validator } from "@carbon/form";
+import type { notifyTask } from "@carbon/jobs/trigger/notify";
+import { NotificationEvent } from "@carbon/notifications";
+import { tasks } from "@trigger.dev/sdk";
import type { ActionFunctionArgs } from "react-router";
import { z } from "zod/v3";
import {
@@ -253,6 +256,23 @@ export async function action({ request, params }: ActionFunctionArgs) {
console.error("Failed to get company settings", companySettings.error);
}
+ // Send notification to supplier quote notification group
+ if (companySettings.data?.supplierQuoteNotificationGroup?.length) {
+ try {
+ await tasks.trigger<typeof notifyTask>("notify", {
+ companyId: companySettings.data.id,
+ documentId: quote.data.id,
+ event: NotificationEvent.SupplierQuoteResponse,
+ recipient: {
+ type: "group",
+ groupIds: companySettings.data.supplierQuoteNotificationGroup
+ }
+ });
+ } catch (err) {
+ console.error("Failed to trigger supplier quote notification", err);
+ }
+ }
+
return {
success: true,
message: "Quote submitted successfully"
diff --git a/apps/erp/app/routes/x+/settings+/purchasing.tsx b/apps/erp/app/routes/x+/settings+/purchasing.tsx
index 1dc98c5291..db49d38923 100644
--- a/apps/erp/app/routes/x+/settings+/purchasing.tsx
+++ b/apps/erp/app/routes/x+/settings+/purchasing.tsx
@@ -15,6 +15,7 @@ import {
generateHTML,
Heading,
HStack,
+ Label,
ScrollArea,
toast,
useDebounce,
@@ -26,13 +27,16 @@ import { useEffect, useState } from "react";
import { LuCircleCheck } from "react-icons/lu";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { redirect, useFetcher, useLoaderData } from "react-router";
+import { Users } from "~/components/Form";
import { usePermissions, useUser } from "~/hooks";
import {
getCompanySettings,
getTerms,
purchasePriceUpdateTimingTypes,
purchasePriceUpdateTimingValidator,
- updatePurchasePriceUpdateTimingSetting
+ supplierQuoteNotificationValidator,
+ updatePurchasePriceUpdateTimingSetting,
+ updateSupplierQuoteNotificationSetting
} from "~/modules/settings";
import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
@@ -107,6 +111,30 @@ export async function action({ request }: ActionFunctionArgs) {
success: true,
message: "Purchase price update timing updated"
};
+
+ case "supplierQuoteNotification":
+ const supplierQuoteValidation = await validator(
+ supplierQuoteNotificationValidator
+ ).validate(formData);
+
+ if (supplierQuoteValidation.error) {
+ return { success: false, message: "Invalid form data" };
+ }
+
+ const supplierQuoteResult = await updateSupplierQuoteNotificationSetting(
+ client,
+ companyId,
+ supplierQuoteValidation.data.supplierQuoteNotificationGroup ?? []
+ );
+
+ if (supplierQuoteResult.error) {
+ return { success: false, message: supplierQuoteResult.error.message };
+ }
+
+ return {
+ success: true,
+ message: "Supplier quote notification setting updated"
+ };
}
return { success: false, message: "Unknown intent" };
@@ -211,6 +239,44 @@ export default function PurchasingSettingsRoute() {
</CardFooter>
</ValidatedForm>
</Card>
+ <Card>
+ <ValidatedForm
+ method="post"
+ validator={supplierQuoteNotificationValidator}
+ defaultValues={{
+ supplierQuoteNotificationGroup:
+ companySettings.supplierQuoteNotificationGroup ?? []
+ }}
+ fetcher={fetcher}
+ >
+ <input
+ type="hidden"
+ name="intent"
+ value="supplierQuoteNotification"
+ />
+ <CardHeader>
+ <CardTitle>Supplier Quote Notifications</CardTitle>
+ <CardDescription>
+ Configure who should receive notifications when a supplier
+ submits a quote.
+ </CardDescription>
+ </CardHeader>
+ <CardContent>
+ <div className="flex flex-col gap-8 max-w-[400px]">
+ <div className="flex flex-col gap-2">
+ <Label>Notifications</Label>
+ <Users
+ name="supplierQuoteNotificationGroup"
+ label="Who should receive notifications when a supplier quote is submitted?"
+ />
+ </div>
+ </div>
+ </CardContent>
+ <CardFooter>
+ <Submit>Save</Submit>
+ </CardFooter>
+ </ValidatedForm>
+ </Card>
<Card>
<HStack className="justify-between items-start">
<CardHeader>
diff --git a/packages/jobs/trigger/notify.ts b/packages/jobs/trigger/notify.ts
index e840bfd67f..5d12edeaaf 100644
--- a/packages/jobs/trigger/notify.ts
+++ b/packages/jobs/trigger/notify.ts
@@ -78,6 +78,8 @@ export const notifyTask = task({
return NotificationWorkflow.DigitalQuoteResponse;
case NotificationEvent.SuggestionResponse:
return NotificationWorkflow.SuggestionResponse;
+ case NotificationEvent.SupplierQuoteResponse:
+ return NotificationWorkflow.SupplierQuoteResponse;
case NotificationEvent.JobOperationMessage:
return NotificationWorkflow.Message;
default:
@@ -304,6 +306,23 @@ export const notifyTask = task({
return `Risk "${risk?.data?.title}" assigned to you`;
+ case NotificationEvent.SupplierQuoteResponse:
+ const supplierQuote = await client
+ .from("supplierQuote")
+ .select("*")
+ .eq("id", documentId)
+ .single();
+
+
+ if (supplierQuote.error) {
+ console.error("Failed to get supplier quote", supplierQuote.error);
+ throw supplierQuote.error;
+ }
+
+ const externalNotes = supplierQuote.data.externalNotes as Record<string, unknown> | null;
+ const respondedBy = externalNotes?.lastSubmittedBy as string | undefined || "Supplier";
+ return `Supplier Quote ${supplierQuote?.data?.supplierQuoteId} was submitted by ${respondedBy}`;
+
default:
return null;
}
diff --git a/packages/notifications/src/index.ts b/packages/notifications/src/index.ts
index dbf6114330..bc6fbd779b 100644
--- a/packages/notifications/src/index.ts
+++ b/packages/notifications/src/index.ts
@@ -9,7 +9,8 @@ export enum NotificationWorkflow {
GaugeCalibration = "gauge-calibration",
JobCompleted = "job-completed",
Message = "message",
- SuggestionResponse = "suggestion-response"
+ SuggestionResponse = "suggestion-response",
+ SupplierQuoteResponse = "supplier-quote-response"
}
export enum NotificationEvent {
@@ -32,6 +33,7 @@ export enum NotificationEvent {
StockTransferAssignment = "stock-transfer-assignment",
SuggestionResponse = "suggestion-response",
SupplierQuoteAssignment = "supplier-quote-assignment",
+ SupplierQuoteResponse = "supplier-quote-response",
TrainingAssignment = "training-assignment"
}
@@ -41,7 +43,8 @@ export enum NotificationType {
JobCompletedInApp = "job-completed-in-app",
ExpirationInApp = "expiration-in-app",
MessageInApp = "message-in-app",
- SuggestionResponseInApp = "suggestion-response-in-app"
+ SuggestionResponseInApp = "suggestion-response-in-app",
+ SupplierQuoteResponseInApp = "supplier-quote-response-in-app"
}
export type TriggerUser = {