X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/b5b366c932e2a8118cafa0d27432fa268099d419..a32fcad2cf3fabf15c9dd10ddc83ce703db66ad8:/SL/DB/AdditionalBillingAddress.pm diff --git a/SL/DB/AdditionalBillingAddress.pm b/SL/DB/AdditionalBillingAddress.pm index 940dce876..c6ffad4da 100644 --- a/SL/DB/AdditionalBillingAddress.pm +++ b/SL/DB/AdditionalBillingAddress.pm @@ -7,6 +7,24 @@ use SL::DB::Manager::AdditionalBillingAddress; __PACKAGE__->meta->initialize; +__PACKAGE__->after_save('_after_save_ensure_only_one_marked_as_default_per_customer'); + +sub _after_save_ensure_only_one_marked_as_default_per_customer { + my ($self) = @_; + + if ($self->id && $self->customer_id && $self->default_address) { + SL::DB::Manager::AdditionalBillingAddress->update_all( + set => { default_address => 0 }, + where => [ + customer_id => $self->customer_id, + '!id' => $self->id, + ], + ); + } + + return 1; +} + sub displayable_id { my $self = shift; my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(name street)),