Dump - ITSA views

This commit is contained in:
AzureAD\SylvainDUVERNAY
2026-06-14 11:05:54 +02:00
parent 3a3e715336
commit af63a53372
27 changed files with 708 additions and 140 deletions

View File

@@ -16,11 +16,11 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
p.reference AS purchase_reference,
pl.id AS purchase_line_id,
pl.finished AS purchase_line_finished,
NULL::integer AS sale_id,
NULL::character varying AS sale_number,
NULL::character varying AS sale_reference,
NULL::integer AS sale_line_id,
NULL::boolean AS sale_line_finished,
s.id AS sale_id,
s.number AS sale_number,
s.reference AS sale_reference,
sl.id AS sale_line_id,
sl.finished AS sale_line_finished,
l.id AS valued_lot_id,
l.lot_type AS valued_lot_type,
NULL::integer AS lot_qt_id,
@@ -33,10 +33,12 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
shi.bl_date,
pl.from_del AS delivery_date_from,
pl.to_del AS delivery_date_to
FROM ((((((purchase_line pl
FROM ((((((((purchase_line pl
JOIN purchase_purchase p ON ((p.id = pl.purchase)))
JOIN lot_lot l ON ((l.line = pl.id)))
JOIN lot_current_qty lcq ON ((lcq.lot_id = l.id)))
LEFT JOIN sale_line sl ON ((sl.id = l.sale_line)))
LEFT JOIN sale_sale s ON ((s.id = sl.sale)))
LEFT JOIN stock_shipment_in shi ON ((shi.id = l.lot_shipment_in)))
LEFT JOIN stock_shipment_internal sint ON ((sint.id = l.lot_shipment_internal)))
LEFT JOIN stock_shipment_out sho ON ((sho.id = l.lot_shipment_out)))
@@ -74,7 +76,9 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
LEFT JOIN stock_shipment_in shi ON ((shi.id = l.lot_shipment_in)))
LEFT JOIN stock_shipment_internal sint ON ((sint.id = l.lot_shipment_internal)))
LEFT JOIN stock_shipment_out sho ON ((sho.id = l.lot_shipment_out)))
WHERE (((pl.type)::text = 'line'::text) AND ((l.lot_type)::text = 'physic'::text))
WHERE (((pl.type)::text = 'line'::text) AND ((l.lot_type)::text = 'physic'::text) AND (NOT (EXISTS ( SELECT 1
FROM purchase_pnl_lots ppl
WHERE ((ppl.valued_lot_id = l.id) AND (ppl.sale_line_id = sl.id))))))
), sale_pnl_matched_virtual_lots AS (
SELECT 'sale'::text AS pnl_side,
p.id AS purchase_id,
@@ -90,7 +94,7 @@ CREATE OR REPLACE VIEW public.vw_utility_trade_pnl_quantities AS
sale_lot.id AS valued_lot_id,
sale_lot.lot_type AS valued_lot_type,
lqt.id AS lot_qt_id,
lcq.pnl_quantity,
lqt.lot_quantity AS pnl_quantity,
lcq.quantity_uom AS quantity_unit,
sl.product AS product_id,
COALESCE(shi.from_location, sint.from_location, sho.from_location, s.from_location) AS from_location_id,