X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FDB%2FOrderItem.pm;h=5fcb8be2ac1295f8099d2ba385382df608017070;hb=10348b514ddb450a0ee23df36f7f4c4242989b3e;hp=8e15d31b9bb62627384157df32c10b0f5715321f;hpb=4ecb8321edcee5e012028a23db3c8d0f760c2178;p=kivitendo-erp.git diff --git a/SL/DB/OrderItem.pm b/SL/DB/OrderItem.pm index 8e15d31b9..5fcb8be2a 100644 --- a/SL/DB/OrderItem.pm +++ b/SL/DB/OrderItem.pm @@ -6,6 +6,10 @@ use List::Util qw(sum); 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, @@ -19,6 +23,8 @@ use SL::DB::Helper::CustomVariables ( __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; @@ -34,33 +40,51 @@ sub shipped_qty { return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi); } -sub delivered_qty { - my ($self) = @_; +sub record { goto &order } - my $d_orders = $self->order->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrder'); - my @d_orders_delivered; +1; - foreach (@$d_orders) { - push (@d_orders_delivered, $_) if $_->delivered; - } +__END__ - my @doi_delivered = grep { $_->parts_id == $self->parts_id } map { $_->orderitems } @d_orders_delivered; +=pod - require SL::AM; - return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi_delivered); -} +=head1 NAME -sub value_of_goods { - my ($self) = @_; +SL::DB::OrderItems: Rose model for orderitems + +=head1 FUNCTIONS + +=over 4 + +=item C + +returns the number of orderitems which are already linked to Delivery Orders. +The linked key is parts_id and not orderitems (id) -> delivery_order_items (id). +Therefore this function is not safe for identical parts_id. +Sample call: +C<$::form-Eformat_amount(\%::myconfig, $_[0]-Eshipped_qty);> + +=back + +=head1 TODO + +Older versions of OrderItem.pm had more functions which where used for calculating the +qty for the different states of the Delivery Order. +For example to get the qty in already marked as delivered Delivery Orders: + +C + +return $self-E_delivered_qty; + + sub _delivered_qty { + (..) + my @d_orders_delivered = grep { $_-Edelivered } @$d_orders; + my @doi_delivered = grep { $_-Eparts_id == $self-Eparts_id } map { $_-Eorderitems } @d_orders_delivered; + } + +In general the function C and all (project) related functions should be marked deprecate, + because of the better linked item to item data in the record_links table. - my $price_factor = $self->price_factor ? $self->price_factor : 1; - return ($self->qty * $self->sellprice * (1 - $self->discount ) / $price_factor); -} -sub taxincluded { - my ($self) = @_; - return SL::DB::Manager::Order->find_by(id => $self->trans_id)->taxincluded ? $::locale->text('WARN: Tax included value!') : ''; -} -1;