Revision f01ed5d1
Von Bernd Bleßmann vor fast 3 Jahren hinzugefügt
SL/DB/Part.pm | ||
---|---|---|
4 | 4 |
|
5 | 5 |
use Carp; |
6 | 6 |
use List::MoreUtils qw(any uniq); |
7 |
use List::Util qw(sum); |
|
7 | 8 |
use Rose::DB::Object::Helpers qw(as_tree); |
8 | 9 |
|
9 | 10 |
use SL::Locale::String qw(t8); |
... | ... | |
26 | 27 |
{name => 'ean', title => t8('EAN') }, ], |
27 | 28 |
); |
28 | 29 |
|
29 |
use List::Util qw(sum); |
|
30 | 30 |
|
31 | 31 |
__PACKAGE__->meta->add_relationships( |
32 | 32 |
assemblies => { |
... | ... | |
91 | 91 |
__PACKAGE__->attr_sorted({ unsorted => 'customerprices', position => 'sortorder' }); |
92 | 92 |
|
93 | 93 |
__PACKAGE__->before_save('_before_save_set_partnumber'); |
94 |
__PACKAGE__->before_save('_before_save_set_assembly_weight'); |
|
94 | 95 |
|
95 | 96 |
sub _before_save_set_partnumber { |
96 | 97 |
my ($self) = @_; |
... | ... | |
99 | 100 |
return 1; |
100 | 101 |
} |
101 | 102 |
|
103 |
sub _before_save_set_assembly_weight { |
|
104 |
my ($self) = @_; |
|
105 |
|
|
106 |
if ( $self->part_type eq 'assembly' ) { |
|
107 |
my $weight_sum = $self->items_weight_sum; |
|
108 |
$self->weight($self->items_weight_sum) if $weight_sum; |
|
109 |
} |
|
110 |
return 1; |
|
111 |
} |
|
112 |
|
|
102 | 113 |
sub items { |
103 | 114 |
my ($self) = @_; |
104 | 115 |
|
... | ... | |
425 | 436 |
SQL |
426 | 437 |
|
427 | 438 |
my $objs = SL::DB::Manager::Inventory->get_all( |
428 |
query => [ id => [ \"$query" ] ], |
|
439 |
query => [ id => [ \"$query" ] ], # make emacs happy "
|
|
429 | 440 |
with_objects => [ 'parts', 'trans_type', 'bin', 'bin.warehouse' ], # prevent lazy loading in template |
430 | 441 |
sort_by => 'itime DESC', |
431 | 442 |
); |
... | ... | |
519 | 530 |
sum map { $_->linetotal_lastcost } @{$self->items}; |
520 | 531 |
}; |
521 | 532 |
|
533 |
sub items_weight_sum { |
|
534 |
my ($self) = @_; |
|
535 |
|
|
536 |
return unless $self->is_assembly; |
|
537 |
return unless $self->items; |
|
538 |
sum map { $_->linetotal_weight} @{$self->items}; |
|
539 |
}; |
|
540 |
|
|
522 | 541 |
1; |
523 | 542 |
|
524 | 543 |
__END__ |
Auch abrufbar als: Unified diff
Erzeugnisse: Gewicht aus einzelnen Bestandteilen ermitteln und speichern.