From 2b69a6ac3bb750d39c4a2534d878b546ff649a35 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Wed, 6 Aug 2014 10:07:46 +0200 Subject: [PATCH] Steuerzone: in Upgrade-Datei customer/vendor angepasst MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Macht man eigentlich nachträglich nicht, aber da das Update noch so frisch ist... Beim Umstellen von taxzone wurde vergessen, auch die Einträge der Standardsteuerzone bei den Kunden und Lieferanten anzupassen. Im Zuge der Umstellung, wo bei taxzone keine 0 mehr erlaubt ist, und diese auf 4 umgemapped wurde, müssen auch die hinterlegten Daten bei Kunden und Lieferanten konvertiert werden. In diesem Schritt wurden dann auch gleich Fremdschlüssel für die Steuerzone bei Kunden und Lieferanten angelegt. Ist das Update schon durchgelaufen und muß man manuell nachbessern wären dies die Schritte (unter der Voraussetzung, daß id 0 auch zu id 4 geworden ist): UPDATE customer SET taxzone_id=4 WHERE taxzone_id=0; UPDATE vendor SET taxzone_id=4 WHERE taxzone_id=0; ALTER TABLE customer ALTER COLUMN taxzone_id DROP default; ALTER TABLE vendor ALTER COLUMN taxzone_id DROP default; ALTER TABLE customer ADD FOREIGN KEY (taxzone_id) REFERENCES tax_zones (id); ALTER TABLE vendor ADD FOREIGN KEY (taxzone_id) REFERENCES tax_zones (id); --- SL/DB/MetaSetup/Customer.pm | 7 ++++++- SL/DB/MetaSetup/Vendor.pm | 7 ++++++- sql/Pg-upgrade2/change_taxzone_id_0.pl | 21 ++++++++++++++++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/SL/DB/MetaSetup/Customer.pm b/SL/DB/MetaSetup/Customer.pm index b80211917..deab35bfd 100644 --- a/SL/DB/MetaSetup/Customer.pm +++ b/SL/DB/MetaSetup/Customer.pm @@ -53,7 +53,7 @@ __PACKAGE__->meta->columns( taxincluded => { type => 'boolean' }, taxincluded_checked => { type => 'boolean' }, taxnumber => { type => 'text' }, - taxzone_id => { type => 'integer', default => '0', not_null => 1 }, + taxzone_id => { type => 'integer', not_null => 1 }, terms => { type => 'integer', default => '0' }, user_password => { type => 'text' }, username => { type => 'text' }, @@ -90,6 +90,11 @@ __PACKAGE__->meta->foreign_keys( class => 'SL::DB::PaymentTerm', key_columns => { payment_id => 'id' }, }, + + taxzone => { + class => 'SL::DB::TaxZone', + key_columns => { taxzone_id => 'id' }, + }, ); 1; diff --git a/SL/DB/MetaSetup/Vendor.pm b/SL/DB/MetaSetup/Vendor.pm index 8367137a3..0b57e83f1 100644 --- a/SL/DB/MetaSetup/Vendor.pm +++ b/SL/DB/MetaSetup/Vendor.pm @@ -46,7 +46,7 @@ __PACKAGE__->meta->columns( street => { type => 'text' }, taxincluded => { type => 'boolean' }, taxnumber => { type => 'text' }, - taxzone_id => { type => 'integer', default => '0', not_null => 1 }, + taxzone_id => { type => 'integer', not_null => 1 }, terms => { type => 'integer', default => '0' }, user_password => { type => 'text' }, username => { type => 'text' }, @@ -85,6 +85,11 @@ __PACKAGE__->meta->foreign_keys( class => 'SL::DB::PaymentTerm', key_columns => { payment_id => 'id' }, }, + + taxzone => { + class => 'SL::DB::TaxZone', + key_columns => { taxzone_id => 'id' }, + }, ); 1; diff --git a/sql/Pg-upgrade2/change_taxzone_id_0.pl b/sql/Pg-upgrade2/change_taxzone_id_0.pl index 23b2023d9..3a36f3d75 100644 --- a/sql/Pg-upgrade2/change_taxzone_id_0.pl +++ b/sql/Pg-upgrade2/change_taxzone_id_0.pl @@ -30,14 +30,27 @@ sub run { $query = qq|DELETE FROM tax_zones WHERE id=0|; $self->db_query($query); - #Adapt other tables to the new id: + #Adapt ar/ap and customer/vendor tables to the new taxzone_id $query = qq|UPDATE ar SET taxzone_id=$id WHERE taxzone_id=0|; $self->db_query($query); $query = qq|UPDATE ap SET taxzone_id=$id WHERE taxzone_id=0|; $self->db_query($query); + + $query = qq|UPDATE customer SET taxzone_id=$id WHERE taxzone_id=0|; + $self->db_query($query); + + $query = qq|UPDATE vendor SET taxzone_id=$id WHERE taxzone_id=0|; + $self->db_query($query); } + # Remove default 0 for taxzone_id + $query = qq|ALTER TABLE customer ALTER COLUMN taxzone_id DROP default|; + $self->db_query($query); + + $query = qq|ALTER TABLE vendor ALTER COLUMN taxzone_id DROP default|; + $self->db_query($query); + #Set Constraints: $query = qq|ALTER TABLE ar ADD FOREIGN KEY (taxzone_id) REFERENCES tax_zones (id)|; $self->db_query($query); @@ -45,6 +58,12 @@ sub run { $query = qq|ALTER TABLE ap ADD FOREIGN KEY (taxzone_id) REFERENCES tax_zones (id)|; $self->db_query($query); + $query = qq|ALTER TABLE customer ADD FOREIGN KEY (taxzone_id) REFERENCES tax_zones (id)|; + $self->db_query($query); + + $query = qq|ALTER TABLE vendor ADD FOREIGN KEY (taxzone_id) REFERENCES tax_zones (id)|; + $self->db_query($query); + $sth->finish; return 1; -- 2.20.1