X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/kivitendo-erp.git/blobdiff_plain/4ad8ecea0ba37ba748bb16b347a097e407c864d7..7cd6d451d97d1f1e7f3c0f9db2de03735dc8c8f0:/SL/DB/PartsGroup.pm diff --git a/SL/DB/PartsGroup.pm b/SL/DB/PartsGroup.pm index f40c5de96..d6122949c 100644 --- a/SL/DB/PartsGroup.pm +++ b/SL/DB/PartsGroup.pm @@ -7,6 +7,7 @@ use strict; use SL::DB::MetaSetup::PartsGroup; use SL::DB::Manager::PartsGroup; +use SL::DB::Helper::ActsAsList; __PACKAGE__->meta->add_relationship( custom_variable_configs => { @@ -23,4 +24,34 @@ sub displayable_name { return join ' ', grep $_, $self->id, $self->partsgroup; } +sub validate { + my ($self) = @_; + require SL::DB::Customer; + + my @errors; + + push @errors, $::locale->text('The description is missing.') if $self->id and !$self->partsgroup; + + return @errors; +} + +sub orphaned { + my ($self) = @_; + die 'not an accessor' if @_ > 1; + + return 1 unless $self->id; + + my @relations = qw( + SL::DB::Part + SL::DB::CustomVariableConfigPartsgroup + ); + + for my $class (@relations) { + eval "require $class"; + return 0 if $class->_get_manager_class->get_all_count(query => [ partsgroup_id => $self->id ]); + } + + return 1; +} + 1;