mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Fixed qu_id_stock change handling when needed conversion is only defined globally (fixes #1974)
This commit is contained in:
parent
06968ac289
commit
dfe9868a48
@ -14,6 +14,7 @@
|
|||||||
- Fixed that consuming a parent product which is not in stock itself (so essentially using any of the child products) may failed when unit conversions were involved (the current stock amount check was wrong in that case)
|
- Fixed that consuming a parent product which is not in stock itself (so essentially using any of the child products) may failed when unit conversions were involved (the current stock amount check was wrong in that case)
|
||||||
- Fixed that the status button counters on the stock overview page ("X products are overdue" and so on) included products which have the option `Never show on stock overview` enabled
|
- Fixed that the status button counters on the stock overview page ("X products are overdue" and so on) included products which have the option `Never show on stock overview` enabled
|
||||||
- Fixed that adding Userfields to existing stock entries was not possible (only editing existing Userfield values, e.g. added during purchase or inventory, was possible)
|
- Fixed that adding Userfields to existing stock entries was not possible (only editing existing Userfield values, e.g. added during purchase or inventory, was possible)
|
||||||
|
- Fixed that it was not possible to change a products stock QU, when the needed unit conversion (old QU => new QU) was only defined globally (means on QU level)
|
||||||
|
|
||||||
### Shopping list
|
### Shopping list
|
||||||
|
|
||||||
|
56
migrations/0197.sql
Normal file
56
migrations/0197.sql
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
DROP TRIGGER cascade_change_qu_id_stock;
|
||||||
|
CREATE TRIGGER cascade_change_qu_id_stock BEFORE UPDATE ON products WHEN NEW.qu_id_stock != OLD.qu_id_stock
|
||||||
|
BEGIN
|
||||||
|
-- All amounts anywhere are related to the products stock QU,
|
||||||
|
-- so apply the appropriate unit conversion to all amounts everywhere on change
|
||||||
|
-- (and enforce that such a conversion need to exist when the product was once added to stock)
|
||||||
|
|
||||||
|
SELECT CASE WHEN((
|
||||||
|
SELECT 1
|
||||||
|
FROM quantity_unit_conversions_resolved
|
||||||
|
WHERE product_id = NEW.id
|
||||||
|
AND from_qu_id = OLD.qu_id_stock
|
||||||
|
AND to_qu_id = NEW.qu_id_stock
|
||||||
|
AND source NOT LIKE '1%'
|
||||||
|
) ISNULL)
|
||||||
|
AND
|
||||||
|
((
|
||||||
|
SELECT 1
|
||||||
|
FROM stock_log
|
||||||
|
WHERE product_id = NEW.id
|
||||||
|
AND NEW.qu_id_stock != OLD.qu_id_stock
|
||||||
|
) NOTNULL) THEN RAISE(ABORT, "qu_id_stock can only be changed when a corresponding QU conversion (old QU => new QU) exists when the product was once added to stock") END;
|
||||||
|
|
||||||
|
UPDATE chores
|
||||||
|
SET product_amount = product_amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0)
|
||||||
|
WHERE product_id = NEW.id;
|
||||||
|
|
||||||
|
UPDATE meal_plan
|
||||||
|
SET product_amount = product_amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0)
|
||||||
|
WHERE type = 'product'
|
||||||
|
AND product_id = NEW.id;
|
||||||
|
|
||||||
|
UPDATE product_barcodes
|
||||||
|
SET amount = amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0)
|
||||||
|
WHERE product_id = NEW.id
|
||||||
|
AND amount IS NOT NULL;
|
||||||
|
|
||||||
|
UPDATE recipes_pos
|
||||||
|
SET amount = amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0)
|
||||||
|
WHERE product_id = NEW.id;
|
||||||
|
|
||||||
|
UPDATE shopping_list
|
||||||
|
SET amount = amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0)
|
||||||
|
WHERE product_id = NEW.id
|
||||||
|
AND product_id IS NOT NULL;
|
||||||
|
|
||||||
|
UPDATE stock
|
||||||
|
SET amount = amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0),
|
||||||
|
price = price / IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0)
|
||||||
|
WHERE product_id = NEW.id;
|
||||||
|
|
||||||
|
UPDATE stock_log
|
||||||
|
SET amount = amount * IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0),
|
||||||
|
price = price / IFNULL((SELECT factor FROM quantity_unit_conversions_resolved WHERE product_id = NEW.id AND from_qu_id = OLD.qu_id_stock AND to_qu_id = NEW.qu_id_stock AND source NOT LIKE '1%'), 1.0)
|
||||||
|
WHERE product_id = NEW.id;
|
||||||
|
END;
|
Loading…
x
Reference in New Issue
Block a user