X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FPricegroup.pm;h=eee044fec26d559455d85033550177d5c99dc295;hb=d79f486d76e7bca69d9dfd6720b9bfedc0c87409;hp=8c9c3727e9dc6e4983a3223c6a0781043e0d5c62;hpb=f9676efea9ccfa01df2a57dca9c45cc8fde0d09e;p=kivitendo-erp.git diff --git a/SL/DB/Pricegroup.pm b/SL/DB/Pricegroup.pm index 8c9c3727e..eee044fec 100644 --- a/SL/DB/Pricegroup.pm +++ b/SL/DB/Pricegroup.pm @@ -1,13 +1,64 @@ -# This file has been auto-generated only because it didn't exist. -# Feel free to modify it at will; it will not be overwritten automatically. - package SL::DB::Pricegroup; use strict; use SL::DB::MetaSetup::Pricegroup; +use SL::DB::Manager::Pricegroup; +use SL::DB::Helper::ActsAsList; + +__PACKAGE__->meta->initialize; + +sub displayable_name { + my $self = shift; + + return join ' ', grep $_, $self->id, $self->pricegroup; +} + +sub validate { + my ($self) = @_; + require SL::DB::Customer; + + my @errors; + + if ( $self->obsolete && SL::DB::Manager::Customer->get_all_count(query => [ pricegroup_id => $self->id ]) ) { + push @errors, $::locale->text('The pricegroup is being used by customers.'); + } + + return @errors; +} + +sub orphaned { + my ($self) = @_; + die 'not an accessor' if @_ > 1; + + return 1 unless $self->id; + + my @relations = qw( + SL::DB::Customer + SL::DB::Price + ); + + # check if pricegroup is the default pricegroup for any customers and has any + # prices assigned. + + for my $class (@relations) { + eval "require $class"; + return 0 if $class->_get_manager_class->get_all_count(query => [ pricegroup_id => $self->id ]); + } + + # check if pricegroup was used in any pricesource + my @item_relations = qw( + SL::DB::OrderItem + SL::DB::DeliveryOrderItem + SL::DB::InvoiceItem + ); + + for my $class (@item_relations) { + eval "require $class"; + return 0 if $class->_get_manager_class->get_all_count(query => [ active_price_source => 'pricegroup/' . $self->id ]); + } -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; + return 1; +} 1;