Revision 2172794d
Von Jan Büren vor fast 2 Jahren hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
140 | 140 |
|
141 | 141 |
$::form->{"cvar_" . $_->{name} . "_valid"} = 1 for @default_valid_configs; |
142 | 142 |
} else { |
143 |
$::form->{lastcost_modified} = $self->check_lastcost_modified;
|
|
143 |
$self->{lastcost_modified} = $self->check_lastcost_modified;
|
|
144 | 144 |
} |
145 | 145 |
|
146 | 146 |
# $self->part has been loaded, parsed and validated without errors and is ready to be saved |
147 | 147 |
$self->part->db->with_transaction(sub { |
148 | 148 |
|
149 | 149 |
$self->part->save(cascade => 1); |
150 |
$self->part->set_lastcost_assemblies_and_assortiments if $self->{lastcost_modified}; |
|
150 | 151 |
|
151 | 152 |
SL::DB::History->new( |
152 | 153 |
trans_id => $self->part->id, |
... | ... | |
864 | 865 |
|
865 | 866 |
sub check_lastcost_modified { |
866 | 867 |
my ($self) = @_; |
867 |
|
|
868 | 868 |
return abs($self->part->lastcost - $self->part->last_price_update->lastcost) < 0.009 ? undef : 1; |
869 | 869 |
} |
870 | 870 |
|
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 |
} |
SL/IR.pm | ||
---|---|---|
243 | 243 |
|
244 | 244 |
next if $payments_only; |
245 | 245 |
|
246 |
# update parts table by setting lastcost to current price, don't allow negative values by using abs |
|
247 |
# maybe allow only 2 decimal places -> rounding error with fx can be too huge for datev checks |
|
248 |
# @values = ($form->round_amount(abs($fxsellprice * $form->{exchangerate} / $basefactor), 2), conv_i($form->{"id_$i"})); |
|
249 |
#$query = qq|UPDATE parts SET lastcost = ? WHERE id = ?|; |
|
250 |
#@values = (abs($fxsellprice * $form->{exchangerate} / $basefactor), conv_i($form->{"id_$i"})); |
|
251 |
#do_query($form, $dbh, $query, @values); |
|
252 | 246 |
# after_save hook changes lastcost for all assemblies and assortments recursively |
253 |
$::form->{lastcost_modified} = 1; |
|
254 | 247 |
my $a = SL::DB::Part->load_cached(conv_i($form->{"id_$i"})); |
255 | 248 |
$a->update_attributes(lastcost => abs($fxsellprice * $form->{exchangerate} / $basefactor)); |
256 |
|
|
249 |
$a->set_lastcost_assemblies_and_assortiments; |
|
257 | 250 |
|
258 | 251 |
# check if we sold the item already and |
259 | 252 |
# make an entry for the expense and inventory |
Auch abrufbar als: Unified diff
Einkaufspreis von Erzeugnissen/Sortimententen ohne after_save hook