1 package SL::DB::OrderItem;
5 use List::Util qw(sum);
8 use SL::DB::MetaSetup::OrderItem;
9 use SL::DB::Manager::OrderItem;
10 use SL::DB::Helper::CustomVariables (
11 sub_module => 'orderitems',
14 parts_id => 'SL::DB::Part',
18 __PACKAGE__->meta->add_relationship(
20 type => 'many to one',
21 class => 'SL::DB::Unit',
22 column_map => { unit => 'name' },
26 __PACKAGE__->meta->initialize;
28 sub is_price_update_available {
30 return $self->origprice > $self->part->sellprice;
36 my $d_orders = $self->order->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrder');
37 my @doi = grep { $_->parts_id == $self->parts_id } map { $_->orderitems } @$d_orders;
39 return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi);