From 9a27b8e3a55415b8dfec648c6f51d9f6eb937fde Mon Sep 17 00:00:00 2001 From: Marc Ole Bulling Date: Fri, 27 Mar 2020 14:29:26 +0100 Subject: [PATCH] Added amount value for locations api (#668) --- grocy.openapi.json | 4 ++++ migrations/0099.sql | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/grocy.openapi.json b/grocy.openapi.json index 1f4baac7..be1bdb71 100644 --- a/grocy.openapi.json +++ b/grocy.openapi.json @@ -3547,6 +3547,9 @@ "product_id": { "type": "integer" }, + "amount": { + "type": "integer" + }, "location_id": { "type": "integer" }, @@ -3560,6 +3563,7 @@ "example": { "id": "1", "product_id": "3", + "amount": "2", "location_id": "1", "name": "Fridge" } diff --git a/migrations/0099.sql b/migrations/0099.sql index b79ed372..d35f069e 100644 --- a/migrations/0099.sql +++ b/migrations/0099.sql @@ -10,3 +10,18 @@ ADD shopping_location_id INTEGER; ALTER TABLE stock ADD shopping_location_id INTEGER; + +DROP VIEW stock_current_locations; +CREATE VIEW stock_current_locations +AS +SELECT + 1 AS id, -- Dummy, LessQL needs an id column + s.product_id, + SUM(s.amount) as amount, + s.location_id AS location_id, + l.name AS location_name, + l.is_freezer AS location_is_freezer +FROM stock s +JOIN locations l + ON s.location_id = l.id +GROUP BY s.product_id, s.location_id, l.name;