X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=SL%2FDB%2FAdditionalBillingAddress.pm;h=c6ffad4da406347457a655faa88a4ff9c687dec5;hb=b775c378552e6b5bf59f98046cdf4e577cd351df;hp=940dce876cd9efa62ecca13226e042a98fe7fccd;hpb=b5b366c932e2a8118cafa0d27432fa268099d419;p=kivitendo-erp.git 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)),