Also update from_qu_id and to_qu_id of inverse unit conversions automatically (closes #1977)

This commit is contained in:
Bernd Bestel
2022-08-24 21:10:22 +02:00
parent 52e2c6d480
commit c396c2a84c
2 changed files with 16 additions and 0 deletions

15
migrations/0199.sql Normal file
View File

@@ -0,0 +1,15 @@
DROP TRIGGER qu_conversions_inverse_UPD;
CREATE TRIGGER qu_conversions_inverse_UPD AFTER UPDATE ON quantity_unit_conversions
BEGIN
/*
Update the inverse QU conversion
*/
UPDATE quantity_unit_conversions
SET factor = 1 / IFNULL(NEW.factor, 1),
from_qu_id = NEW.to_qu_id,
to_qu_id = NEW.from_qu_id
WHERE from_qu_id = OLD.to_qu_id
AND to_qu_id = OLD.from_qu_id
AND IFNULL(product_id, -1) = IFNULL(NEW.product_id, -1);
END;