partpicker mit classification_id als filter erweitert
[kivitendo-erp.git] / SL / Controller / Part.pm
index 2741370..8eb0f83 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;
 }
@@ -488,6 +491,7 @@ sub action_ajax_autocomplete {
       query => [
         obsolete => 0,
         SL::DB::Manager::Part->type_filter($::form->{filter}{part_type}),
+        SL::DB::Manager::PartClassification->classification_filter($::form->{filter}{classification_id}),
         or => [
           description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
           partnumber  => { ilike => $::form->{filter}{'all:substr:multi::ilike'} },
@@ -789,7 +793,7 @@ sub init_models {
       partnumber  => t8('Partnumber'),
       description  => t8('Description'),
     },
-    with_objects => [ qw(unit_obj) ],
+    with_objects => [ qw(unit_obj classification) ],
   );
 }
 
@@ -872,7 +876,8 @@ sub init_all_languages {
 }
 
 sub init_all_partsgroups {
-  SL::DB::Manager::PartsGroup->get_all_sorted;
+  my ($self) = @_;
+  SL::DB::Manager::PartsGroup->get_all_sorted(query => [ or => [ id => $self->part->partsgroup_id, obsolete => 0 ] ]);
 }
 
 sub init_all_buchungsgruppen {
@@ -894,7 +899,8 @@ sub init_all_units {
 }
 
 sub init_all_payment_terms {
-  SL::DB::Manager::PaymentTerm->get_all_sorted;
+  my ($self) = @_;
+  SL::DB::Manager::PaymentTerm->get_all_sorted(query => [ or => [ id => $self->part->payment_id, obsolete => 0 ] ]);
 }
 
 sub init_all_price_factors {
@@ -910,7 +916,7 @@ sub init_multi_items_models {
   SL::Controller::Helper::GetModels->new(
     controller     => $_[0],
     model          => 'Part',
-    with_objects   => [ qw(unit_obj partsgroup) ],
+    with_objects   => [ qw(unit_obj partsgroup classification) ],
     disable_plugin => 'paginated',
     source         => $::form->{multi_items},
     sorted         => {