Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bd389ba9

Von Moritz Bunkus vor fast 11 Jahren hinzugefügt

  • ID bd389ba9a00c3b56958b9c541fa0ca0e6ebcd6bf
  • Vorgänger e680ea8e
  • Nachfolger d41acd2d

Wiedervorlagen löschen, wenn dazugehörige Belege gelöscht werden

Behebt #2310.

Unterschiede anzeigen:

sql/Pg-upgrade2/delete_close_follow_ups_when_order_is_deleted_closed.sql
1
-- @tag: delete_close_follow_ups_when_order_is_deleted_closed
2
-- @description: Wiedervorlagen lößchen/schließen, wenn dazugehörige Belege gelöscht/geschlossen werden
3
-- @depends: release_3_0_0
4

  
5
ALTER TABLE follow_up_links DROP CONSTRAINT follow_up_links_follow_up_id_fkey;
6
ALTER TABLE follow_up_links ADD FOREIGN KEY (follow_up_id) REFERENCES follow_ups (id) ON DELETE CASCADE;
7

  
8
CREATE OR REPLACE FUNCTION follow_up_delete_notes_trigger()
9
RETURNS TRIGGER AS $$
10
  BEGIN
11
    DELETE FROM notes
12
    WHERE (trans_id     = OLD.id)
13
      AND (trans_module = 'fu');
14
    RETURN OLD;
15
  END;
16
$$ LANGUAGE plpgsql;
17

  
18
CREATE OR REPLACE FUNCTION follow_up_delete_when_oe_is_deleted_trigger()
19
RETURNS TRIGGER AS $$
20
  BEGIN
21
    DELETE FROM follow_ups
22
    WHERE id IN (
23
      SELECT follow_up_id
24
      FROM follow_up_links
25
      WHERE (trans_id   = OLD.id)
26
        AND (trans_type IN ('sales_quotation',   'sales_order',    'sales_delivery_order',    'sales_invoice',
27
                            'request_quotation', 'purchase_order', 'purchase_delivery_order', 'purchase_invoice'))
28
    );
29

  
30
    RETURN OLD;
31
  END;
32
$$ LANGUAGE plpgsql;
33

  
34
CREATE OR REPLACE FUNCTION follow_up_delete_when_customer_vendor_is_deleted_trigger()
35
RETURNS TRIGGER AS $$
36
  BEGIN
37
    DELETE FROM follow_ups
38
    WHERE id IN (
39
      SELECT follow_up_id
40
      FROM follow_up_links
41
      WHERE (trans_id   = OLD.id)
42
        AND (trans_type IN ('customer', 'vendor'))
43
    );
44

  
45
    DELETE FROM notes
46
    WHERE (trans_id     = OLD.id)
47
      AND (trans_module = 'ct');
48

  
49
    RETURN OLD;
50
  END;
51
$$ LANGUAGE plpgsql;
52

  
53
-- ============================================================
54

  
55
DROP TRIGGER IF EXISTS follow_up_delete_notes ON follow_ups;
56

  
57
CREATE TRIGGER follow_up_delete_notes
58
AFTER DELETE ON follow_ups
59
FOR EACH ROW  EXECUTE PROCEDURE follow_up_delete_notes_trigger();
60

  
61
DROP TRIGGER IF EXISTS oe_before_delete_clear_follow_ups ON oe;
62

  
63
CREATE TRIGGER oe_before_delete_clear_follow_ups
64
BEFORE DELETE ON oe
65
FOR EACH ROW  EXECUTE PROCEDURE follow_up_delete_when_oe_is_deleted_trigger();
66

  
67
DROP TRIGGER IF EXISTS customer_before_delete_clear_follow_ups ON customer;
68
DROP TRIGGER IF EXISTS vendor_before_delete_clear_follow_ups   ON vendor;
69

  
70
CREATE TRIGGER customer_before_delete_clear_follow_ups
71
AFTER DELETE ON customer
72
FOR EACH ROW  EXECUTE PROCEDURE follow_up_delete_when_customer_vendor_is_deleted_trigger();
73

  
74
CREATE TRIGGER vendor_before_delete_clear_follow_ups
75
AFTER DELETE ON vendor
76
FOR EACH ROW  EXECUTE PROCEDURE follow_up_delete_when_customer_vendor_is_deleted_trigger();

Auch abrufbar als: Unified diff