Inventory Helper: Bessere Fehlermeldung bei fehlenden Parametern
[kivitendo-erp.git] / SL / Helper / Inventory.pm
index b0dc16e..cd50907 100644 (file)
@@ -57,11 +57,13 @@ sub _get_stock_onhand {
   }
 
   if ($params{date}) {
+    Carp::croak("not DateTime ".$params{date}) unless ref($params{date}) eq 'DateTime';
     push @where, sprintf "shippingdate <= ?";
     push @values, $params{date};
   }
 
   if ($params{bestbefore}) {
+    Carp::croak("not DateTime ".$params{date}) unless ref($params{bestbefore}) eq 'DateTime';
     push @where, sprintf "bestbefore >= ?";
     push @values, $params{bestbefore};
   }
@@ -165,8 +167,17 @@ sub get_onhand {
 sub allocate {
   my (%params) = @_;
 
-  my $part = $params{part} or Carp::croak('allocate needs a part');
-  my $qty  = $params{qty}  or Carp::croak('allocate needs a qty');
+  die SL::X::Inventory::Allocation->new(
+    error => 'allocate needs a part',
+    msg => t8("Method allocate needs the parameter 'part'"),
+  ) unless $params{part};
+  die SL::X::Inventory::Allocation->new(
+    error => 'allocate needs a qty',
+    msg => t8("Method allocate needs the parameter 'qty'"),
+  ) unless $params{qty};
+
+  my $part = $params{part};
+  my $qty  = $params{qty};
 
   return () if $qty <= 0;
 
@@ -279,6 +290,7 @@ sub check_constraints {
       bin_id       => 'bin_id',
       warehouse_id => 'warehouse_id',
       chargenumber => 'chargenumber',
+      reserve_for  => 'reserve_for_id',
     );
 
     for (keys %$constraints ) {
@@ -290,9 +302,10 @@ sub check_constraints {
 
       if (any { !$whitelist{$_->$accessor} } @$allocations) {
         my %error_constraints = (
-          bin_id       => t8('Bins'),
-          warehouse_id => t8('Warehouses'),
-          chargenumber => t8('Chargenumbers'),
+          bin_id         => t8('Bins'),
+          warehouse_id   => t8('Warehouses'),
+          chargenumber   => t8('Chargenumbers'),
+          reserve_for    => t8('Reserve For'),
         );
         my @allocs = grep { $whitelist{$_->$accessor} } @$allocations;
         my $needed = sum map { $_->qty } grep { !$whitelist{$_->$accessor} } @$allocations;