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(
21 class => 'SL::DB::Part',
22 column_map => { parts_id => 'id' },
26 class => 'SL::DB::PriceFactor',
27 column_map => { price_factor_id => 'id' },
31 class => 'SL::DB::Unit',
32 column_map => { unit => 'name' },
36 class => 'SL::DB::Order',
37 column_map => { trans_id => 'id' },
41 __PACKAGE__->meta->initialize;
43 sub is_price_update_available {
45 return $self->origprice > $self->part->sellprice;
51 my $d_orders = $self->order->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrder');
52 my @doi = grep { $_->parts_id == $self->parts_id } map { $_->orderitems } @$d_orders;
54 return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi);