Revision 0e7a8b0c
Von Jan Büren vor mehr als 1 Jahr hinzugefügt
SL/Controller/Part.pm | ||
---|---|---|
139 | 139 |
@{ CVar->get_configs() }; |
140 | 140 |
|
141 | 141 |
$::form->{"cvar_" . $_->{name} . "_valid"} = 1 for @default_valid_configs; |
142 |
} else { |
|
143 |
$::form->{lastcost_modified} = $self->check_lastcost_modified; |
|
142 | 144 |
} |
143 | 145 |
|
144 | 146 |
# $self->part has been loaded, parsed and validated without errors and is ready to be saved |
... | ... | |
860 | 862 |
|
861 | 863 |
} |
862 | 864 |
|
865 |
sub check_lastcost_modified { |
|
866 |
my ($self) = @_; |
|
867 |
|
|
868 |
return abs($self->part->lastcost - $self->part->last_price_update->lastcost) < 0.009 ? undef : 1; |
|
869 |
} |
|
870 |
|
|
863 | 871 |
sub parse_form { |
864 | 872 |
my ($self, %params) = @_; |
865 | 873 |
|
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'); |
|
95 | 96 |
|
96 | 97 |
sub _before_save_set_partnumber { |
97 | 98 |
my ($self) = @_; |
... | ... | |
545 | 546 |
sum map { $_->linetotal_weight} @{$self->items}; |
546 | 547 |
}; |
547 | 548 |
|
549 |
sub _set_lastcost_assemblies_and_assortiments { |
|
550 |
my ($self) = @_; |
|
551 |
|
|
552 |
return 1 unless $self->lastcost; # not saved yet |
|
553 |
return 1 unless $::form->{lastcost_modified}; |
|
554 |
|
|
555 |
# 1. check all |
|
556 |
my $assortments = SL::DB::Manager::AssortmentItem->get_all(where => [parts_id => $self->id ]); |
|
557 |
my $assemblies = SL::DB::Manager::Assembly->get_all( where => [parts_id => $self->id ]); |
|
558 |
|
|
559 |
foreach my $assembly (@{ $assemblies }) { |
|
560 |
next unless ref $assembly eq 'SL::DB::Assembly'; |
|
561 |
my $a = SL::DB::Part->load_cached($assembly->id); |
|
562 |
$a->update_attributes(lastcost => $a->items_lastcost_sum); |
|
563 |
} |
|
564 |
foreach my $assortment (@{ $assortments }) { |
|
565 |
next unless ref $assortment eq 'SL::DB::AssortmentItem'; |
|
566 |
my $a = SL::DB::Part->load_cached($assortment->assortment_id); |
|
567 |
$a->update_attributes(lastcost => $a->items_lastcost_sum); |
|
568 |
} |
|
569 |
return 1; |
|
570 |
} |
|
571 |
|
|
548 | 572 |
1; |
549 | 573 |
|
550 | 574 |
__END__ |
SL/IR.pm | ||
---|---|---|
246 | 246 |
# update parts table by setting lastcost to current price, don't allow negative values by using abs |
247 | 247 |
# maybe allow only 2 decimal places -> rounding error with fx can be too huge for datev checks |
248 | 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); |
|
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 |
# after_save hook changes lastcost for all assemblies and assortments recursively |
|
253 |
$::form->{lastcost_modified} = 1; |
|
254 |
my $a = SL::DB::Part->load_cached(conv_i($form->{"id_$i"})); |
|
255 |
$a->update_attributes(lastcost => abs($fxsellprice * $form->{exchangerate} / $basefactor)); |
|
256 |
|
|
252 | 257 |
|
253 | 258 |
# check if we sold the item already and |
254 | 259 |
# make an entry for the expense and inventory |
Auch abrufbar als: Unified diff
Einkaufspreis von Erzeugnissen/Sortimententen aktualisieren (rekursiv)
Falls sich ein einzelner Bestandteil verändert. Läuft über alle
weiter verbauten Teile durch Aufruf von Parts::after_save.
Benötigt einen boolean Parameter in $::form->{lastcost_modified}, damit
nicht bei jedem Speichern des Artikels ohne Veränderung des EK-Preises
die Rekursion losgetreten wird. Beachtet auch die Veränderungsroutine
innerhalb des EK-Rechnungscodes.