From 3afb9643c43974ac3cbf78406393dcae9ebdec8f Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sat, 5 Aug 2023 18:28:49 +0200 Subject: [PATCH] Fix handling when there are no single edited stock entries at all (references #2292) --- migrations/0225.sql | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 migrations/0225.sql diff --git a/migrations/0225.sql b/migrations/0225.sql new file mode 100644 index 00000000..b7336b6a --- /dev/null +++ b/migrations/0225.sql @@ -0,0 +1,15 @@ +DROP VIEW stock_edited_entries; +CREATE VIEW stock_edited_entries +AS +/* + Returns stock_id's which have been edited manually +*/ +SELECT DISTINCT + IFNULL(sl_add.stock_id, '') AS stock_id, + IFNULL(MAX(sl_edit.id), -1) AS stock_log_id_of_newest_edited_entry +FROM stock_log sl_add +JOIN stock_log sl_edit + ON sl_add.stock_id = sl_edit.stock_id + AND sl_edit.transaction_type = 'stock-edit-new' +WHERE sl_add.transaction_type IN ('purchase', 'inventory-correction', 'self-production') + AND sl_add.amount > 0;