Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 697fe153

Von Sven Schöling vor etwa 1 Jahr hinzugefügt

  • ID 697fe1534459a1e3204ef316400bcb208a9cb02a
  • Vorgänger d45d7473
  • Nachfolger 6fbd8a07

CVar + PriceRule: Manager Logik und Tests

Implementiert sind jetzt die CVar typen:
- select
- part
- customer
- vendor
- number
- date

nicht unterstützt sind:
- text
- textfield
- bool

unterstützt werden alle module:
- IC
- CT (customer und vendor, unabhängig ob der Beleg customer oder vendor
hat)
- Projects (am recorditem.project oder record.globalproject als fallback)
- Contacts (nur wenn direkt im record gesetzt)

Unterschiede anzeigen:

SL/DB/Manager/PriceRuleItem.pm
32 32
  { type => 'pricegroup', description => t8('Pricegroup'),         customer => 1, vendor => 1, data_type => 'int',  data => sub { $_[1]->pricegroup_id }, exclude_nulls => 1 },
33 33
  { type => 'partsgroup', description => t8('Partsgroup'),         customer => 1, vendor => 1, data_type => 'int',  data => sub { $_[1]->part->partsgroup_id }, exclude_nulls => 1 },
34 34
  { type => 'qty',        description => t8('Qty'),                customer => 1, vendor => 1, data_type => 'num',  data => sub { $_[1]->qty }, ops => 'num' },
35
  { type => 'cvar',       description => t8('Custom Variables'),   customer => 1, vendor => 1, data_type => 'int',  data => sub { $_[1]->part->cvar_by_name('articlegroup')->id }, exclude_nulls => 1 },
36 35
);
37 36

  
38 37
# ITEM.part.cvar_by_name(var.config.name)
......
86 85
# we only generate cvar types for cvar price_rules that are actually used to keep the query smaller
87 86
# these are cached per request
88 87
sub generate_cvar_types {
89
  my $cvar_configs = SL::DB::Manager::CustomVariableConfig->get_all(query => [
90
    id => [ \"(select distinct custom_variable_configs_id from price_rule_items where custom_variable_configs_id is not null)" ]
91
  ]);
88
  my $cvar_configs = SL::DB::Manager::CustomVariableConfig->get_all;
92 89

  
93 90
  my @types;
94 91

  
92
  # text, textfield, bool are not supported
93
  my %price_rule_type_by_cvar_type = (
94
    select    => 'text',
95
    customer  => 'int',
96
    vendor    => 'int',
97
    part      => 'int',
98
    number    => 'num',
99
    date      => 'date',
100
  );
101

  
102
  my %ops_by_cvar_type = (
103
    number    => 'num',
104
    date      => 'date',
105
  );
106

  
95 107
  for my $config (@$cvar_configs) {
108
    # cvars can be pretty complicated, but most of that luckily doesn't affect price rule filtering:
109
    #   - editable flags are copied to submodule entries - so those need to be preferred
110
    #   - cvars may be invalid - but in that case they just won't get crated so we won't find any
111
    #   - cvars may be restricted to partgroups, but again, in that case we simply won't find any
112
    #   - cvars may have different types of values () just like price_rule_items, but the ->value
113
    #     accessor already handles that, so we only need to set the price_rule type accordingly
114

  
115

  
116
    my %data_by_module = (
117
      IC => sub {
118
        raw_value(
119
          $config->processed_flags->{editable}
120
            ? $_[1]->cvar_by_name($config->name)->value
121
            : $_[1]->part->cvar_by_name($config->name)->value
122
        );
123
      },
124
      CT => sub {
125
        raw_value(
126
          $_[0]->customervendor->cvar_by_name($config->name)->value
127
        );
128
      },
129
      Projects => sub {
130
        raw_value(
131
          $_[1]->project ? $_[1]->project->cvar_by_name($config->name)->value :
132
          $_[0]->globalproject ? $_[0]->globalproject->cvar_by_name($config->name)->value : undef
133
        );
134
      },
135
      Contacts => sub {
136
        raw_value(
137
          $_[0]->contact ? $_[0]->contact->cvar_by_name($config->name)->value : undef
138
        );
139
      },
140
    );
141

  
142
    my $data_type = $price_rule_type_by_cvar_type{$config->type} or
143
      die "cvar type @{[$config->type]} is not supported in price rules";
144

  
145
    my $ops = $ops_by_cvar_type{$config->type};
96 146

  
97 147
    push @types, {
98 148
      type          => "cvar_" . $config->id,
99 149
      description   => $config->description,
100 150
      customer      => 1,
101 151
      vendor        => 1,
102
      data_type     => 'text',
103
      data          => sub {
104
        $config->processed_flags->{editable}
105
          ? $_[1]->cvar_by_name($config->name)->value
106
          : $_[1]->part->cvar_by_name($config->name)->value
107
      },
152
      data_type     => $data_type,
153
      data          => $data_by_module{$config->module},
108 154
      exclude_nulls => 1,
109 155
      cvar_config   => $config->id,
110
    } if $config->module eq 'IC' && $config->type eq 'select';
111

  
156
      ops           => $ops,
157
    };
112 158
  }
113 159

  
114 160
  @types;
115 161
}
116 162

  
163
sub raw_value {
164
  my ($value) = @_;
165
  return if !defined $value;
166
  return $value->id if (ref $value) =~ /Part|Customer|Contact|Vendor|Project/;
167
  return $value if (ref $value) =~ /DateTime/;
168
  die "reference value unsupported for binding to price_rules, got ref " . ref $value if ref $value;
169
  $value;
170
}
171

  
117 172
sub get_all_types {
118 173
  my ($class, $vc) = @_;
119 174

  

Auch abrufbar als: Unified diff