mirror of
https://github.com/grocy/grocy.git
synced 2025-08-20 12:20:22 +00:00
Fixed stock entry Userfield edit handling (fixes #1969)
This commit is contained in:
21
migrations/0196.sql
Normal file
21
migrations/0196.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
DROP TRIGGER userfield_values_special_handling_INS;
|
||||
CREATE TRIGGER userfield_values_special_handling_INS AFTER INSERT ON userfield_values
|
||||
BEGIN
|
||||
-- Entity stock:
|
||||
-- object_id is the transaction_id on insert -> replace it by the corresponding stock_id
|
||||
INSERT OR REPLACE INTO userfield_values
|
||||
(field_id, object_id, value)
|
||||
SELECT uv.field_id, sl.stock_id, uv.value
|
||||
FROM userfield_values uv
|
||||
JOIN stock_log sl
|
||||
ON uv.object_id = sl.transaction_id
|
||||
AND sl.transaction_type IN ('purchase', 'inventory-correction', 'stock-edit-new')
|
||||
WHERE uv.field_id IN (SELECT id FROM userfields WHERE entity = 'stock')
|
||||
AND uv.field_id = NEW.field_id
|
||||
AND uv.object_id = NEW.object_id;
|
||||
|
||||
DELETE FROM userfield_values
|
||||
WHERE field_id IN (SELECT id FROM userfields WHERE entity = 'stock')
|
||||
AND field_id = NEW.field_id
|
||||
AND object_id = NEW.object_id;
|
||||
END;
|
Reference in New Issue
Block a user