mirror of
https://github.com/grocy/grocy.git
synced 2025-10-14 17:24:07 +00:00
Show more info in product card (closes #173)
This commit is contained in:
26
migrations/0064.sql
Normal file
26
migrations/0064.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
CREATE VIEW stock_average_product_shelf_life
|
||||
AS
|
||||
SELECT
|
||||
p.id,
|
||||
CASE WHEN x.product_id IS NULL THEN -1 ELSE AVG(x.shelf_life_days) END AS average_shelf_life_days
|
||||
FROM products p
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
sl_p.product_id,
|
||||
JULIANDAY(MIN(sl_p.best_before_date)) - JULIANDAY(MIN(sl_c.used_date)) AS shelf_life_days
|
||||
FROM stock_log sl_p
|
||||
JOIN (
|
||||
SELECT
|
||||
product_id,
|
||||
stock_id,
|
||||
MAX(used_date) AS used_date
|
||||
FROM stock_log
|
||||
WHERE transaction_type = 'consume'
|
||||
GROUP BY product_id, stock_id
|
||||
) sl_c
|
||||
ON sl_p.stock_id = sl_c.stock_id
|
||||
WHERE sl_p.transaction_type = 'purchase'
|
||||
GROUP BY sl_p.product_id, sl_p.stock_id
|
||||
) x
|
||||
ON p.id = x.product_id
|
||||
GROUP BY p.id;
|
Reference in New Issue
Block a user