kivitendo/SL/DB/OrderItem.pm @ 4b1666b7
82515b2d | Sven Schöling | package SL::DB::OrderItem;
|
||
use strict;
|
||||
ba0fb69c | Sven Schöling | use List::Util qw(sum);
|
||
82515b2d | Sven Schöling | use SL::DB::MetaSetup::OrderItem;
|
||
ef2b5e94 | Moritz Bunkus | use SL::DB::Manager::OrderItem;
|
||
3b7bda40 | Jan Büren | use SL::DB::DeliveryOrderItemsStock;
|
||
3954d14b | Bernd Bleßmann | use SL::DB::Helper::ActsAsList;
|
||
ca808f20 | Geoffrey Richardson | use SL::DB::Helper::LinkedRecords;
|
||
1904d8c6 | Sven Schöling | use SL::DB::Helper::RecordItem;
|
||
e1bf173b | Sven Schöling | use SL::DB::Helper::CustomVariables (
|
||
sub_module => 'orderitems',
|
||||
cvars_alias => 1,
|
||||
overloads => {
|
||||
5a7ae14c | Sven Schöling | parts_id => {
|
||
class => 'SL::DB::Part',
|
||||
module => 'IC',
|
||||
}
|
||||
e1bf173b | Sven Schöling | },
|
||
);
|
||||
400d16e3 | Sven Schöling | use SL::Helper::ShippedQty;
|
||
82515b2d | Sven Schöling | |||
__PACKAGE__->meta->initialize;
|
||||
3954d14b | Bernd Bleßmann | __PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id)]);
|
||
82515b2d | Sven Schöling | sub is_price_update_available {
|
||
my $self = shift;
|
||||
return $self->origprice > $self->part->sellprice;
|
||||
}
|
||||
ba0fb69c | Sven Schöling | sub shipped_qty {
|
||
400d16e3 | Sven Schöling | my ($self, %params) = @_;
|
||
my $force = delete $params{force};
|
||||
ba0fb69c | Sven Schöling | |||
400d16e3 | Sven Schöling | SL::Helper::ShippedQty->new(%params)->calculate($self)->write_to_objects if $force || !defined $self->{shipped_qty};
|
||
ba0fb69c | Sven Schöling | |||
400d16e3 | Sven Schöling | $self->{shipped_qty};
|
||
ba0fb69c | Sven Schöling | }
|
||
8a3f13c3 | Geoffrey Richardson | sub linked_delivery_order_items {
|
||
my ($self) = @_;
|
||||
return $self->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrderItem');
|
||||
}
|
||||
400d16e3 | Sven Schöling | sub delivered_qty { goto &shipped_qty }
|
||
8a3f13c3 | Geoffrey Richardson | |||
073ee541 | Geoffrey Richardson | sub record { goto &order }
|
||
82515b2d | Sven Schöling | 1;
|
||
7317b8d9 | Jan Büren | |||
31347b09 | Jan Büren | __END__
|
||
=pod
|
||||
=head1 NAME
|
||||
SL::DB::OrderItems: Rose model for orderitems
|
||||
=head1 FUNCTIONS
|
||||
=over 4
|
||||
400d16e3 | Sven Schöling | =item C<shipped_qty PARAMS>
|
||
8a3f13c3 | Geoffrey Richardson | |||
400d16e3 | Sven Schöling | Calculates the shipped qty for this orderitem (measured in the current unit)
|
||
and returns it.
|
||||
8a3f13c3 | Geoffrey Richardson | |||
400d16e3 | Sven Schöling | Note that the shipped qty is expected not to change within the request and is
|
||
cached in C<shipped_qty> once calculated. If C<< force => 1 >> is passed, the
|
||||
existibng cache is ignored.
|
||||
8a3f13c3 | Geoffrey Richardson | |||
400d16e3 | Sven Schöling | Given parameters will be passed to L<SL::Helper::ShippedQty>, so you can force
|
||
the shipped/delivered distinction like this:
|
||||
8a3f13c3 | Geoffrey Richardson | |||
400d16e3 | Sven Schöling | $_->shipped_qty(require_stock_out => 0);
|
||
8a3f13c3 | Geoffrey Richardson | |||
400d16e3 | Sven Schöling | Note however that calculating shipped_qty on individual Orderitems is generally
|
||
a bad idea. See L<SL::Helper::ShippedQty> for way to compute these all at once.
|
||||
8a3f13c3 | Geoffrey Richardson | |||
400d16e3 | Sven Schöling | =item C<delivered_qty>
|
||
8a3f13c3 | Geoffrey Richardson | |||
400d16e3 | Sven Schöling | Alias for L</shipped_qty>.
|
||
8a3f13c3 | Geoffrey Richardson | |||
31347b09 | Jan Büren | =back
|
||
8a3f13c3 | Geoffrey Richardson | =head1 AUTHORS
|
||
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
|
||||
31347b09 | Jan Büren | |||
8a3f13c3 | Geoffrey Richardson | =cut
|
||
31347b09 | Jan Büren |