Show synchronized composition in production orders
This commit is contained in:
@@ -560,8 +560,50 @@ const getOrderById = async (id, client = pool) => {
|
|||||||
)
|
)
|
||||||
ORDER BY component.id
|
ORDER BY component.id
|
||||||
)
|
)
|
||||||
FROM production_order_components component
|
FROM (
|
||||||
WHERE component.production_order_id = po.id
|
SELECT
|
||||||
|
order_component.id,
|
||||||
|
order_component.component_tiny_id,
|
||||||
|
order_component.component_sku,
|
||||||
|
order_component.component_name,
|
||||||
|
order_component.quantity_per_unit,
|
||||||
|
order_component.total_quantity,
|
||||||
|
order_component.unit
|
||||||
|
FROM production_order_components order_component
|
||||||
|
WHERE order_component.production_order_id = po.id
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
-composition_component.id AS id,
|
||||||
|
composition_component.component_tiny_id,
|
||||||
|
composition_component.component_sku,
|
||||||
|
composition_component.component_name,
|
||||||
|
composition_component.quantity_per_unit,
|
||||||
|
composition_component.quantity_per_unit * po.quantity AS total_quantity,
|
||||||
|
composition_component.unit
|
||||||
|
FROM product_composition_components composition_component
|
||||||
|
JOIN product_compositions composition
|
||||||
|
ON composition.id = (
|
||||||
|
SELECT matched_composition.id
|
||||||
|
FROM product_compositions matched_composition
|
||||||
|
WHERE matched_composition.source IN ('manual', 'tiny_olist_v3')
|
||||||
|
AND (
|
||||||
|
matched_composition.finished_tiny_product_id = po.product_sku
|
||||||
|
OR matched_composition.finished_tiny_product_id = po.tiny_id
|
||||||
|
OR matched_composition.external_source_id = po.product_sku
|
||||||
|
OR matched_composition.external_source_id = po.tiny_id
|
||||||
|
OR matched_composition.finished_product_sku = UPPER(po.product_sku)
|
||||||
|
)
|
||||||
|
ORDER BY CASE matched_composition.source WHEN 'manual' THEN 0 ELSE 1 END, matched_composition.id
|
||||||
|
LIMIT 1
|
||||||
|
)
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM production_order_components order_component
|
||||||
|
WHERE order_component.production_order_id = po.id
|
||||||
|
)
|
||||||
|
) component
|
||||||
),
|
),
|
||||||
'[]'::json
|
'[]'::json
|
||||||
) as components,
|
) as components,
|
||||||
@@ -700,8 +742,50 @@ const baseProductionOrderSelect = `
|
|||||||
)
|
)
|
||||||
ORDER BY component.id
|
ORDER BY component.id
|
||||||
)
|
)
|
||||||
FROM production_order_components component
|
FROM (
|
||||||
WHERE component.production_order_id = po.id
|
SELECT
|
||||||
|
order_component.id,
|
||||||
|
order_component.component_tiny_id,
|
||||||
|
order_component.component_sku,
|
||||||
|
order_component.component_name,
|
||||||
|
order_component.quantity_per_unit,
|
||||||
|
order_component.total_quantity,
|
||||||
|
order_component.unit
|
||||||
|
FROM production_order_components order_component
|
||||||
|
WHERE order_component.production_order_id = po.id
|
||||||
|
|
||||||
|
UNION ALL
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
-composition_component.id AS id,
|
||||||
|
composition_component.component_tiny_id,
|
||||||
|
composition_component.component_sku,
|
||||||
|
composition_component.component_name,
|
||||||
|
composition_component.quantity_per_unit,
|
||||||
|
composition_component.quantity_per_unit * po.quantity AS total_quantity,
|
||||||
|
composition_component.unit
|
||||||
|
FROM product_composition_components composition_component
|
||||||
|
JOIN product_compositions composition
|
||||||
|
ON composition.id = (
|
||||||
|
SELECT matched_composition.id
|
||||||
|
FROM product_compositions matched_composition
|
||||||
|
WHERE matched_composition.source IN ('manual', 'tiny_olist_v3')
|
||||||
|
AND (
|
||||||
|
matched_composition.finished_tiny_product_id = po.product_sku
|
||||||
|
OR matched_composition.finished_tiny_product_id = po.tiny_id
|
||||||
|
OR matched_composition.external_source_id = po.product_sku
|
||||||
|
OR matched_composition.external_source_id = po.tiny_id
|
||||||
|
OR matched_composition.finished_product_sku = UPPER(po.product_sku)
|
||||||
|
)
|
||||||
|
ORDER BY CASE matched_composition.source WHEN 'manual' THEN 0 ELSE 1 END, matched_composition.id
|
||||||
|
LIMIT 1
|
||||||
|
)
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM production_order_components order_component
|
||||||
|
WHERE order_component.production_order_id = po.id
|
||||||
|
)
|
||||||
|
) component
|
||||||
),
|
),
|
||||||
'[]'::json
|
'[]'::json
|
||||||
) as components,
|
) as components,
|
||||||
|
|||||||
Reference in New Issue
Block a user