Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9d391728

Von Sven Schöling vor mehr als 11 Jahren hinzugefügt

  • ID 9d391728884d035ab7bd1dfbcc3b38e3ecb90de2
  • Vorgänger a6a6121c
  • Nachfolger 21c7e952

Custom Filter 'type' und 'all' für Parts

Unterschiede anzeigen:

SL/DB/Manager/Part.pm
3 3
use strict;
4 4

  
5 5
use SL::DB::Helper::Manager;
6
use SL::DB::Helper::Sorted;
7
use SL::DB::Helper::Paginated;
8
use SL::DB::Helper::Filtered;
6 9
use base qw(SL::DB::Helper::Manager);
7 10

  
8 11
use Carp;
......
12 15
sub object_class { 'SL::DB::Part' }
13 16

  
14 17
__PACKAGE__->make_manager_methods;
18
__PACKAGE__->add_filter_specs(
19
  type => sub {
20
    my ($key, $value, $prefix) = @_;
21
    return __PACKAGE__->type_filter($value, $prefix);
22
  },
23
  all => sub {
24
    my ($key, $value, $prefix) = @_;
25
    return or => [ map { $prefix . $_ => $value } qw(partnumber description) ]
26
  }
27
);
15 28

  
16 29
sub type_filter {
17
  my ($class, $type) = @_;
30
  my ($class, $type, $prefix) = @_;
18 31

  
19 32
  return () unless $type;
20 33

  
34
  $prefix //= '';
35

  
36
  # this is to make selection like type => { part => 1, service => 1 } work
37
  if ('HASH' eq ref $type) {
38
    $type = grep { $type->{$_} } keys %$type;
39
  }
40

  
21 41
  my @types = listify($type);
22 42
  my @filter;
23 43

  
24 44
  for my $type (@types) {
25 45
    if ($type =~ m/^part/) {
26
      push @filter, (and => [ or                    => [ assembly => 0, assembly => undef ],
27
                       '!inventory_accno_id' => 0,
28
                       '!inventory_accno_id' => undef,
46
      push @filter, (and => [ or                    => [ $prefix . assembly => 0, $prefix . assembly => undef ],
47
                       "!${prefix}inventory_accno_id" => 0,
48
                       "!${prefix}inventory_accno_id" => undef,
29 49
                     ]);
30 50
    } elsif ($type =~ m/^service/) {
31
      push @filter, (and => [ or => [ assembly           => 0, assembly           => undef ],
32
                       or => [ inventory_accno_id => 0, inventory_accno_id => undef ],
51
      push @filter, (and => [ or => [ $prefix . assembly           => 0, $prefix . assembly           => undef ],
52
                       or => [ $prefix . inventory_accno_id => 0, $prefix . inventory_accno_id => undef ],
33 53
                     ]);
34 54
    } elsif ($type =~ m/^assembl/) {
35
      push @filter, (assembly => 1);
55
      push @filter, ($prefix . assembly => 1);
36 56
    }
37 57
  }
38 58

  
39
  return @filter ? (or => \@filter) : ();
59
  return @filter > 2 ? (or => \@filter) :
60
         @filter     ? @filter          : ();
40 61
}
41 62

  
42 63
sub get_ordered_qty {

Auch abrufbar als: Unified diff