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::DeliveryOrderItemsStock;
10 use SL::DB::Helper::ActsAsList;
11 use SL::DB::Helper::LinkedRecords;
12 use SL::DB::Helper::RecordItem;
13 use SL::DB::Helper::CustomVariables (
14 sub_module => 'orderitems',
18 class => 'SL::DB::Part',
24 __PACKAGE__->meta->initialize;
26 __PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id)]);
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;
40 return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi);
43 sub record { goto &order }
53 SL::DB::OrderItems: Rose model for orderitems
61 returns the number of orderitems which are already linked to Delivery Orders.
62 The linked key is parts_id and not orderitems (id) -> delivery_order_items (id).
63 Therefore this function is not safe for identical parts_id.
65 C<$::form-E<gt>format_amount(\%::myconfig, $_[0]-E<gt>shipped_qty);>
71 Older versions of OrderItem.pm had more functions which where used for calculating the
72 qty for the different states of the Delivery Order.
73 For example to get the qty in already marked as delivered Delivery Orders:
77 return $self-E<gt>_delivered_qty;
81 my @d_orders_delivered = grep { $_-E<gt>delivered } @$d_orders;
82 my @doi_delivered = grep { $_-E<gt>parts_id == $self-E<gt>parts_id } map { $_-E<gt>orderitems } @d_orders_delivered;
85 In general the function C<shipped_qty> and all (project) related functions should be marked deprecate,
86 because of the better linked item to item data in the record_links table.