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.
TypeScript ai-agentsbill-of-materialserpinventory-managementleanmanufacturingmanufacturing-execution-systemmcp-servermesmrpopen-source-erppostgresqlproduction-planningqmsquality-management-systemreact-routerself-hostedsupabasetraceabilitytypescript
fix: use company base currency instead of hardcoded USD in item trigger
neilk1793029830a4e1
diff --git a/packages/database/supabase/migrations/20260212000000_fix-item-sale-price-currency.sql b/packages/database/supabase/migrations/20260212000000_fix-item-sale-price-currency.sqlnew file mode 100644index 0000000000..05e8e7cbab--- /dev/null+++ b/packages/database/supabase/migrations/20260212000000_fix-item-sale-price-currency.sql@@ -0,0 +1,33 @@+-- Fix the create_item_related_records trigger to use the company's+-- baseCurrencyCode instead of hardcoded 'USD'+CREATE OR REPLACE FUNCTION public.create_item_related_records()+RETURNS TRIGGER AS $$+DECLARE+ base_currency TEXT;+BEGIN+ SELECT "baseCurrencyCode" INTO base_currency+ FROM public."company"+ WHERE "id" = new."companyId";++ INSERT INTO public."itemCost"("itemId", "costingMethod", "createdBy", "companyId")+ VALUES (new.id, 'FIFO', new."createdBy", new."companyId");++ INSERT INTO public."itemReplenishment"("itemId", "createdBy", "companyId")+ VALUES (new.id, new."createdBy", new."companyId");++ INSERT INTO public."itemUnitSalePrice"("itemId", "currencyCode", "createdBy", "companyId")+ VALUES (new.id, COALESCE(base_currency, 'USD'), new."createdBy", new."companyId");++ -- Insert itemPlanning records for each location+ INSERT INTO public."itemPlanning"("itemId", "locationId", "createdBy", "companyId")+ SELECT+ new.id,+ l.id,+ new."createdBy",+ new."companyId"+ FROM public."location" l+ WHERE l."companyId" = new."companyId";++ RETURN new;+END;+$$ LANGUAGE plpgsql SECURITY DEFINER;