From 777fcbae77388b399b95df6da4e5b577bb386545 Mon Sep 17 00:00:00 2001 From: Bernd Bestel Date: Sun, 20 Feb 2022 17:07:22 +0100 Subject: [PATCH] Use products stock QU for product_barcodes when empty (references #1794) --- migrations/0170.sql | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 migrations/0170.sql diff --git a/migrations/0170.sql b/migrations/0170.sql new file mode 100644 index 00000000..fb34805d --- /dev/null +++ b/migrations/0170.sql @@ -0,0 +1,19 @@ +CREATE TRIGGER default_qu_INS AFTER INSERT ON product_barcodes +BEGIN + UPDATE product_barcodes + SET qu_id = (SELECT qu_id_stock FROM products WHERE id = product_barcodes.product_id) + WHERE id = NEW.id + AND IFNULL(qu_id, 0) = 0; +END; + +CREATE TRIGGER default_qu_UPD AFTER UPDATE ON product_barcodes +BEGIN + UPDATE product_barcodes + SET qu_id = (SELECT qu_id_stock FROM products WHERE id = product_barcodes.product_id) + WHERE id = NEW.id + AND IFNULL(qu_id, 0) = 0; +END; + +UPDATE product_barcodes +SET qu_id = (SELECT qu_id_stock FROM products WHERE id = product_barcodes.product_id) +WHERE IFNULL(qu_id, 0) = 0;