my $part_type = $::form->{part_type};
die unless $part_type =~ /^(assortment|assembly)$/;
- my $sellprice_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'sellcost');
- my $lastcost_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'lastcost');
+ my $sellprice_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'sellcost');
+ my $lastcost_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'lastcost');
+ my $items_weight_sum = $self->recalc_item_totals(part_type => $part_type, price_type => 'weight');
my $sum_diff = $sellprice_sum-$lastcost_sum;
->html('#items_sum_diff', $::form->format_amount(\%::myconfig, $sum_diff, 2, 0))
->html('#items_sellprice_sum_basic', $::form->format_amount(\%::myconfig, $sellprice_sum, 2, 0))
->html('#items_lastcost_sum_basic', $::form->format_amount(\%::myconfig, $lastcost_sum, 2, 0))
+ ->html('#items_weight_sum_basic' , $::form->format_amount(\%::myconfig, $items_weight_sum))
->no_flash_clear->render();
}
my $items_sellprice_sum = $part->items_sellprice_sum;
my $items_lastcost_sum = $part->items_lastcost_sum;
my $items_sum_diff = $items_sellprice_sum - $items_lastcost_sum;
+ my $items_weight_sum = $part->items_weight_sum;
$self->js
->append('#assembly_rows', $html) # append in tbody
->html('#items_sum_diff', $::form->format_amount(\%::myconfig, $items_sum_diff , 2, 0))
->html('#items_sellprice_sum_basic', $::form->format_amount(\%::myconfig, $items_sellprice_sum, 2, 0))
->html('#items_lastcost_sum_basic' , $::form->format_amount(\%::myconfig, $items_lastcost_sum , 2, 0))
+ ->html('#items_weight_sum_basic' , $::form->format_amount(\%::myconfig, $items_weight_sum))
->render;
}
}
} elsif ( $part->is_assembly ) {
$part->assemblies( @{$self->assembly_items} );
- if ( $params{price_type} eq 'lastcost' ) {
+ if ( $params{price_type} eq 'weight' ) {
+ return $part->items_weight_sum;
+ } elsif ( $params{price_type} eq 'lastcost' ) {
return $part->items_lastcost_sum;
} else {
return $part->items_sellprice_sum;
use Carp;
use List::MoreUtils qw(any uniq);
+use List::Util qw(sum);
use Rose::DB::Object::Helpers qw(as_tree);
use SL::Locale::String qw(t8);
{name => 'ean', title => t8('EAN') }, ],
);
-use List::Util qw(sum);
__PACKAGE__->meta->add_relationships(
assemblies => {
__PACKAGE__->attr_sorted({ unsorted => 'customerprices', position => 'sortorder' });
__PACKAGE__->before_save('_before_save_set_partnumber');
+__PACKAGE__->before_save('_before_save_set_assembly_weight');
sub _before_save_set_partnumber {
my ($self) = @_;
return 1;
}
+sub _before_save_set_assembly_weight {
+ my ($self) = @_;
+
+ if ( $self->part_type eq 'assembly' ) {
+ my $weight_sum = $self->items_weight_sum;
+ $self->weight($self->items_weight_sum) if $weight_sum;
+ }
+ return 1;
+}
+
sub items {
my ($self) = @_;
SQL
my $objs = SL::DB::Manager::Inventory->get_all(
- query => [ id => [ \"$query" ] ],
+ query => [ id => [ \"$query" ] ], # make emacs happy "
with_objects => [ 'parts', 'trans_type', 'bin', 'bin.warehouse' ], # prevent lazy loading in template
sort_by => 'itime DESC',
);
sum map { $_->linetotal_lastcost } @{$self->items};
};
+sub items_weight_sum {
+ my ($self) = @_;
+
+ return unless $self->is_assembly;
+ return unless $self->items;
+ sum map { $_->linetotal_weight} @{$self->items};
+};
+
1;
__END__