Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / sql / Pg-upgrade2 / payment_terms_for_invoices.sql
diff --git a/sql/Pg-upgrade2/payment_terms_for_invoices.sql b/sql/Pg-upgrade2/payment_terms_for_invoices.sql
new file mode 100644 (file)
index 0000000..6b6653d
--- /dev/null
@@ -0,0 +1,20 @@
+-- @tag: payment_terms_for_invoices
+-- @description: Unterscheidung in Zahlungsbedingungen für Angebote/Aufträge und Rechnungen
+-- @depends: release_3_4_0
+ALTER TABLE payment_terms ADD COLUMN description_long_invoice TEXT;
+UPDATE payment_terms SET description_long_invoice = description_long;
+
+INSERT INTO generic_translations (translation_type, language_id, translation_id, translation)
+SELECT translation_type || '_invoice', language_id, translation_id, translation
+FROM generic_translations
+WHERE translation_type = 'SL::DB::PaymentTerm/description_long';
+
+CREATE OR REPLACE FUNCTION generic_translations_delete_on_payment_terms_delete_trigger()
+RETURNS TRIGGER AS $$
+  BEGIN
+    DELETE FROM generic_translations
+    WHERE (translation_id = OLD.id)
+      AND (translation_type IN ('SL::DB::PaymentTerm/description_long', 'SL::DB::PaymentTerm/description_long_invoice'));
+    RETURN OLD;
+  END;
+$$ LANGUAGE plpgsql;