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