Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a2dbfe22

Von Tamino Steinert vor 11 Monaten hinzugefügt

  • ID a2dbfe22187f8327bad704c79209c1f297d57c33
  • Vorgänger a6a4f786
  • Nachfolger ab480a51

Varianten: Schnellbearbeitung von Varianten (EAN, Auf Lager)

Unterschiede anzeigen:

SL/Controller/Part.pm
273 273
  }
274 274

  
275 275
  SL::DB->client->with_transaction(sub {
276
    foreach my $variant (@{$self->part->variants}) {
277
      $variant->update_attributes(
278
        description         => $variant_id_to_values{$variant->id}->{description},
279
        listprice_as_number => $variant_id_to_values{$variant->id}->{listprice_as_number},
280
        sellprice_as_number => $variant_id_to_values{$variant->id}->{sellprice_as_number},
281
        lastcost_as_number  => $variant_id_to_values{$variant->id}->{lastcost_as_number},
282
        rop_as_number       => $variant_id_to_values{$variant->id}->{rop_as_number},
283
      );
284
    }
276
    my $new_variant_property;
285 277
    if ($variant_property_id) {
286
      SL::DB::VariantPropertyPart->new(
278
      $new_variant_property = SL::DB::VariantPropertyPart->new(
287 279
        part_id             => $self->part->id,
288 280
        variant_property_id => $variant_property_id,
289 281
      )->save;
290
      foreach my $variant (@{$self->part->variants}) {
282
    }
283
    foreach my $variant (@{$self->part->variants}) {
284
      my $variant_attributes = $variant_id_to_values{$variant->id};
285
      my $variant_property_value_id = delete $variant_attributes->{add_variant_property_value};
286
      delete $variant_attributes->{$_} for qw(id position);
287
      $variant->update_attributes(%$variant_attributes);
288
      if ($new_variant_property) {
291 289
        SL::DB::VariantPropertyValuePart->new(
292 290
          part_id                   => $variant->id,
293
          variant_property_value_id => $variant_id_to_values{$variant->id}->{"add_variant_property_value"},
291
          variant_property_value_id => $variant_property_value_id,
294 292
        )->save;
295 293
      }
296 294
    }
297 295
    1;
298 296
  }) or do {
299
    return $self->js->error(t8('Error while adding variant property: ' . @_))->render();
297
    return $self->js->error(t8('Error while adding variant property: #1', SL::DB->client->error))->render();
300 298
  };
301 299

  
302 300
  $self->redirect_to(
......
882 880
  my %sort_keys = (
883 881
    partnumber       => sub { $_[0]->partnumber },
884 882
    description      => sub { $_[0]->description },
883
    ean              => sub { $_[0]->ean },
884
    listprice        => sub { $_[0]->listprice },
885 885
    sellprice        => sub { $_[0]->sellprice },
886 886
    lastcost         => sub { $_[0]->lastcost },
887
    onhand           => sub { $_[0]->onhand },
888
    rop              => sub { $_[0]->rop },
887 889
    variant_values   => sub { $_[0]->variant_values },
888 890
  );
889 891
  foreach my $variant_property (@{$part->variant_properties}) {
......
902 904
    @{$::form->{variants}};
903 905

  
904 906
  my @to_sort = map { { old_pos => $variant_id_to_position{$_->id}, order_by => $method->($_) } } @items;
905
  if ($::form->{order_by} =~ /^(sellprice|lastcost)$/ ||
907
  if ($::form->{order_by} =~ /^(listpirce|sellprice|lastcost|onhand|rop)$/ ||
906 908
      $::form->{order_by} =~ /^variant_property_/) {
907 909
    if ($::form->{sort_dir}) {
908 910
      @to_sort = sort { $a->{order_by} <=> $b->{order_by} } @to_sort;
SL/DB/Part.pm
4 4

  
5 5
use Carp;
6 6
use List::MoreUtils qw(any uniq pairwise);
7
use List::Util qw(sum max);
7
use List::Util qw(sum max first);
8 8
use Rose::DB::Object::Helpers qw(as_tree);
9 9

  
10 10
use SL::Locale::String qw(t8);
......
100 100
    map_from  => 'part',
101 101
    map_to    => 'variant_property',
102 102
    type      => 'many to many',
103
    manager_args => { sort_by => 'sortkey ASC' }
103 104
  },
104 105
  variant_property_values => {
105 106
    map_class => 'SL::DB::VariantPropertyValuePart',
......
107 108
    map_to    => 'variant_property_value',
108 109
    type      => 'many to many',
109 110
  },
110
  parent_variant => {
111
  parent_variants => { # access through parent_variant
111 112
    map_class => 'SL::DB::PartParentVariantPartVariant',
112 113
    map_from  => 'variant',
113 114
    map_to    => 'parent_variant',
......
156 157
  my ($self) = @_;
157 158
  if ($self->is_variant) {
158 159
    my @property_value_ids = sort map {$_->id} $self->variant_property_values;
159
    my ($parent_variant) = $self->parent_variant;
160
    my $parent_variant = $self->parent_variant;
160 161
    my $other_variants = $parent_variant->variants;
161 162
    foreach my $variant (@$other_variants) {
162 163
      next if $variant->id == $self->id;
......
337 338
  shift->buchungsgruppen(@_);
338 339
}
339 340

  
341
sub parent_variant {
342
  my ($parent_variant) = shift->parent_variants(@_);
343
  return $parent_variant;
344
}
345

  
340 346
sub get_variant_property_value_by_unique_name {
341 347
  my ($self, $variant_property_unique_name) = @_;
342 348

  
......
686 692
  return unless $self->is_variant;
687 693
  return "[" .join("|",
688 694
    map {$_->variant_property->abbreviation . ":" . $_->abbreviation}
689
    $self->variant_property_values)  . "]";
695
    sort {$a->variant_property->sortkey <=> $b->variant_property->sortkey}
696
    $self->variant_property_values
697
  )  . "]";
690 698
}
691 699

  
692 700
sub variant_value {
......
694 702
  die "only callable on parts of type parent_variant"     unless $self->is_variant;
695 703
  die "only callable with SL::DB::VariantProperty object" unless ref $variant_property eq 'SL::DB::VariantProperty';
696 704

  
697
  my %property_id_to_values =
698
    map {$_->variant_property_id => $_}
705
  my $property_value =
706
    first {$variant_property->id == $_->variant_property_id}
699 707
    @{$self->variant_property_values};
700 708

  
701
  my $property_value = $property_id_to_values{$variant_property->id};
702

  
703
  return $property_value && $property_value->displayable_name();
709
  return $property_value;
704 710
}
705 711

  
706 712
sub init_onhandqty {
templates/design40_webpages/part/_parent_variant.html
24 24
            [% 'Partnumber' | $T8 %]
25 25
          </a>
26 26
        </th>
27
        <th id="variant_ean_header_id">
28
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("ean")'>
29
            [% "EAN" | $T8 %]
30
          </a>
31
        </th>
27 32
        <th id="variant_description_header_id">
28 33
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("description")'>
29 34
            [% "Description" | $T8 %]
......
41 46
          </a>
42 47
        </th>
43 48
        [% END %]
44
        <th>[% 'List Price' | $T8 %]</th>
45
        <th>[% 'Sell Price' | $T8 %]</th>
46
        <th>[% 'Last Cost' | $T8 %]</th>
47
        <th>[% 'ROP' | $T8 %]</th>
49
        <th id="variant_listprice_header_id">
50
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("listprice")'>
51
            [% "List Price" | $T8 %]
52
          </a>
53
        </th>
54
        <th id="variant_sellprice_header_id">
55
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("sellprice")'>
56
            [% "Sell Price" | $T8 %]
57
          </a>
58
        </th>
59
        <th id="variant_lastcost_header_id">
60
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("lastcost")'>
61
            [% "Last Cost" | $T8 %]
62
          </a>
63
        </th>
64
        <th id="variant_onhand_header_id">
65
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("onhand")'>
66
            [% "On Hand" | $T8 %]
67
          </a>
68
        </th>
69
        <th id="variant_rop_header_id">
70
          <a href='#' onClick='javascript:kivi.Part.reorder_variants("rop")'>
71
            [% "ROP" | $T8 %]
72
          </a>
73
        </th>
48 74
        <th>
49 75
          [% L.select_tag("add_variant_property", AVAILABLE_VARIANT_PROPERIES
50 76
            title_key='displayable_name', value_key='id',
......
54 80
        </th>
55 81
      </tr>
56 82
      <tr>
57
        <th class="center">
83
        <th>
58 84
          [%- L.button_tag('kivi.Part.variant_rows_toggle_selected();', "🔄",
59 85
                           title=LxERP.t8("Toggle selection"),
60 86
                           alt=LxERP.t8("Toggle selection"),
61 87
                           ) %]
62 88
        </th>
63
        <th></th>
89
        <th><!-- partnumber --></th>
90
        <th><!-- ean --></th>
64 91
        <th>
65 92
          [% L.input_tag("description_for_selected_variants", SELF.part.description,
66 93
                          class="wi-medium",
......
72 99
                title=LxERP.t8('Apply to selected rows'),
73 100
          ) %]
74 101
        </th>
75
        <th colspan="[% SELF.part.variant_properties.size + 1 %]"></th>
102
        <th><!-- variant_values --></th>
103
        [% FOREACH property = SELF.part.variant_properties %]
104
        <th></th>
105
        [% END %]
76 106
        <th>
77 107
          [% L.input_tag(
78 108
                "listprice_as_number_for_selected_variants",
......
112 142
                title=LxERP.t8('Apply to selected rows'),
113 143
          ) %]
114 144
        </th>
145
        <th><!-- onhand --></th>
115 146
        <th>
116 147
          [% L.input_tag(
117 148
                "rop_as_number_for_selected_variants",
......
148 179
              [% L.checkbox_tag('variant_multi_id_' _ loop.count, value=variant.id, checked=0) %]
149 180
            </td>
150 181
            <td>[% variant.presenter.part %]</td>
182
            <td>
183
              [% L.input_tag("variants[].ean", variant.ean, class="wi-medium") %]
184
            </td>
151 185
            <td>
152 186
              [% L.input_tag("variants[].description", variant.description, class="wi-medium") %]
153 187
            </td>
154 188
            <td>[% variant.variant_values | html %]</td>
155 189
            [% FOREACH variant_property = SELF.part.variant_properties %]
156
            <td> [% variant.variant_value(variant_property) %] </td>
190
            <td> [% variant.variant_value(variant_property).displayable_name %] </td>
157 191
            [% END %]
158 192
            <td>
159 193
              [% L.input_tag(
......
176 210
                    class='reformat_number numeric wi-small',
177 211
              ) %]
178 212
            </td>
213
            <td>
214
              <span class="data wi-small numeric">
215
                [% LxERP.format_amount(variant.onhand) %] [% variant.unit | html %]
216
              </span>
217
            </td>
179 218
            <td>
180 219
              [% L.input_tag(
181 220
                    "variants[].rop_as_number",

Auch abrufbar als: Unified diff