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