Fix is_aggregate_amount always 0

This commit is contained in:
fipwmaqzufheoxq92ebc 2020-11-14 12:34:43 +01:00
parent 71f6b38cb2
commit 94878d57ae
No known key found for this signature in database
GPG Key ID: F4DF989490C2ADB7

View File

@ -9,7 +9,7 @@ SELECT
MIN(s.best_before_date) AS best_before_date,
IFNULL((SELECT SUM(amount) FROM stock WHERE product_id = pr.parent_product_id AND open = 1), 0) AS amount_opened,
IFNULL((SELECT SUM(amount) FROM stock WHERE product_id IN (SELECT sub_product_id FROM products_resolved WHERE parent_product_id = pr.parent_product_id) AND open = 1), 0) * IFNULL(qucr.factor, 1) AS amount_opened_aggregated,
CASE WHEN p_sub.parent_product_id IS NOT NULL THEN 1 ELSE 0 END AS is_aggregated_amount
CASE WHEN COUNT(p_sub.parent_product_id) > 0 THEN 1 ELSE 0 END AS is_aggregated_amount
FROM products_resolved pr
JOIN stock s
ON pr.sub_product_id = s.product_id