X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FOrderItem.pm;h=a92e2f3eb77167da2cb6a24be4077b95f415355c;hb=f769991a4bd3d207cece79bb2cb3fc96cec4602d;hp=1eb52473416f0e10ec435362f43c07f9dba1615c;hpb=7317b8d9828cad7fd033d73589d7e9665fb397c7;p=kivitendo-erp.git diff --git a/SL/DB/OrderItem.pm b/SL/DB/OrderItem.pm index 1eb524734..a92e2f3eb 100644 --- a/SL/DB/OrderItem.pm +++ b/SL/DB/OrderItem.pm @@ -20,6 +20,7 @@ use SL::DB::Helper::CustomVariables ( } }, ); +use SL::Helper::ShippedQty; __PACKAGE__->meta->initialize; @@ -31,16 +32,66 @@ sub is_price_update_available { } sub shipped_qty { - my ($self) = @_; + my ($self, %params) = @_; + + my $force = delete $params{force}; - my $d_orders = $self->order->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrder'); - my @doi = grep { $_->parts_id == $self->parts_id } map { $_->orderitems } @$d_orders; + SL::Helper::ShippedQty->new(%params)->calculate($self)->write_to_objects if $force || !defined $self->{shipped_qty}; - require SL::AM; - return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi); + $self->{shipped_qty}; } +sub linked_delivery_order_items { + my ($self) = @_; + + return $self->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrderItem'); +} + +sub delivered_qty { goto &shipped_qty } + sub record { goto &order } 1; +__END__ + +=pod + +=head1 NAME + +SL::DB::OrderItems: Rose model for orderitems + +=head1 FUNCTIONS + +=over 4 + +=item C + +Calculates the shipped qty for this orderitem (measured in the current unit) +and returns it. + +Note that the shipped qty is expected not to change within the request and is +cached in C once calculated. If C<< force => 1 >> is passed, the +existibng cache is ignored. + +Given parameters will be passed to L, so you can force +the shipped/delivered distinction like this: + + $_->shipped_qty(require_stock_out => 0); + +Note however that calculating shipped_qty on individual Orderitems is generally +a bad idea. See L for way to compute these all at once. + +=item C + +Alias for L. + +=back + +=head1 AUTHORS + +G. Richardson Egrichardson@kivitendo-premium.deE + +=cut + +