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:
Bernd Bestel 2022-09-30 12:32:39 +02:00
parent fa49b449dd
commit e8f76e5694
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300

25
migrations/0202.sql Normal file
View 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;