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(invoicing): show saved external notes on sales invoices (#2077)

Brad Barbin3994c6762e22
diff --git a/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineNotes.tsx b/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineNotes.tsx
index c34463b8c5..476d07520a 100644
--- a/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineNotes.tsx
+++ b/apps/erp/app/modules/sales/ui/Opportunity/OpportunityLineNotes.tsx
@@ -47,7 +47,13 @@ const OpportunityLineNotes = ({
const permissions = usePermissions();
const isEmployee = permissions.is("employee");
const { t } = useLingui();
- const canEdit = !isReadOnlyProp && permissions.can("update", "sales");
+ // Invoice rows are written under invoicing's RLS, not sales'.
+ const canEdit =
+ !isReadOnlyProp &&
+ permissions.can(
+ "update",
+ table === "salesInvoiceLine" ? "invoicing" : "sales"
+ );
const [tab, setTab] = useState(isEmployee ? "internal" : "external");
const [internalNotes, setInternalNotes] = useState(
initialInternalNotes ?? {}
diff --git a/apps/erp/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx b/apps/erp/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx
index 5ddf6eb935..286547506a 100644
--- a/apps/erp/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx
+++ b/apps/erp/app/modules/sales/ui/Opportunity/OpportunityNotes.tsx
@@ -45,7 +45,10 @@ const OpportunityNotes = ({
const permissions = usePermissions();
const isEmployee = permissions.is("employee");
const { t } = useLingui();
- const canEdit = !isReadOnlyProp && permissions.can("update", "sales");
+ // Invoice rows are written under invoicing's RLS, not sales'.
+ const canEdit =
+ !isReadOnlyProp &&
+ permissions.can("update", table === "salesInvoice" ? "invoicing" : "sales");
const [tab, setTab] = useState(isEmployee ? "internal" : "external");
const [internalNotes, setInternalNotes] = useState(
initialInternalNotes ?? {}
diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx
index b3362fcba1..40d5b780aa 100644
--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx
+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.$lineId.details.tsx
@@ -14,8 +14,13 @@ import { Fragment } from "react/jsx-runtime";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "react-router";
import { useLoaderData, useParams } from "react-router";
import { DeferredFiles } from "~/components";
-import { salesInvoiceLineValidator } from "~/modules/invoicing/invoicing.models";
+import { useRouteData } from "~/hooks";
+import {
+ isSalesInvoiceLocked,
+ salesInvoiceLineValidator
+} from "~/modules/invoicing/invoicing.models";
import { getSalesInvoiceLine } from "~/modules/invoicing/invoicing.service";
+import type { SalesInvoice } from "~/modules/invoicing/types";
import SalesInvoiceLineForm from "~/modules/invoicing/ui/SalesInvoice/SalesInvoiceLineForm";
import { getOpportunityLineDocuments } from "~/modules/sales/sales.service";
import {
@@ -73,6 +78,9 @@ export default function EditSalesInvoiceLineRoute() {
if (!lineId) throw notFound("lineId not found");
const { salesInvoiceLine, files } = useLoaderData<typeof loader>();
+ const routeData = useRouteData<{ salesInvoice: SalesInvoice }>(
+ path.to.salesInvoice(invoiceId)
+ );
const initialValues = {
id: salesInvoiceLine?.id ?? undefined,
@@ -115,7 +123,9 @@ export default function EditSalesInvoiceLineRoute() {
table="salesInvoiceLine"
title={t`Notes`}
subTitle={getItemReadableId(items, salesInvoiceLine?.itemId) ?? ""}
+ isReadOnly={isSalesInvoiceLocked(routeData?.salesInvoice?.status)}
internalNotes={salesInvoiceLine?.internalNotes as JSONContent}
+ externalNotes={salesInvoiceLine?.externalNotes as JSONContent}
/>
<DeferredFiles resolve={files}>
diff --git a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.details.tsx b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.details.tsx
index aeaaf23d42..074ea5017b 100644
--- a/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.details.tsx
+++ b/apps/erp/app/routes/x+/sales-invoice+/$invoiceId.details.tsx
@@ -15,6 +15,7 @@ import type { LoaderFunctionArgs } from "react-router";
import { useLoaderData, useParams } from "react-router";
import { DeferredFiles } from "~/components";
import { useRouteData, useUser } from "~/hooks";
+import { isSalesInvoiceLocked } from "~/modules/invoicing/invoicing.models";
import {
getInvoiceSettlementsForInvoice,
getSalesInvoice
@@ -57,13 +58,15 @@ export async function loader({ request, params }: LoaderFunctionArgs) {
return {
internalNotes: (invoice.data?.internalNotes ?? {}) as JSONContent,
+ externalNotes: (invoice.data?.externalNotes ?? {}) as JSONContent,
paymentApplications: applications.data ?? []
};
}
export default function SalesInvoiceBasicRoute() {
const { t } = useLingui();
- const { internalNotes, paymentApplications } = useLoaderData<typeof loader>();
+ const { internalNotes, externalNotes, paymentApplications } =
+ useLoaderData<typeof loader>();
const { invoiceId } = useParams();
if (!invoiceId) throw new Error("invoiceId not found");
@@ -109,7 +112,9 @@ export default function SalesInvoiceBasicRoute() {
id={invoiceId}
title={t`Notes`}
table="salesInvoice"
+ isReadOnly={isSalesInvoiceLocked(salesInvoice.status)}
internalNotes={internalNotes}
+ externalNotes={externalNotes}
/>
{/* Documents live under the opportunity's storage folder, so an
invoice without one has nowhere to keep them. */}
diff --git a/packages/documents/src/pdf/blocks/LineItemsBlock.tsx b/packages/documents/src/pdf/blocks/LineItemsBlock.tsx
index d206a31531..7b8186e813 100644
--- a/packages/documents/src/pdf/blocks/LineItemsBlock.tsx
+++ b/packages/documents/src/pdf/blocks/LineItemsBlock.tsx
@@ -205,11 +205,17 @@ export function LineItemsBlock({
</Text>
</View>
{Object.keys(line.externalNotes ?? {}).length > 0 ? (
- <View style={tw("px-3 py-2 border-b border-gray-200")}>
- <Note
- key={`${line.id}-notes`}
- content={line.externalNotes as JSONContent}
- />
+ // Indented under the description, past the line-number column.
+ <View
+ style={tw("flex flex-row px-3 py-2 border-b border-gray-200")}
+ >
+ <View style={tw("w-[6%]")} />
+ <View style={tw("w-[94%]")}>
+ <Note
+ key={`${line.id}-notes`}
+ content={line.externalNotes as JSONContent}
+ />
+ </View>
</View>
) : null}
</View>