From d41acd2d498242ad691ea870fd06690a2fbfb253 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 6 Jan 2014 17:13:28 +0100 Subject: [PATCH] =?utf8?q?Wiedervorlagen=20schlie=C3=9Fen,=20wenn=20dazuge?= =?utf8?q?h=C3=B6rige=20Belege=20geschlossen=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Siehe #2310. --- ...ollow_ups_when_order_is_deleted_closed.sql | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sql/Pg-upgrade2/delete_close_follow_ups_when_order_is_deleted_closed.sql b/sql/Pg-upgrade2/delete_close_follow_ups_when_order_is_deleted_closed.sql index ec96729f9..f22e68216 100644 --- a/sql/Pg-upgrade2/delete_close_follow_ups_when_order_is_deleted_closed.sql +++ b/sql/Pg-upgrade2/delete_close_follow_ups_when_order_is_deleted_closed.sql @@ -74,3 +74,36 @@ FOR EACH ROW EXECUTE PROCEDURE follow_up_delete_when_customer_vendor_is_deleted CREATE TRIGGER vendor_before_delete_clear_follow_ups AFTER DELETE ON vendor FOR EACH ROW EXECUTE PROCEDURE follow_up_delete_when_customer_vendor_is_deleted_trigger(); + +-- ============================================================ + +CREATE OR REPLACE FUNCTION follow_up_close_when_oe_closed_trigger() +RETURNS TRIGGER AS $$ + BEGIN + IF COALESCE(NEW.closed, FALSE) AND NOT COALESCE(OLD.closed, FALSE) THEN + UPDATE follow_ups + SET done = TRUE + WHERE id IN ( + SELECT follow_up_id + FROM follow_up_links + WHERE (trans_id = NEW.id) + AND (trans_type IN ('sales_quotation', 'sales_order', 'sales_delivery_order', + 'request_quotation', 'purchase_order', 'purchase_delivery_order')) + ); + END IF; + + RETURN NEW; + END; +$$ LANGUAGE plpgsql; + +DROP TRIGGER IF EXISTS oe_on_update_close_follow_up ON oe; + +CREATE TRIGGER oe_on_update_close_follow_up +AFTER UPDATE ON oe +FOR EACH ROW EXECUTE PROCEDURE follow_up_close_when_oe_closed_trigger(); + +DROP TRIGGER IF EXISTS delivery_orders_on_update_close_follow_up ON delivery_orders; + +CREATE TRIGGER delivery_orders_on_update_close_follow_up +AFTER UPDATE ON delivery_orders +FOR EACH ROW EXECUTE PROCEDURE follow_up_close_when_oe_closed_trigger(); -- 2.20.1