mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 17:45:39 +00:00
Prevent adding recipe ingredients with a unit for which no conversion exists (closes #2013)
Wasn't a problem of the web frontend, only possible by externally/manually using the API and not thinking about that that's bullshit.
This commit is contained in:
parent
fa49b449dd
commit
e8f76e5694
25
migrations/0202.sql
Normal file
25
migrations/0202.sql
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
DROP TRIGGER recipes_pos_qu_id_default;
|
||||||
|
CREATE TRIGGER recipes_pos_qu_id_default AFTER INSERT ON recipes_pos
|
||||||
|
BEGIN
|
||||||
|
UPDATE recipes_pos
|
||||||
|
SET qu_id = (SELECT qu_id_stock FROM products where id = product_id)
|
||||||
|
WHERE id = NEW.id
|
||||||
|
AND IFNULL(qu_id, '') = '';
|
||||||
|
|
||||||
|
SELECT CASE WHEN((
|
||||||
|
SELECT 1
|
||||||
|
FROM recipes_pos rp
|
||||||
|
JOIN quantity_unit_conversions_resolved qucr
|
||||||
|
ON qucr.product_id = rp.product_id
|
||||||
|
AND qucr.to_qu_id = rp.qu_id
|
||||||
|
WHERE rp.id = NEW.id
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
-- only_check_single_unit_in_stock = 1 ingredients can have any QU
|
||||||
|
SELECT 1
|
||||||
|
FROM recipes_pos rp
|
||||||
|
WHERE rp.id = NEW.id
|
||||||
|
AND IFNULL(rp.only_check_single_unit_in_stock, 0) = 1
|
||||||
|
) ISNULL) THEN RAISE(ABORT, "Provided qu_id doesn't have a related conversion for that product") END;
|
||||||
|
END;
|
Loading…
x
Reference in New Issue
Block a user