1 package SL::DB::Pricegroup;
5 use SL::DB::MetaSetup::Pricegroup;
6 use SL::DB::Manager::Pricegroup;
7 use SL::DB::Helper::ActsAsList;
9 __PACKAGE__->meta->initialize;
11 sub displayable_name {
14 return join ' ', grep $_, $self->id, $self->pricegroup;
19 require SL::DB::Customer;
23 if ( $self->obsolete && SL::DB::Manager::Customer->get_all_count(query => [ pricegroup_id => $self->id ]) ) {
24 push @errors, $::locale->text('The pricegroup is being used by customers.');
32 die 'not an accessor' if @_ > 1;
34 return 1 unless $self->id;
41 # check if pricegroup is the default pricegroup for any customers and has any
44 for my $class (@relations) {
45 eval "require $class";
46 return 0 if $class->_get_manager_class->get_all_count(query => [ pricegroup_id => $self->id ]);
49 # check if pricegroup was used in any pricesource
50 my @item_relations = qw(
52 SL::DB::DeliveryOrderItem
56 for my $class (@item_relations) {
57 eval "require $class";
58 return 0 if $class->_get_manager_class->get_all_count(query => [ active_price_source => 'pricegroup/' . $self->id ]);