Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2172794d

Von Jan Büren vor etwa 1 Jahr hinzugefügt

Einkaufspreis von Erzeugnissen/Sortimententen ohne after_save hook

Unterschiede anzeigen:

SL/DB/Part.pm
92 92

  
93 93
__PACKAGE__->before_save('_before_save_set_partnumber');
94 94
__PACKAGE__->before_save('_before_save_set_assembly_weight');
95
__PACKAGE__->after_save('_set_lastcost_assemblies_and_assortiments');
96 95

  
97 96
sub _before_save_set_partnumber {
98 97
  my ($self) = @_;
......
546 545
  sum map { $_->linetotal_weight} @{$self->items};
547 546
};
548 547

  
549
sub _set_lastcost_assemblies_and_assortiments {
548
sub set_lastcost_assemblies_and_assortiments {
550 549
  my ($self) = @_;
551 550

  
552
  return 1 unless $self->lastcost;  # not saved yet
553
  return 1 unless $::form->{lastcost_modified};
551
  return 1 unless $self->id;  # not saved yet
552

  
553
  require SL::DB::AssortmentItem;
554
  require SL::DB::Assembly;
554 555

  
555 556
  # 1. check all
556 557
  my $assortments = SL::DB::Manager::AssortmentItem->get_all(where => [parts_id => $self->id ]);
......
560 561
    next unless ref $assembly eq 'SL::DB::Assembly';
561 562
    my $a = SL::DB::Part->load_cached($assembly->id);
562 563
    $a->update_attributes(lastcost => $a->items_lastcost_sum);
564
    $a->set_lastcost_assemblies_and_assortiments;
563 565
  }
564 566
  foreach my $assortment (@{ $assortments }) {
565 567
    next unless ref $assortment eq 'SL::DB::AssortmentItem';
566 568
    my $a = SL::DB::Part->load_cached($assortment->assortment_id);
567 569
    $a->update_attributes(lastcost => $a->items_lastcost_sum);
570
    $a->set_lastcost_assemblies_and_assortiments;
568 571
  }
569 572
  return 1;
570 573
}

Auch abrufbar als: Unified diff