X-Git-Url: http://wagnertech.de/git?p=kivitendo-erp.git;a=blobdiff_plain;f=SL%2FDB%2FPartsGroup.pm;fp=SL%2FDB%2FPartsGroup.pm;h=4a7f607f45da956776e1a11ac0aced0d06cea1ac;hp=ed3c164fe44916bdc9b6227afc971ae49ca28e63;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44 diff --git a/SL/DB/PartsGroup.pm b/SL/DB/PartsGroup.pm index ed3c164fe..4a7f607f4 100644 --- a/SL/DB/PartsGroup.pm +++ b/SL/DB/PartsGroup.pm @@ -6,23 +6,57 @@ package SL::DB::PartsGroup; use strict; use SL::DB::MetaSetup::PartsGroup; +use SL::DB::Manager::PartsGroup; +use SL::DB::Helper::ActsAsList; __PACKAGE__->meta->add_relationship( custom_variable_configs => { type => 'many to many', map_class => 'SL::DB::CustomVariableConfigPartsgroup', }, + parts => { + type => 'one to many', + class => 'SL::DB::Part', + column_map => { id => 'partsgroup_id' }, + }, ); __PACKAGE__->meta->initialize; -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; - sub displayable_name { my $self = shift; 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;