Abfangen von leerer warehouse_id bevor Objekt gesucht wird
authorMartin Helmling martin.helmling@octosoft.eu <martin.helmling@octosoft.eu>
Wed, 4 Jan 2017 09:30:20 +0000 (10:30 +0100)
committerMartin Helmling martin.helmling@octosoft.eu <martin.helmling@octosoft.eu>
Wed, 4 Jan 2017 10:19:26 +0000 (11:19 +0100)
Will man kein Default Lager einstellen kommt es zu einem Rose Fehler.
Nun wird verfahren wie wenn Lager nicht gefunden wird.

SL/Controller/Part.pm

index 6b40493..23b4eff 100644 (file)
@@ -457,20 +457,23 @@ sub action_reorder_items {
 sub action_warehouse_changed {
   my ($self) = @_;
 
-  $self->warehouse(SL::DB::Manager::Warehouse->find_by_or_create(id => $::form->{warehouse_id}));
-  die unless ref($self->warehouse) eq 'SL::DB::Warehouse';
-
-  if ( $self->warehouse->id and @{$self->warehouse->bins} ) {
-    $self->bin($self->warehouse->bins->[0]);
-    $self->js
-      ->html('#bin', $self->build_bin_select)
-      ->focus('#part_bin_id');
-  } else {
-    # no warehouse was selected, empty the bin field and reset the id
-    $self->js
-        ->val('#part_bin_id', undef)
-        ->html('#bin', '');
-  };
+  if ($::form->{warehouse_id} ) {
+    $self->warehouse(SL::DB::Manager::Warehouse->find_by_or_create(id => $::form->{warehouse_id}));
+    die unless ref($self->warehouse) eq 'SL::DB::Warehouse';
+
+    if ( $self->warehouse->id and @{$self->warehouse->bins} ) {
+      $self->bin($self->warehouse->bins->[0]);
+      $self->js
+        ->html('#bin', $self->build_bin_select)
+        ->focus('#part_bin_id');
+      return $self->js->render;
+    }
+  }
+
+  # no warehouse was selected, empty the bin field and reset the id
+  $self->js
+       ->val('#part_bin_id', undef)
+       ->html('#bin', '');
 
   return $self->js->render;
 }