Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8a0d2996

Von Tamino Steinert vor 6 Monaten hinzugefügt

  • ID 8a0d29968757bfba2f0a06dfa07b650eaffc4ef7
  • Vorgänger bc8ddcc1
  • Nachfolger e4982f5b

Varianten: einfachen Artikel in Variante umwandeln

Unterschiede anzeigen:

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

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

  
......
133 133

  
134 134
__PACKAGE__->before_save('_before_save_set_partnumber');
135 135
__PACKAGE__->before_save('_before_save_set_assembly_weight');
136
__PACKAGE__->before_save('_before_check_variant_property_values');
136 137

  
137 138
sub _before_save_set_partnumber {
138 139
  my ($self) = @_;
......
151 152
  return 1;
152 153
}
153 154

  
155
sub _before_check_variant_property_values {
156
  my ($self) = @_;
157
  if ($self->is_variant) {
158
    my @property_value_ids = sort map {$_->id} $self->variant_property_values;
159
    my ($parent_variant) = $self->parent_variant;
160
    my $other_variants = $parent_variant->variants;
161
    foreach my $variant (@$other_variants) {
162
      next if $variant->id == $self->id;
163
      my @other_property_value_ids = sort map {$_->id} $variant->variant_property_values;
164
      if (@other_property_value_ids == @property_value_ids
165
        && not any {$_} pairwise {$a != $b} @other_property_value_ids, @property_value_ids
166
      ) {
167
        die t8("There is already a variant with the property values: "),
168
          join(' ,', map {$_->displayable_name} $self->variant_property_values);
169
      }
170
    }
171
  }
172
  return 1;
173
}
174

  
154 175
sub items {
155 176
  my ($self) = @_;
156 177

  
......
513 534
    die "Given variant_property_values dosn't match the variant_properties of parent_variant part";
514 535
  }
515 536

  
516
  my $separator = '.'; # TODO: make configurable
537
  my $new_variant = $self->clone_and_reset;
538
  $new_variant->partnumber($self->_next_variant_partnumber);
539
  $new_variant->variant_type('variant');
540
  $new_variant->add_assemblies(map {$_->clone_and_reset} $self->assemblies) if ($self->is_assembly);
541
  $new_variant->add_variant_property_values(@$variant_property_values);
542
  $new_variant->parent_variant($self);
543
  $new_variant->save;
544

  
545
  $self->add_variants($new_variant);
546
  return $new_variant;
547
}
517 548

  
549
sub _next_variant_partnumber {
550
  my ($self) = @_;
551
  die "only callable on parts of type parent_variant" unless $self->is_parent_variant;
552

  
553
  my $separator = '.'; # TODO: make configurable
518 554
  my $last_variant_number =
519 555
    max
520 556
    map {
......
524 560
    }
525 561
    $self->variants;
526 562

  
527
  my $new_variant = $self->clone_and_reset;
528
  $new_variant->partnumber($self->partnumber . $separator . ($last_variant_number + 1));
529
  $new_variant->variant_type('variant');
530
  $new_variant->add_assemblies(map {$_->clone_and_reset} $self->assemblies) if ($self->is_assembly);
531
  $new_variant->add_variant_property_values(@$variant_property_values);
532

  
533
  $self->add_variants($new_variant);
534
  $self->save;
535
  return $new_variant;
563
  return $self->partnumber . $separator . ($last_variant_number + 1);
536 564
}
537 565

  
538 566
sub clone_and_reset_deep {

Auch abrufbar als: Unified diff