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;
10 __PACKAGE__->before_save('_before_save_remove_customer_pricegroup');
12 sub displayable_name {
15 return join ' ', grep $_, $self->id, $self->pricegroup;
18 sub _before_save_remove_customer_pricegroup {
21 return 1 unless $::form->{SELF}{remove_customer_pricegroup};
23 my %attributes = (pricegroup_id => undef);
24 require SL::DB::Customer;
25 SL::DB::Manager::Customer->update_all(
28 'pricegroup_id' => $self->id,
37 require SL::DB::Customer;
40 if (!$::form->{SELF}{remove_customer_pricegroup} &&
42 SL::DB::Manager::Customer->get_all_count(query => [ pricegroup_id => $self->id ]) ) {
43 push @errors, $::locale->text('The pricegroup is being used by customers.');
51 die 'not an accessor' if @_ > 1;
53 return 1 unless $self->id;
60 # check if pricegroup is the default pricegroup for any customers and has any
63 for my $class (@relations) {
64 eval "require $class";
65 return 0 if $class->_get_manager_class->get_all_count(query => [ pricegroup_id => $self->id ]);
68 # check if pricegroup was used in any pricesource
69 my @item_relations = qw(
71 SL::DB::DeliveryOrderItem
75 for my $class (@item_relations) {
76 eval "require $class";
77 return 0 if $class->_get_manager_class->get_all_count(query => [ active_price_source => 'pricegroup/' . $self->id ]);