X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FOrderItem.pm;h=a92e2f3eb77167da2cb6a24be4077b95f415355c;hb=f769991a4bd3d207cece79bb2cb3fc96cec4602d;hp=9ee5743efccbf2284089c3d8616dd8d51b81afd4;hpb=dbdaaafb9239a402faa889d9d89616a3e98d79fe;p=kivitendo-erp.git diff --git a/SL/DB/OrderItem.pm b/SL/DB/OrderItem.pm index 9ee5743ef..a92e2f3eb 100644 --- a/SL/DB/OrderItem.pm +++ b/SL/DB/OrderItem.pm @@ -2,29 +2,96 @@ package SL::DB::OrderItem; use strict; -use SL::DB::MetaSetup::OrderItem; +use List::Util qw(sum); -__PACKAGE__->meta->add_relationship( - part => { - type => 'one to one', - class => 'SL::DB::Part', - column_map => { parts_id => 'id' }, - }, - price_factor_obj => { - type => 'one to one', - class => 'SL::DB::PriceFactor', - column_map => { price_factor_id => 'id' }, +use SL::DB::MetaSetup::OrderItem; +use SL::DB::Manager::OrderItem; +use SL::DB::DeliveryOrderItemsStock; +use SL::DB::Helper::ActsAsList; +use SL::DB::Helper::LinkedRecords; +use SL::DB::Helper::RecordItem; +use SL::DB::Helper::CustomVariables ( + sub_module => 'orderitems', + cvars_alias => 1, + overloads => { + parts_id => { + class => 'SL::DB::Part', + module => 'IC', + } }, ); - -# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all. -__PACKAGE__->meta->make_manager_class; +use SL::Helper::ShippedQty; __PACKAGE__->meta->initialize; +__PACKAGE__->configure_acts_as_list(group_by => [qw(trans_id)]); + sub is_price_update_available { my $self = shift; return $self->origprice > $self->part->sellprice; } +sub shipped_qty { + my ($self, %params) = @_; + + my $force = delete $params{force}; + + SL::Helper::ShippedQty->new(%params)->calculate($self)->write_to_objects if $force || !defined $self->{shipped_qty}; + + $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 + +