From: G. Richardson Date: Sun, 7 Aug 2016 20:31:43 +0000 (+0200) Subject: SL::DB::Part - neue Methode validate X-Git-Tag: release-3.5.4~1905 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=53d15b75d74b5db63bd41be18be774ecd26d9451;p=kivitendo-erp.git SL::DB::Part - neue Methode validate --- diff --git a/SL/DB/Part.pm b/SL/DB/Part.pm index d336af38d..09fdc0d9e 100644 --- a/SL/DB/Part.pm +++ b/SL/DB/Part.pm @@ -58,6 +58,29 @@ sub _before_save_set_partnumber { return 1; } +sub validate { + my ($self) = @_; + + my @errors; + push @errors, $::locale->text('The partnumber is missing.') unless $self->partnumber; + push @errors, $::locale->text('The unit is missing.') unless $self->unit; + push @errors, $::locale->text('The buchungsgruppe is missing.') unless $self->buchungsgruppen_id or $self->buchungsgruppe; + + unless ( $self->id ) { + push @errors, $::locale->text('The partnumber already exists.') if SL::DB::Manager::Part->get_all_count(where => [ partnumber => $self->partnumber ]); + }; + + if ($self->is_assortment && scalar @{$self->assortment_items} == 0) { + push @errors, $::locale->text('The assortment doesn\'t have any items.'); + } + + if ($self->is_assembly && scalar @{$self->assemblies} == 0) { + push @errors, $::locale->text('The assembly doesn\'t have any items.'); + } + + return @errors; +} + sub is_type { my $self = shift; my $type = lc(shift || '');