From: Moritz Bunkus Date: Fri, 12 Jul 2013 11:18:56 +0000 (+0200) Subject: Partpicker: Filtermöglichkeit nach konvertierbaren Einheiten ('convertible_unit') X-Git-Tag: release-3.1.0beta1~175^2~1 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=df33875fc30c508b60af9421d0061e66cdc0d55a;p=kivitendo-erp.git Partpicker: Filtermöglichkeit nach konvertierbaren Einheiten ('convertible_unit') --- diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 9b4744e9e..904e6c5c9 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -92,7 +92,7 @@ sub action_part_picker_result { } sub init_parts { - $_[0]->get_models; + $_[0]->get_models(with_objects => [ qw(unit_obj) ]); } 1; diff --git a/SL/DB/Manager/Unit.pm b/SL/DB/Manager/Unit.pm index 8b3c138a8..f081af49e 100644 --- a/SL/DB/Manager/Unit.pm +++ b/SL/DB/Manager/Unit.pm @@ -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; diff --git a/SL/Presenter/Part.pm b/SL/Presenter/Part.pm index 1b81ade4d..1a33a463b 100644 --- a/SL/Presenter/Part.pm +++ b/SL/Presenter/Part.pm @@ -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 only parts with this unit will be used for autocompletion. You may comma separate multiple units as in C. +If C<%params> contains C 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. diff --git a/js/autocomplete_part.js b/js/autocomplete_part.js index 5c6b65a8a..b9ef3e924 100644 --- a/js/autocomplete_part.js +++ b/js/autocomplete_part.js @@ -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,