From 83b3c64ecfdbcd1c3dc1e1586af1260bc0917aeb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 25 Nov 2014 14:29:02 +0100 Subject: [PATCH] CustomerVendor-Controller: Daten in Neu-Anzeige bei Fehler beibehalten MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit RDBO hat das Verhalten, dass bei einem neuen, noch nicht gespeicherten Objekt die Methoden zum Hinzufügen von Relationship-Objekten (z.B. in 1:n-Beziehnungen wie $customer->add_contacts(…)) beim danach erfolgenden Auslesen der Beziehung nicht zurückliefert. Das heißt, dass Folgendes der Fall ist: my $customer = SL::DB::Customer->new; $customer->add_contacts(SL::DB::Contacts->new); print scalar(@{ $customer->contacts || [] }); # Das hier gibt 0 aus Existiert das Objekt hingegen schon, dann klappt das normal. Das Problem kann man umgehen, indem man beim Anlegen des neuen Objektes die Beziehungen explizit auf eine leere Array-Referenz setzt, damit der in RDBO enthaltene Check an der Stelle greift. Das betrifft den Workflow, wenn man Daten in den benutzerdefinierten Variablen eingibt, auf Speichern drückt und kivitendo dann wegen eines fehlgeschlagenen Checks die Maske erneut anzeigt. --- SL/Controller/CustomerVendor.pm | 37 ++++++++++++------- .../tabs/custom_variables.html | 2 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/SL/Controller/CustomerVendor.pm b/SL/Controller/CustomerVendor.pm index 3e6ad8217..468e02618 100644 --- a/SL/Controller/CustomerVendor.pm +++ b/SL/Controller/CustomerVendor.pm @@ -365,7 +365,7 @@ sub action_delete_contact { } }) || die($db->error); - $self->{contact} = SL::DB::Contact->new(); + $self->{contact} = $self->_new_contact_object; } $self->action_edit(); @@ -679,11 +679,7 @@ sub _instantiate_args { $self->{cv} = SL::DB::Customer->new(id => $::form->{cv}->{id})->load(); } } else { - if ( $self->is_vendor() ) { - $self->{cv} = SL::DB::Vendor->new(); - } else { - $self->{cv} = SL::DB::Customer->new(); - } + $self->{cv} = $self->_new_customer_vendor_object; } $self->{cv}->assign_attributes(%{$::form->{cv}}); @@ -735,7 +731,7 @@ sub _instantiate_args { if ( $::form->{contact}->{cp_id} ) { $self->{contact} = SL::DB::Contact->new(cp_id => $::form->{contact}->{cp_id})->load(); } else { - $self->{contact} = SL::DB::Contact->new(); + $self->{contact} = $self->_new_contact_object; } $self->{contact}->assign_attributes(%{$::form->{contact}}); @@ -786,18 +782,14 @@ sub _load_customer_vendor { die($::locale->text('Error')); } } else { - $self->{contact} = SL::DB::Contact->new(); + $self->{contact} = $self->_new_contact_object; } } sub _create_customer_vendor { my ($self) = @_; - if ( $self->is_vendor() ) { - $self->{cv} = SL::DB::Vendor->new(); - } else { - $self->{cv} = SL::DB::Customer->new(); - } + $self->{cv} = $self->_new_customer_vendor_object; $self->{cv}->currency_id($::instance_conf->get_currency_id()); $self->{note} = SL::DB::Note->new(); @@ -806,7 +798,7 @@ sub _create_customer_vendor { $self->{shipto} = SL::DB::Shipto->new(); - $self->{contact} = SL::DB::Contact->new(); + $self->{contact} = $self->_new_contact_object; } sub _pre_render { @@ -970,4 +962,21 @@ sub init_vendor_models { ); } +sub _new_customer_vendor_object { + my ($self) = @_; + + my $class = 'SL::DB::' . ($self->is_vendor ? 'Vendor' : 'Customer'); + return $class->new( + contacts => [], + shipto => [], + custom_variables => [], + ); +} + +sub _new_contact_object { + my ($self) = @_; + + return SL::DB::Contact->new(custom_variables => []); +} + 1; diff --git a/templates/webpages/customer_vendor/tabs/custom_variables.html b/templates/webpages/customer_vendor/tabs/custom_variables.html index dcd62f091..7b9abf3ad 100644 --- a/templates/webpages/customer_vendor/tabs/custom_variables.html +++ b/templates/webpages/customer_vendor/tabs/custom_variables.html @@ -3,7 +3,7 @@

- [% FOREACH var = cv_cvars %] + [% FOREACH var = SELF.cv.cvars_by_config %] -- 2.20.1
[% var.config.description | html %]