Revision 2172794d
Von Jan Büren vor etwa 2 Jahren hinzugefügt
SL/DB/Part.pm | ||
---|---|---|
|
||
__PACKAGE__->before_save('_before_save_set_partnumber');
|
||
__PACKAGE__->before_save('_before_save_set_assembly_weight');
|
||
__PACKAGE__->after_save('_set_lastcost_assemblies_and_assortiments');
|
||
|
||
sub _before_save_set_partnumber {
|
||
my ($self) = @_;
|
||
... | ... | |
sum map { $_->linetotal_weight} @{$self->items};
|
||
};
|
||
|
||
sub _set_lastcost_assemblies_and_assortiments {
|
||
sub set_lastcost_assemblies_and_assortiments {
|
||
my ($self) = @_;
|
||
|
||
return 1 unless $self->lastcost; # not saved yet
|
||
return 1 unless $::form->{lastcost_modified};
|
||
return 1 unless $self->id; # not saved yet
|
||
|
||
require SL::DB::AssortmentItem;
|
||
require SL::DB::Assembly;
|
||
|
||
# 1. check all
|
||
my $assortments = SL::DB::Manager::AssortmentItem->get_all(where => [parts_id => $self->id ]);
|
||
... | ... | |
next unless ref $assembly eq 'SL::DB::Assembly';
|
||
my $a = SL::DB::Part->load_cached($assembly->id);
|
||
$a->update_attributes(lastcost => $a->items_lastcost_sum);
|
||
$a->set_lastcost_assemblies_and_assortiments;
|
||
}
|
||
foreach my $assortment (@{ $assortments }) {
|
||
next unless ref $assortment eq 'SL::DB::AssortmentItem';
|
||
my $a = SL::DB::Part->load_cached($assortment->assortment_id);
|
||
$a->update_attributes(lastcost => $a->items_lastcost_sum);
|
||
$a->set_lastcost_assemblies_and_assortiments;
|
||
}
|
||
return 1;
|
||
}
|
Auch abrufbar als: Unified diff
Einkaufspreis von Erzeugnissen/Sortimententen ohne after_save hook