From 6b6a2ddf2b4cfeab9a207313f856b9288bfde270 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Thu, 22 Jan 2015 15:26:33 +0100 Subject: [PATCH] =?utf8?q?Angebots-Position=20mit=20Auftragsposition=20ver?= =?utf8?q?kn=C3=BCpft=20(orderitems=20->=20orderitems)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Angebot -> Workflow Auftrag - from_table -> to_table (tabelleneintrag) i.O. - delete trigger i.O. - mittlere position löschen (vor speichern) i.O. - update sicher in form i.O. ++++++++ - mehrfach speichern (converted* wird nicht gelöscht) n.i.O. --- SL/OE.pm | 10 ++++ bin/mozilla/oe.pl | 2 + ...ecord_links_orderitems_delete_triggers.sql | 46 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql diff --git a/SL/OE.pm b/SL/OE.pm index a60b86c5a..9d6f84962 100644 --- a/SL/OE.pm +++ b/SL/OE.pm @@ -578,6 +578,16 @@ SQL name_prefix => 'ic_', name_postfix => "_$i", dbh => $dbh); + # link quotation items with order items + if ($form->{"converted_from_quotation_orderitems_id_$i"}) { + RecordLinks->create_links('dbh' => $dbh, + 'mode' => 'ids', + 'from_table' => 'orderitems', + 'from_ids' => $form->{"converted_from_quotation_orderitems_id_$i"}, + 'to_table' => 'orderitems', + 'to_id' => $orderitems_id, + ); + } } } # search for orphaned ids diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 904a4b9fe..9a1da4a39 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -1820,6 +1820,7 @@ sub poso { # reset map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered ordnumber); + $form->{"converted_from_quotation_orderitems_id_$_"} = $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"}; # always reset orderitems_id delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"}; # always reset orderitems_id # if purchase_order was generated from sales_order, use lastcost_$i as sellprice_$i @@ -1896,6 +1897,7 @@ sub delivery_order { for my $i (1 .. $form->{rowcount}) { map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice lastcost basefactor discount); + $form->{"converted_from_order_orderitems_id_$_"} = $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"}; } my %old_values = map { $_ => $form->{$_} } qw(customer_id oldcustomer customer vendor_id oldvendor vendor shipto_id); diff --git a/sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql b/sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql new file mode 100644 index 000000000..904f4bb10 --- /dev/null +++ b/sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql @@ -0,0 +1,46 @@ +-- @tag: record_links_orderitems_delete_triggers +-- @description: delete trigger für verknüpfte invoice(items), orderitems und delivery_order_items +-- @depends: record_links_post_delete_triggers2 +CREATE OR REPLACE FUNCTION clean_up_record_links_before_orderitems_delete() RETURNS trigger AS $$ + BEGIN + DELETE FROM record_links + WHERE (from_table = 'orderitems' AND from_id = OLD.id) + OR (to_table = 'orderitems' AND to_id = OLD.id); + RETURN OLD; + END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION clean_up_record_links_before_delivery_order_items_delete() RETURNS trigger AS $$ + BEGIN + DELETE FROM record_links + WHERE (from_table = 'delivery_order_items' AND from_id = OLD.id) + OR (to_table = 'delivery_order_items' AND to_id = OLD.id); + RETURN OLD; + END; +$$ LANGUAGE plpgsql; + +CREATE OR REPLACE FUNCTION clean_up_record_links_before_invoice_delete() RETURNS trigger AS $$ + BEGIN + DELETE FROM record_links + WHERE (from_table = 'invoice' AND from_id = OLD.id) + OR (to_table = 'invoice' AND to_id = OLD.id); + RETURN OLD; + END; +$$ LANGUAGE plpgsql; + + + +CREATE TRIGGER before_delete_orderitems_trigger +BEFORE DELETE ON orderitems FOR EACH ROW EXECUTE +PROCEDURE clean_up_record_links_before_orderitems_delete(); + +CREATE TRIGGER before_delete_delivery_order_items_trigger +BEFORE DELETE ON delivery_order_items FOR EACH ROW EXECUTE +PROCEDURE clean_up_record_links_before_delivery_order_items_delete(); + +CREATE TRIGGER before_delete_invoice_trigger +BEFORE DELETE ON invoice FOR EACH ROW EXECUTE +PROCEDURE clean_up_record_links_before_invoice_delete(); + + + -- 2.20.1