From 0a3e85dab4917510f5145fbd3fc765c6da8db996 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 22 Aug 2020 17:50:08 +0200 Subject: [PATCH] Make sure that the view products_last_purchased always returns a row per product, also for not in stock items (references #801) Otherwise there are errors when getting product details for currently not in stock items... --- migrations/0104.sql | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/migrations/0104.sql b/migrations/0104.sql index d22dd5a2..77e817e6 100644 --- a/migrations/0104.sql +++ b/migrations/0104.sql @@ -3,9 +3,9 @@ DROP VIEW products_current_price; CREATE VIEW products_last_purchased AS -select +SELECT 1 AS id, -- Dummy, LessQL needs an id column - sl.product_id, + p.id AS product_id, sl.amount, sl.best_before_date, sl.purchased_date, @@ -13,8 +13,10 @@ select sl.qu_factor_purchase_to_stock, sl.location_id, sl.shopping_location_id - FROM stock_log sl - JOIN ( + FROM products p + LEFT JOIN stock_log sl + ON p.id = sl.product_id + LEFT JOIN ( SELECT s1.product_id, MAX(s1.id) max_stock_id @@ -32,8 +34,8 @@ select WHERE undone = 0 AND transaction_type in ('purchase', 'stock-edit-new', 'inventory-correction') GROUP BY s1.product_id) sp3 - ON sl.product_id = sp3.product_id - AND sl.id = sp3.max_stock_id; + ON sl.product_id = sp3.product_id + AND sl.id = sp3.max_stock_id; CREATE VIEW products_average_price AS