1 package SL::DB::AdditionalBillingAddress;
 
   5 use SL::DB::MetaSetup::AdditionalBillingAddress;
 
   6 use SL::DB::Manager::AdditionalBillingAddress;
 
   8 __PACKAGE__->meta->initialize;
 
  10 __PACKAGE__->after_save('_after_save_ensure_only_one_marked_as_default_per_customer');
 
  12 sub _after_save_ensure_only_one_marked_as_default_per_customer {
 
  15   if ($self->id && $self->customer_id && $self->default_address) {
 
  16     SL::DB::Manager::AdditionalBillingAddress->update_all(
 
  17       set   => { default_address => 0 },
 
  19         customer_id => $self->customer_id,
 
  30   my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(name street)),
 
  41   return unless $self->id;
 
  43   require SL::DB::Order;
 
  44   require SL::DB::Invoice;
 
  45   require SL::DB::DeliveryOrder;
 
  47   my %args = (query => [ billing_address_id => $self->id ]);
 
  49   return SL::DB::Manager::Invoice->get_all_count(%args)
 
  50       || SL::DB::Manager::Order->get_all_count(%args)
 
  51       || SL::DB::Manager::DeliveryOrder->get_all_count(%args);
 
  55   $_[0]->customer_id(undef);