Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4d819a87

Von Sven Schöling vor fast 2 Jahren hinzugefügt

  • ID 4d819a8783f132b9eca8c81099adb50c9d0df4c1
  • Vorgänger 34b81691
  • Nachfolger fd069f37

CVar + PriceRule: anlegen/editieren/speichern im Preisregel Controller

Im Moment erlaubt sind alle CVar configs, die:

- irgendwie im Beleg erreichbar sind (alle module ausser Pflichtenhefte)
- und von einem Typ sind die mit dem bestehenden Preisregelsystem
abgebildet werden können. d.h.:

- id mit Picker (part, customer, vendor)
- numerisch (number, integer)
- datetime (date, timestamp)
- und weil Jan das direkt braucht: selectboxen

Unterschiede anzeigen:

SL/Controller/PriceRule.pm
17 17

  
18 18
use Rose::Object::MakeMethods::Generic
19 19
(
20
 'scalar --get_set_init' => [ qw(models price_rule vc pricegroups partsgroups businesses cvar) ],
20
 'scalar --get_set_init' => [ qw(models price_rule vc pricegroups partsgroups businesses cvar_configs) ],
21 21
);
22 22

  
23 23
# __PACKAGE__->run_before('check_auth');
......
80 80
sub action_add_item_row {
81 81
  my ($self, %params) = @_;
82 82

  
83
  my $item = SL::DB::PriceRuleItem->new(type => $::form->{type});
83
  my $item = $::form->{type} =~ m{cvar/(\d+)}
84
    ? SL::DB::PriceRuleItem->new(type => 'cvar', custom_variable_configs_id => $1)
85
    : SL::DB::PriceRuleItem->new(type => $::form->{type});
84 86

  
85 87
  my $html = $self->render('price_rule/item', { output => 0 }, item => $item);
86 88

  
......
235 237
}
236 238

  
237 239
sub all_price_rule_item_types {
238
  SL::DB::Manager::PriceRuleItem->get_all_types($_[0]->vc || $_[0]->price_rule->type);
240
  my $item_types = SL::DB::Manager::PriceRuleItem->get_all_types($_[0]->vc || $_[0]->price_rule->type);
241
  my @cvar_types = map [ "cvar/" . $_->id, $_->presenter->description_with_module ], @{$_[0]->cvar_configs };
242

  
243
  [ @$item_types, @cvar_types ];
239 244
}
240 245

  
241 246
sub add_javascripts  {
......
255 260

  
256 261
  my @items;
257 262
  for my $raw_item (@$items) {
258
    my $item = $raw_item->{id} ? $old_items{ $raw_item->{id} } || SL::DB::PriceRuleItem->new(id => $raw_item->{id})->load : SL::DB::PriceRuleItem->new;
263
    my $item = $raw_item->{id}
264
      ? $old_items{ $raw_item->{id} } || SL::DB::PriceRuleItem->new(id => $raw_item->{id})->load
265
      : SL::DB::PriceRuleItem->new;
259 266
    $item->assign_attributes(%$raw_item);
260 267
    push @items, $item;
261 268
  }
......
281 288
  SL::DB::Manager::PartsGroup->get_all;
282 289
}
283 290

  
284
sub init_cvar {
285
  # SL::DB::Manager::CustomVariableConfig->get_all_sorted(where => [ module => 'IC' ]);
286
  # proof of concept: hard coded for articlegroup
287
  SL::DB::Manager::CustomVariableConfig->get_first(where => [ module => 'IC', name => 'articlegroup' ]) ;
291
sub init_cvar_configs {
292
  # eligible cvars for this are all that are reachable from a record or recorditem (all modules but requirement spec)
293
  # and of a type that price rules support (currently: id-based with picker, numeric or date) and by special request select
294
  SL::DB::Manager::CustomVariableConfig->get_all(where => [
295
    "!module" => 'RequirementSpecs',
296
    type => [ qw(timestamp date number integer customer vendor part select) ],
297
  ]) ;
288 298
}
289 299

  
290 300

  
SL/DB/PriceRuleItem.pm
99 99
  SL::DB::Pricegroup->load_cached($_[0]->value_int);
100 100
}
101 101

  
102
sub cvar_config {
103
  die "not a cvar price rule item" unless $_[0]->type eq 'cvar';
104
  &custom_variable_configs
105
}
106

  
102 107
sub full_description {
103 108
  my ($self) = @_;
104 109

  
SL/Presenter/CustomVariableConfig.pm
1
package SL::Presenter::CustomVariableConfig;
2

  
3
use strict;
4

  
5
use SL::Presenter::EscapedText qw(escape is_escaped);
6
use SL::Locale::String qw(t8);
7

  
8
use Exporter qw(import);
9
our @EXPORT_OK = qw(cvar_config_description_with_module);
10

  
11
our %t8 = (
12
  CT                => t8('Customers and vendors'),
13
  Contacts          => t8('Contact persons'),
14
  IC                => t8('Parts, services and assemblies'),
15
  Projects          => t8('Projects'),
16
  RequirementSpecs  => t8('Requirement Specs'),
17
  ShipTo            => t8('Shipping Address'),
18
);
19

  
20

  
21
sub cvar_config_description_with_module {
22
  my ($cvar_config) = @_;
23

  
24
  my $module = $t8{$cvar_config->module};
25
  my $description = $cvar_config->description;
26

  
27
  escape("($module) $description");
28
}
29

  
30
sub description_with_module {
31
  goto &cvar_config_description_with_module;
32
}
33

  
34

  
35
1;
templates/webpages/price_rule/item.html
17 17
<a class='price_rule_remove_line interact cursor-pointer'>✘</a>
18 18
[% L.hidden_tag('price_rule.items[+].id', item.id) %]
19 19
[% L.hidden_tag('price_rule.items[].type', item.type) %]
20
[% L.hidden_tag('price_rule.items[].custom_variable_configs_id', item.custom_variable_configs_id) %]
20 21
[%- SWITCH item.type %]
21 22
  [% CASE 'part' %]
22 23
    [% 'Part' | $T8 %] [% 'is' | $T8 %] [% P.part.picker('price_rule.items[].value_int', item.part) %]
......
37 38
  [% CASE 'pricegroup' %]
38 39
    [% 'Pricegroup' | $T8 %] [% 'is' | $T8 %] [% L.select_tag('price_rule.items[].value_int', SELF.pricegroups, title_key='pricegroup', default=item.value_int) %]
39 40
  [% CASE 'cvar' %]
40
  [% # Dumper.dump_html(SELF.cvar.processed_options) %]
41
    [% 'Custom Variables' | $T8 %] [% 'is' | $T8 %] [% L.select_tag('price_rule.items[].custom_variable_configs_id', SELF.cvar, title_key='description', default=item.custom_variable_configs_id ) %] [% 'with value' | $T8 %]  [% L.select_tag('price_rule.items[].value_text', SELF.cvar.processed_options, title_key='options', default=item.value_text ) %]
42

  
41
    [% # Dumper.dump_html(SELF.cvar.processed_options) %]
42
    [% SET cvar_config = item.cvar_config %]
43
    [% SET description = cvar_config.description %]
44
    [% SWITCH cvar_config.type %]
45
      [% CASE 'timestamp' %]
46
        [% description | html %] [% L.select_tag('price_rule.items[].op', date_compare_ops, default=item.op) %] [% L.date_tag('price_rule.items[].value_date', item.value_date) %]
47
      [% CASE 'date' %]
48
        [% description | html %] [% L.select_tag('price_rule.items[].op', date_compare_ops, default=item.op) %] [% L.date_tag('price_rule.items[].value_date', item.value_date) %]
49
      [% CASE 'number' %]
50
        [% description | html %] [% L.select_tag('price_rule.items[].op', num_compare_ops, default=item.op) %] [% L.input_tag('price_rule.items[].value_num_as_number', item.value_num_as_number) %]
51
      [% CASE 'integer' %]
52
        [% description | html %] [% L.select_tag('price_rule.items[].op', num_compare_ops, default=item.op) %] [% L.input_tag('price_rule.items[].value_num_as_number', item.value_num_as_number) %]
53
      [% CASE 'customer' %]
54
        [% description | html %] [% 'is' | $T8 %] [% P.customer_vendor.picker('price_rule.items[].value_int', item.customer, type='customer') %]
55
      [% CASE 'vendor' %]
56
        [% description | html %] [% 'is' | $T8 %] [% P.customer_vendor.picker('price_rule.items[].value_int', item.vendor, type='vendor') %]
57
      [% CASE 'part' %]
58
        [% description | html %] [% 'is' | $T8 %] [% P.part.picker('price_rule.items[].value_int', item.part) %]
59
      [% CASE 'select' %]
60
        [% description | html %] [% 'is' | $T8 %] [% L.select_tag('price_rule.items[].value_text', cvar_config.processed_options, title_key='options', default=item.value_text ) %]
61
    [% END %]
43 62
  [% CASE %]
44 63
[%- END %]
45 64
</div>

Auch abrufbar als: Unified diff