From 53d15b75d74b5db63bd41be18be774ecd26d9451 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Sun, 7 Aug 2016 22:31:43 +0200 Subject: [PATCH] SL::DB::Part - neue Methode validate --- SL/DB/Part.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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 || ''); -- 2.20.1