Also consider opened products for minimum stock amounts (optionally, but by default) (closes #353)

This commit is contained in:
Bernd Bestel
2019-09-19 18:11:03 +02:00
parent cbf1d1ca40
commit a4d479d047
4 changed files with 33 additions and 3 deletions

13
migrations/0086.sql Normal file
View File

@@ -0,0 +1,13 @@
CREATE VIEW stock_missing_products_including_opened
AS
SELECT
p.id,
MAX(p.name) AS name,
p.min_stock_amount - (IFNULL(SUM(s.amount), 0) - IFNULL(SUM(s.amount_opened), 0)) AS amount_missing,
CASE WHEN IFNULL(SUM(s.amount), 0) > 0 THEN 1 ELSE 0 END AS is_partly_in_stock
FROM products p
LEFT JOIN stock_current s
ON p.id = s.product_id
WHERE p.min_stock_amount != 0
GROUP BY p.id
HAVING IFNULL(SUM(s.amount), 0) - IFNULL(SUM(s.amount_opened), 0) < p.min_stock_amount;