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: receipt and invoice posting when both inventory and supplier type is null

Brad Barbinfc8df08f8f57
diff --git a/apps/carbon/app/modules/accounting/accounting.service.ts b/apps/carbon/app/modules/accounting/accounting.service.ts
index d8a15d8745..2729064d4a 100644
--- a/apps/carbon/app/modules/accounting/accounting.service.ts
+++ b/apps/carbon/app/modules/accounting/accounting.service.ts
@@ -470,12 +470,16 @@ export async function getFiscalYearSettings(
export async function getInventoryPostingGroup(
client: SupabaseClient<Database>,
+ companyId: string,
args: {
itemPostingGroupId: string | null;
locationId: string | null;
}
) {
- let query = client.from("postingGroupInventory").select("*");
+ let query = client
+ .from("postingGroupInventory")
+ .select("*")
+ .eq("companyId", companyId);
if (args.itemPostingGroupId === null) {
query = query.is("itemPostingGroupId", null);
@@ -560,12 +564,16 @@ export async function getPaymentTermsList(
export async function getPurchasingPostingGroup(
client: SupabaseClient<Database>,
+ companyId: string,
args: {
itemPostingGroupId: string | null;
supplierTypeId: string | null;
}
) {
- let query = client.from("postingGroupInventory").select("*");
+ let query = client
+ .from("postingGroupInventory")
+ .select("*")
+ .eq("companyId", companyId);
if (args.itemPostingGroupId === null) {
query = query.is("itemPostingGroupId", null);
diff --git a/apps/carbon/app/modules/inventory/ui/Inventory/InventoryActivity.tsx b/apps/carbon/app/modules/inventory/ui/Inventory/InventoryActivity.tsx
index 8b42f81c41..7c3112a04d 100644
--- a/apps/carbon/app/modules/inventory/ui/Inventory/InventoryActivity.tsx
+++ b/apps/carbon/app/modules/inventory/ui/Inventory/InventoryActivity.tsx
@@ -3,6 +3,46 @@ import Activity from "~/components/Activity";
import type { ItemLedger } from "../../types";
const getActivityText = (ledgerRecord: ItemLedger) => {
+ console.log({ ledgerRecord });
+ switch (ledgerRecord.documentType) {
+ case "Purchase Receipt":
+ return `received ${ledgerRecord.quantity} units`;
+ case "Purchase Invoice":
+ return `invoiced ${ledgerRecord.quantity} units`;
+ case "Sales Shipment":
+ return `shipped ${ledgerRecord.quantity} units`;
+ case "Sales Invoice":
+ return `invoiced ${ledgerRecord.quantity} units for sale`;
+ case "Transfer Shipment":
+ return `shipped ${ledgerRecord.quantity} units for transfer`;
+ case "Transfer Receipt":
+ return `received ${ledgerRecord.quantity} units from transfer`;
+ case "Direct Transfer":
+ return `directly transferred ${ledgerRecord.quantity} units`;
+ case "Inventory Receipt":
+ return `received ${ledgerRecord.quantity} units into inventory`;
+ case "Inventory Shipment":
+ return `shipped ${ledgerRecord.quantity} units from inventory`;
+ case "Posted Assembly":
+ return `assembled ${ledgerRecord.quantity} units`;
+ case "Purchase Credit Memo":
+ return `credited ${ledgerRecord.quantity} units for purchase`;
+ case "Purchase Return Shipment":
+ return `returned ${ledgerRecord.quantity} units to supplier`;
+ case "Sales Credit Memo":
+ return `credited ${ledgerRecord.quantity} units for sale`;
+ case "Sales Return Receipt":
+ return `received ${ledgerRecord.quantity} units as sales return`;
+ case "Service Credit Memo":
+ return `credited ${ledgerRecord.quantity} units for service`;
+ case "Service Invoice":
+ return `invoiced ${ledgerRecord.quantity} units for service`;
+ case "Service Shipment":
+ return `shipped ${ledgerRecord.quantity} units for service`;
+ default:
+ break;
+ }
+
switch (ledgerRecord.entryType) {
case "Positive Adjmt.":
return `made a positive adjustment of ${ledgerRecord.quantity}${
diff --git a/packages/database/supabase/functions/post-purchase-invoice/index.ts b/packages/database/supabase/functions/post-purchase-invoice/index.ts
index fc89e64b97..21e92147a3 100644
--- a/packages/database/supabase/functions/post-purchase-invoice/index.ts
+++ b/packages/database/supabase/functions/post-purchase-invoice/index.ts
@@ -283,6 +283,7 @@ serve(async (req: Request) => {
} else {
const inventoryPostingGroup = await getInventoryPostingGroup(
client,
+ companyId,
{
itemPostingGroupId,
locationId,
@@ -312,6 +313,7 @@ serve(async (req: Request) => {
} else {
const purchasingPostingGroup = await getPurchasingPostingGroup(
client,
+ companyId,
{
itemPostingGroupId,
supplierTypeId,
diff --git a/packages/database/supabase/functions/post-receipt/index.ts b/packages/database/supabase/functions/post-receipt/index.ts
index ed6d3ffcf7..af648b64f9 100644
--- a/packages/database/supabase/functions/post-receipt/index.ts
+++ b/packages/database/supabase/functions/post-receipt/index.ts
@@ -234,6 +234,7 @@ serve(async (req: Request) => {
} else {
const inventoryPostingGroup = await getInventoryPostingGroup(
client,
+ companyId,
{
itemPostingGroupId,
locationId,
@@ -271,8 +272,10 @@ serve(async (req: Request) => {
`${itemPostingGroupId}-${supplierTypeId}`
];
} else {
+ console.log({ itemPostingGroupId, supplierTypeId });
const purchasingPostingGroup = await getPurchasingPostingGroup(
client,
+ companyId,
{
itemPostingGroupId,
supplierTypeId,
diff --git a/packages/database/supabase/functions/shared/get-posting-group.ts b/packages/database/supabase/functions/shared/get-posting-group.ts
index 2011fcec5a..922667ceb0 100644
--- a/packages/database/supabase/functions/shared/get-posting-group.ts
+++ b/packages/database/supabase/functions/shared/get-posting-group.ts
@@ -3,12 +3,16 @@ import { Database } from "../lib/types.ts";
export async function getInventoryPostingGroup(
client: SupabaseClient<Database>,
+ companyId: string,
args: {
itemPostingGroupId: string | null;
locationId: string | null;
}
) {
- let query = client.from("postingGroupInventory").select("*");
+ let query = client
+ .from("postingGroupInventory")
+ .select("*")
+ .eq("companyId", companyId);
if (args.itemPostingGroupId === null) {
query = query.is("itemPostingGroupId", null);
@@ -27,12 +31,16 @@ export async function getInventoryPostingGroup(
export async function getPurchasingPostingGroup(
client: SupabaseClient<Database>,
+ companyId: string,
args: {
itemPostingGroupId: string | null;
supplierTypeId: string | null;
}
) {
- let query = client.from("postingGroupPurchasing").select("*");
+ let query = client
+ .from("postingGroupPurchasing")
+ .select("*")
+ .eq("companyId", companyId);
if (args.itemPostingGroupId === null) {
query = query.is("itemPostingGroupId", null);
@@ -48,3 +56,31 @@ export async function getPurchasingPostingGroup(
return await query.single();
}
+
+export async function getSalesPostingGroup(
+ client: SupabaseClient<Database>,
+ companyId: string,
+ args: {
+ itemPostingGroupId: string | null;
+ customerTypeId: string | null;
+ }
+) {
+ let query = client
+ .from("postingGroupSales")
+ .select("*")
+ .eq("companyId", companyId);
+
+ if (args.itemPostingGroupId === null) {
+ query = query.is("itemPostingGroupId", null);
+ } else {
+ query = query.eq("itemPostingGroupId", args.itemPostingGroupId);
+ }
+
+ if (args.customerTypeId === null) {
+ query = query.is("customerTypeId", null);
+ } else {
+ query = query.eq("customerTypeId", args.customerTypeId);
+ }
+
+ return await query.single();
+}