From 12f2bab2096020a8aac37fb8176f6b7ed5cd0e04 Mon Sep 17 00:00:00 2001 From: Sylvain DUVERNAY Date: Tue, 6 Jan 2026 15:57:02 +0100 Subject: [PATCH] Initial Commit --- vw_utility_stock_movements.sql | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 vw_utility_stock_movements.sql diff --git a/vw_utility_stock_movements.sql b/vw_utility_stock_movements.sql new file mode 100644 index 0000000..2e2613d --- /dev/null +++ b/vw_utility_stock_movements.sql @@ -0,0 +1,43 @@ +-- View: public.vw_utility_stock_movements + +-- DROP VIEW public.vw_utility_stock_movements; + +CREATE OR REPLACE VIEW public.vw_utility_stock_movements AS + SELECT sm.id AS "intStockId", + sm.company AS "intCompanyId", + COALESCE(sm.lot, 0) AS "intLotId", + COALESCE(sm.cost_price, 0::numeric) AS "dblCostPrice", + cur.name AS "strCurrency", + sm.effective_date AS "dtmEffectiveDate", + sm.bldate AS "dtmBLDate", + sm.product AS "intProductId", + sm.from_location AS "intFromLocationId", + sm.to_location AS "intToLocationId", + sm.origin, + split_part(sm.origin::text, ','::text, 1) AS "strSourceType", + COALESCE(split_part(sm.shipment::text, ','::text, 2)::integer, 0) AS "intShipmentId", + CASE + WHEN split_part(sm.origin::text, ','::text, 1) = 'purchase.line'::text THEN 'Inbound'::text + WHEN split_part(sm.origin::text, ','::text, 1) = 'sale.line'::text THEN 'Outbound'::text + ELSE 'Unknown'::text + END AS "strMovementType", + CASE + WHEN split_part(sm.origin::text, ','::text, 1) = 'purchase.line'::text THEN split_part(sm.origin::text, ','::text, 2)::integer + ELSE 0 + END AS "intPurchaseLineId", + CASE + WHEN split_part(sm.origin::text, ','::text, 1) = 'sale.line'::text THEN split_part(sm.origin::text, ','::text, 2)::integer + ELSE 0 + END AS "intSaleLineId", + sm.quantity AS "dblQuantity", + uom.name AS "strUnit", + round((sm.quantity * uom.factor)::numeric, get_rounding_position(uom.rounding::numeric)) AS "dblQuantityKg", + sm.unit_price, + sm.unit_price_updated AS "ysnPriceUpdated", + sm.state AS "strState" + FROM stock_move sm + JOIN currency_currency cur ON sm.currency = cur.id + LEFT JOIN product_uom uom ON sm.unit = uom.id; + +ALTER TABLE public.vw_utility_stock_movements + OWNER TO postgres;