a92e2f3eb77167da2cb6a24be4077b95f415355c
[kivitendo-erp.git] / SL / DB / OrderItem.pm
1 package SL::DB::OrderItem;
2
3 use strict;
4
5 use List::Util qw(sum);
6
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',
15   cvars_alias => 1,
16   overloads   => {
17     parts_id => {
18       class => 'SL::DB::Part',
19       module => 'IC',
20     }
21   },
22 );
23 use SL::Helper::ShippedQty;
24
25 __PACKAGE__->meta->initialize;
26
27 __PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id)]);
28
29 sub is_price_update_available {
30   my $self = shift;
31   return $self->origprice > $self->part->sellprice;
32 }
33
34 sub shipped_qty {
35   my ($self, %params) = @_;
36
37   my $force = delete $params{force};
38
39   SL::Helper::ShippedQty->new(%params)->calculate($self)->write_to_objects if $force || !defined $self->{shipped_qty};
40
41   $self->{shipped_qty};
42 }
43
44 sub linked_delivery_order_items {
45   my ($self) = @_;
46
47   return $self->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrderItem');
48 }
49
50 sub delivered_qty { goto &shipped_qty }
51
52 sub record { goto &order }
53
54 1;
55
56 __END__
57
58 =pod
59
60 =head1 NAME
61
62 SL::DB::OrderItems: Rose model for orderitems
63
64 =head1 FUNCTIONS
65
66 =over 4
67
68 =item C<shipped_qty PARAMS>
69
70 Calculates the shipped qty for this orderitem (measured in the current unit)
71 and returns it.
72
73 Note that the shipped qty is expected not to change within the request and is
74 cached in C<shipped_qty> once calculated. If C<< force => 1 >> is passed, the
75 existibng cache is ignored.
76
77 Given parameters will be passed to L<SL::Helper::ShippedQty>, so you can force
78 the shipped/delivered distinction like this:
79
80   $_->shipped_qty(require_stock_out => 0);
81
82 Note however that calculating shipped_qty on individual Orderitems is generally
83 a bad idea. See L<SL::Helper::ShippedQty> for way to compute these all at once.
84
85 =item C<delivered_qty>
86
87 Alias for L</shipped_qty>.
88
89 =back
90
91 =head1 AUTHORS
92
93 G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
94
95 =cut
96
97