CREATE OR REPLACE VIEW public.vw_utility_instructed_lots AS WITH stock_move AS ( SELECT DISTINCT mvt_1."intLotId", mvt_1."intShipmentId", mvt_1."dblQuantity", mvt_1."strUnit", mvt_1."dblQuantityKg" FROM vw_utility_stock_movements mvt_1 WHERE ((1 = 1) AND (mvt_1."strMovementType" = ANY (ARRAY['Inbound'::text, 'Dropship'::text]))) ) SELECT mvt."intLotId", mvt."intShipmentId", lot."intPurchaseLineId", mvt."dblQuantity", mvt."strUnit", mvt."dblQuantityKg", lot."intSaleLineId" FROM ((stock_move mvt JOIN vw_utility_shipment_in spt ON ((mvt."intShipmentId" = spt."intShipmentId"))) JOIN vw_utility_lot lot ON ((mvt."intLotId" = lot."intLotId"))) WHERE ((1 = 1) AND ((spt."strState")::text = 'draft'::text));;