Kundenstammdaten: keine leeren »zusätzliche Rechnungsadressen« erzeugen
authorMoritz Bunkus <m.bunkus@linet.de>
Mon, 21 Feb 2022 09:09:08 +0000 (10:09 +0100)
committerMoritz Bunkus <m.bunkus@linet.de>
Mon, 21 Feb 2022 09:09:08 +0000 (10:09 +0100)
SL/Controller/CustomerVendor.pm
sql/Pg-upgrade2/customer_remove_empty_additional_billing_addresses.sql [new file with mode: 0644]

index 608803a..f9e2515 100644 (file)
@@ -283,7 +283,7 @@ sub _save {
       $self->{shipto}->save(cascade => 1);
     }
 
-    if ($self->is_customer && any { $self->{additional_billing_address}->$_ ne '' } @ADDITIONAL_BILLING_ADDRESS_COLUMNS) {
+    if ($self->is_customer && any { $self->{additional_billing_address}->$_ ne '' } grep { $_ ne 'default_address' } @ADDITIONAL_BILLING_ADDRESS_COLUMNS) {
       $self->{additional_billing_address}->customer_id($self->{cv}->id);
       $self->{additional_billing_address}->save(cascade => 1);
 
diff --git a/sql/Pg-upgrade2/customer_remove_empty_additional_billing_addresses.sql b/sql/Pg-upgrade2/customer_remove_empty_additional_billing_addresses.sql
new file mode 100644 (file)
index 0000000..bb60358
--- /dev/null
@@ -0,0 +1,16 @@
+-- @tag: customer_remove_empty_additional_billing_addresses
+-- @description: Leere »zusätzliche Rechnungsadressen« entfernen
+-- @depends: customer_additional_billing_addresses
+DELETE
+FROM additional_billing_addresses
+WHERE (coalesce(name,         '') = '')
+  AND (coalesce(department_1, '') = '')
+  AND (coalesce(department_2, '') = '')
+  AND (coalesce(contact,      '') = '')
+  AND (coalesce(street,       '') = '')
+  AND (coalesce(zipcode,      '') = '')
+  AND (coalesce(city,         '') = '')
+  AND (coalesce(country,      '') = '')
+  AND (coalesce(email,        '') = '')
+  AND (coalesce(phone,        '') = '')
+  AND (coalesce(fax,          '') = '');