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