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: move Supplier fields Posting Group and Tax ID to a new Accounting tab

Rob Carrington39c84c54466f
diff --git a/apps/carbon/app/modules/purchasing/purchasing.models.ts b/apps/carbon/app/modules/purchasing/purchasing.models.ts
index 176f608ddf..f2b11e8c92 100644
--- a/apps/carbon/app/modules/purchasing/purchasing.models.ts
+++ b/apps/carbon/app/modules/purchasing/purchasing.models.ts
@@ -206,6 +206,12 @@ export const supplierShippingValidator = z.object({
shippingMethodId: zfd.text(z.string().optional()),
});
+export const supplierAccountingValidator = z.object({
+ id: zfd.text(z.string()),
+ supplierTypeId: zfd.text(z.string().optional()),
+ taxId: zfd.text(z.string().optional()),
+});
+
export const supplierTypeValidator = z.object({
id: zfd.text(z.string().optional()),
name: z.string().min(1, { message: "Name is required" }),
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierAccountingForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierAccountingForm.tsx
new file mode 100644
index 0000000000..0f2e13ae5b
--- /dev/null
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierAccountingForm.tsx
@@ -0,0 +1,56 @@
+import {
+ Card,
+ CardContent,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ HStack,
+} from "@carbon/react";
+import { ValidatedForm } from "@carbon/remix-validated-form";
+import type { z } from "zod";
+import { Input, Submit, SupplierType } from "~/components/Form";
+import { usePermissions } from "~/hooks";
+import { supplierAccountingValidator } from "~/modules/purchasing";
+
+type SupplierPaymentFormProps = {
+ initialValues: z.infer<typeof supplierAccountingValidator>;
+};
+
+const SupplierAccountingForm = ({
+ initialValues,
+}: SupplierPaymentFormProps) => {
+ const permissions = usePermissions();
+
+ const isDisabled = !permissions.can("update", "purchasing");
+
+ return (
+ <ValidatedForm
+ method="post"
+ validator={supplierAccountingValidator}
+ defaultValues={initialValues}
+ >
+ <Card>
+ <CardHeader>
+ <CardTitle>Supplier Accounting</CardTitle>
+ </CardHeader>
+ <CardContent>
+ <div className="grid grid-cols-1 lg:grid-cols-3 gap-x-8 gap-y-4 w-full">
+ <Input name="taxId" label="Tax ID" />
+ <SupplierType
+ name="supplierTypeId"
+ label="Posting Group"
+ placeholder="Select Posting Group"
+ />
+ </div>
+ </CardContent>
+ <CardFooter>
+ <HStack>
+ <Submit isDisabled={isDisabled}>Save</Submit>
+ </HStack>
+ </CardFooter>
+ </Card>
+ </ValidatedForm>
+ );
+};
+
+export default SupplierAccountingForm;
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
index 937da7f647..93d2da4dfd 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierForm.tsx
@@ -23,7 +23,6 @@ import {
Input,
Submit,
SupplierStatus,
- SupplierType,
} from "~/components/Form";
import { usePermissions } from "~/hooks";
import type { Supplier } from "~/modules/purchasing";
@@ -93,13 +92,7 @@ const SupplierForm = ({
)}
>
<Input autoFocus={!isEditing} name="name" label="Name" />
- <Input name="taxId" label="Tax ID" />
- <SupplierType
- name="supplierTypeId"
- label="Posting Group"
- placeholder="Select Posting Group"
- />
<SupplierStatus
name="supplierStatusId"
label="Supplier Status"
diff --git a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
index 75aa7de65a..cc78f11869 100644
--- a/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/Supplier/SupplierSidebar/useSupplierSidebar.tsx
@@ -3,6 +3,7 @@ import {
LuBuilding,
LuContact,
LuCreditCard,
+ LuLandmark,
LuMapPin,
LuTruck,
} from "react-icons/lu";
@@ -57,6 +58,13 @@ export function useSupplierSidebar({ contacts, locations }: Props) {
icon: LuTruck,
shortcut: "Command+Shift+s",
},
+ {
+ name: "Accounting",
+ to: path.to.supplierAccounting(supplierId),
+ role: ["employee"],
+ icon: LuLandmark,
+ shortcut: "Command+Shift+a",
+ },
].filter(
(item) =>
item.role === undefined ||
diff --git a/apps/carbon/app/routes/x+/supplier+/$supplierId.accounting.tsx b/apps/carbon/app/routes/x+/supplier+/$supplierId.accounting.tsx
new file mode 100644
index 0000000000..bf590530e2
--- /dev/null
+++ b/apps/carbon/app/routes/x+/supplier+/$supplierId.accounting.tsx
@@ -0,0 +1,76 @@
+import { validationError, validator } from "@carbon/remix-validated-form";
+import type { ActionFunctionArgs } from "@remix-run/node";
+import { json, redirect } from "@remix-run/node";
+import { useParams } from "@remix-run/react";
+import { useRouteData } from "~/hooks";
+import type { SupplierDetail } from "~/modules/purchasing";
+import { supplierValidator, upsertSupplier } from "~/modules/purchasing";
+import SupplierAccountingForm from "~/modules/purchasing/ui/Supplier/SupplierAccountingForm";
+import { requirePermissions } from "~/services/auth/auth.server";
+import { flash } from "~/services/session.server";
+import { getCustomFields } from "~/utils/form";
+import { assertIsPost } from "~/utils/http";
+import { path } from "~/utils/path";
+import { error, success } from "~/utils/result";
+
+export async function action({ request }: ActionFunctionArgs) {
+ console.log("got here!!!");
+ assertIsPost(request);
+ const { client, userId } = await requirePermissions(request, {
+ create: "purchasing",
+ });
+ const formData = await request.formData();
+ const validation = await validator(supplierValidator).validate(formData);
+
+ if (validation.error) {
+ return validationError(validation.error);
+ }
+
+ const { id, ...data } = validation.data;
+
+ if (!id) {
+ throw redirect(
+ path.to.suppliers,
+ await flash(request, error(null, "Failed to update supplier"))
+ );
+ }
+
+ const update = await upsertSupplier(client, {
+ id,
+ ...data,
+ updatedBy: userId,
+ });
+
+ if (update.error) {
+ throw redirect(
+ path.to.suppliers,
+ await flash(request, error(update.error, "Failed to update supplier"))
+ );
+ }
+
+ return json(null, await flash(request, success("Updated supplier")));
+}
+
+export default function SupplierAccountingRoute() {
+ const { supplierId } = useParams();
+ if (!supplierId) throw new Error("Could not find supplierId");
+ const routeData = useRouteData<{ supplier: SupplierDetail }>(
+ path.to.supplier(supplierId)
+ );
+
+ if (!routeData?.supplier) return null;
+
+ const initialValues = {
+ id: routeData?.supplier?.id ?? undefined,
+ supplierTypeId: routeData?.supplier?.supplierTypeId ?? undefined,
+ taxId: routeData?.supplier?.taxId ?? "",
+ ...getCustomFields(routeData?.supplier?.customFields),
+ };
+
+ return (
+ <SupplierAccountingForm
+ key={initialValues.id}
+ initialValues={initialValues}
+ />
+ );
+}
diff --git a/apps/carbon/app/utils/path.ts b/apps/carbon/app/utils/path.ts
index 8d872f4a63..924588f820 100644
--- a/apps/carbon/app/utils/path.ts
+++ b/apps/carbon/app/utils/path.ts
@@ -673,6 +673,8 @@ export const path = {
generatePath(`${x}/supplier/${id}/payments`),
supplierShipping: (id: string) =>
generatePath(`${x}/supplier/${id}/shipping`),
+ supplierAccounting: (id: string) =>
+ generatePath(`${x}/supplier/${id}/accounting`),
supplierRoot: `${x}/supplier`,
supplierStatus: (id: string) =>
generatePath(`${x}/purchasing/supplier-statuses/${id}`),