mirror of
https://github.com/grocy/grocy.git
synced 2025-04-30 10:05:45 +00:00
Revert "Make sure that the view products_last_purchased always returns a row per product, also for not in stock items (references #801)"
This reverts commit 0a3e85dab4917510f5145fbd3fc765c6da8db996. Revert "Make sure that the views products_average_price and products_oldest_stock_unit_price always returns a row per product, also for not in stock items (references #801)" This reverts commit 939b98e470a5b65786ec82bbb342edc9c8715dc5.
This commit is contained in:
parent
9c92ec4748
commit
e91bc0b01b
@ -3,9 +3,9 @@ DROP VIEW products_current_price;
|
|||||||
|
|
||||||
CREATE VIEW products_last_purchased
|
CREATE VIEW products_last_purchased
|
||||||
AS
|
AS
|
||||||
SELECT
|
select
|
||||||
1 AS id, -- Dummy, LessQL needs an id column
|
1 AS id, -- Dummy, LessQL needs an id column
|
||||||
p.id AS product_id,
|
sl.product_id,
|
||||||
sl.amount,
|
sl.amount,
|
||||||
sl.best_before_date,
|
sl.best_before_date,
|
||||||
sl.purchased_date,
|
sl.purchased_date,
|
||||||
@ -13,10 +13,8 @@ SELECT
|
|||||||
sl.qu_factor_purchase_to_stock,
|
sl.qu_factor_purchase_to_stock,
|
||||||
sl.location_id,
|
sl.location_id,
|
||||||
sl.shopping_location_id
|
sl.shopping_location_id
|
||||||
FROM products p
|
FROM stock_log sl
|
||||||
LEFT JOIN stock_log sl
|
JOIN (
|
||||||
ON p.id = sl.product_id
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT
|
SELECT
|
||||||
s1.product_id,
|
s1.product_id,
|
||||||
MAX(s1.id) max_stock_id
|
MAX(s1.id) max_stock_id
|
||||||
@ -34,37 +32,32 @@ SELECT
|
|||||||
WHERE undone = 0
|
WHERE undone = 0
|
||||||
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction')
|
||||||
GROUP BY s1.product_id) sp3
|
GROUP BY s1.product_id) sp3
|
||||||
ON sl.product_id = sp3.product_id
|
ON sl.product_id = sp3.product_id
|
||||||
AND sl.id = sp3.max_stock_id;
|
AND sl.id = sp3.max_stock_id;
|
||||||
|
|
||||||
CREATE VIEW products_average_price
|
CREATE VIEW products_average_price
|
||||||
AS
|
AS
|
||||||
SELECT
|
SELECT
|
||||||
1 AS id, -- Dummy, LessQL needs an id column
|
1 AS id, -- Dummy, LessQL needs an id column
|
||||||
p.id AS product_id,
|
s.product_id,
|
||||||
CASE WHEN s.product_id IS NOT NULL THEN round(sum(s.amount * s.price) / sum(s.amount), 2) ELSE NULL END as price
|
round(sum(s.amount * s.price) / sum(s.amount), 2) as price
|
||||||
FROM products p
|
FROM stock s
|
||||||
LEFT JOIN stock s
|
GROUP BY s.product_id;
|
||||||
ON p.id = s.product_id
|
|
||||||
GROUP BY p.id;
|
|
||||||
|
|
||||||
CREATE VIEW products_oldest_stock_unit_price
|
CREATE VIEW products_oldest_stock_unit_price
|
||||||
AS
|
AS
|
||||||
-- Find oldest best_before_date then oldest purchased_date then make sure to return one stock row using max
|
-- Find oldest best_before_date then oldest purchased_date then make sure to return one stock row using max
|
||||||
SELECT
|
SELECT
|
||||||
1 AS id, -- Dummy, LessQL needs an id column
|
1 AS id, -- Dummy, LessQL needs an id column
|
||||||
p.id AS product_id,
|
sw.product_id,
|
||||||
s.amount,
|
sw.amount,
|
||||||
s.best_before_date,
|
sw.best_before_date,
|
||||||
s.purchased_date,
|
sw.purchased_date,
|
||||||
s.price,
|
sw.price, sw.qu_factor_purchase_to_stock,
|
||||||
s.qu_factor_purchase_to_stock,
|
sw.location_id,
|
||||||
s.location_id,
|
sw.shopping_location_id
|
||||||
s.shopping_location_id
|
FROM stock sw
|
||||||
FROM products p
|
JOIN (
|
||||||
LEFT JOIN stock s
|
|
||||||
ON p.id = s.product_id
|
|
||||||
LEFT JOIN (
|
|
||||||
SELECT
|
SELECT
|
||||||
s1.product_id,
|
s1.product_id,
|
||||||
MIN(s1.id) min_stock_id
|
MIN(s1.id) min_stock_id
|
||||||
@ -88,8 +81,8 @@ SELECT
|
|||||||
AND s1.best_before_date = sp2.oldest_date
|
AND s1.best_before_date = sp2.oldest_date
|
||||||
AND s1.purchased_date = sp2.min_purchased_date
|
AND s1.purchased_date = sp2.min_purchased_date
|
||||||
GROUP BY s1.product_id) sp3
|
GROUP BY s1.product_id) sp3
|
||||||
ON s.product_id = sp3.product_id
|
ON sw.product_id = sp3.product_id
|
||||||
AND s.id = sp3.min_stock_id;
|
AND sw.id = sp3.min_stock_id;
|
||||||
|
|
||||||
DROP VIEW recipes_pos_resolved;
|
DROP VIEW recipes_pos_resolved;
|
||||||
CREATE VIEW recipes_pos_resolved
|
CREATE VIEW recipes_pos_resolved
|
||||||
|
Loading…
x
Reference in New Issue
Block a user