]> wagnertech.de Git - kivitendo-erp.git/commitdiff
Partpicker: Filtermöglichkeit nach konvertierbaren Einheiten ('convertible_unit')
authorMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 12 Jul 2013 11:18:56 +0000 (13:18 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Fri, 12 Jul 2013 11:36:52 +0000 (13:36 +0200)
SL/Controller/Part.pm
SL/DB/Manager/Unit.pm
SL/Presenter/Part.pm
js/autocomplete_part.js

index 9b4744e9e6bebdb8cf8ae2fcc6e53cf2a175dfde..904e6c5c9caa123e14afa196055a31a426fbcc55 100644 (file)
@@ -92,7 +92,7 @@ sub action_part_picker_result {
 }
 
 sub init_parts {
-  $_[0]->get_models;
+  $_[0]->get_models(with_objects => [ qw(unit_obj) ]);
 }
 
 1;
index 8b3c138a8852d08aa8ba19bd970c6d3d651d1c39..f081af49ee8ba6d4aa1bcfa86c6ad33b4abc1b60 100644 (file)
@@ -6,10 +6,17 @@ use SL::DB::Helper::Manager;
 use base qw(SL::DB::Helper::Manager);
 
 use SL::DB::Helper::Sorted;
+use SL::DB::Helper::Filtered;
 
 sub object_class { 'SL::DB::Unit' }
 
 __PACKAGE__->make_manager_methods;
+__PACKAGE__->add_filter_specs(
+  convertible_to => sub {
+    my ($key, $value, $prefix) = @_;
+    return __PACKAGE__->convertible_to_filter($key, $value, $prefix);
+  },
+);
 
 sub _sort_spec {
   return ( default => [ 'sortkey', 1 ],
@@ -18,4 +25,20 @@ sub _sort_spec {
                       });
 }
 
+sub convertible_to_filter {
+  my ($class, $key, $unit_name, $prefix) = @_;
+
+  return () unless $unit_name;
+
+  $prefix //= '';
+
+  my $unit = $class->find_by(name => $unit_name);
+  if (!$unit) {
+    $::lxdebug->warn("Unit manager: No unit with name $unit_name");
+    return ();
+  }
+
+  return ("${prefix}name" => [ map { $_->name } @{ $unit->convertible_units } ]);
+}
+
 1;
index 1b81ade4d50e63aa25d0fcb9af5c45e2a3608d3c..1a33a463bb01bb4a8b8da7151ac17d8889855bfb 100644 (file)
@@ -15,7 +15,7 @@ sub part_picker {
 
   my $ret =
     $self->input_tag($name, (ref $value && $value->can('id') ? $value->id : ''), class => 'part_autocomplete', type => 'hidden', id => $id) .
-    join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(column type unit)) .
+    join('', map { $params{$_} ? $self->input_tag("", delete $params{$_}, id => "${id}_${_}", type => 'hidden') : '' } qw(column type unit convertible_unit)) .
     $self->input_tag("", (ref $value && $value->can('description')) ? $value->description : '', id => "${id}_name", %params);
 
   $self->html_tag('span', $ret, class => 'part_picker');
@@ -63,6 +63,9 @@ If C<%params> contains C<unit> only parts with this unit will be used
 for autocompletion. You may comma separate multiple units as in
 C<h,min>.
 
+If C<%params> contains C<convertible_unit> only parts with a unit
+that's convertible to unit will be used for autocompletion.
+
 Obsolete parts will by default not displayed for selection. However they are
 accepted as default values and can persist during updates. As with other
 selectors though, they are not selectable once overridden.
index 5c6b65a8a40507fde9647538d1857a4babc3078f..b9ef3e92476cd7f0cb60d1db8ebb62f6eb90bcba 100644 (file)
@@ -13,6 +13,7 @@ namespace('kivi', function(k){
     var $dummy  = $('#' + real_id + '_name');
     var $type   = $('#' + real_id + '_type');
     var $unit   = $('#' + real_id + '_unit');
+    var $convertible_unit = $('#' + real_id + '_convertible_unit');
     var $column = $('#' + real_id + '_column');
     var state   = STATES.PICKED;
     var last_real = $real.val();
@@ -32,7 +33,8 @@ namespace('kivi', function(k){
       var data = {
         'filter.all:substr::ilike': term,
         'filter.obsolete': 0,
-        column:   $column.val()===undefined ? '' : $column.val(),
+        'filter.unit_obj.convertible_to': $convertible_unit && $convertible_unit.val() ? $convertible_unit.val() : '',
+        column:   $column && $column.val() ? $column.val() : '',
         current:  $real.val(),
       };
 
@@ -154,6 +156,7 @@ namespace('kivi', function(k){
       dummy:          function() { return $dummy },
       type:           function() { return $type },
       unit:           function() { return $unit },
+      convertible_unit: function() { return $convertible_unit },
       column:         function() { return $column },
       update_results: update_results,
       set_item:       set_item,