X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FHelper%2FShippedQty.pm;h=e109fa7ec0c21b5263abf56631d3d064f5632a58;hb=2b6b46fefd21ebee3ddd76b499ddc0f72b893fed;hp=a50cebcdc90828d2b27769eaa65fc08dbbe496ed;hpb=0d6c87b05048688066bab51642390947b1cad2d4;p=kivitendo-erp.git diff --git a/SL/Helper/ShippedQty.pm b/SL/Helper/ShippedQty.pm index a50cebcdc..e109fa7ec 100644 --- a/SL/Helper/ShippedQty.pm +++ b/SL/Helper/ShippedQty.pm @@ -3,12 +3,13 @@ package SL::Helper::ShippedQty; use strict; use parent qw(Rose::Object); -use SL::AM; +use Carp; use Scalar::Util qw(blessed); -use SL::DBUtils qw(selectall_hashref_query selectall_as_map); use List::Util qw(min); use List::MoreUtils qw(any all uniq); use List::UtilsBy qw(partition_by); +use SL::AM; +use SL::DBUtils qw(selectall_hashref_query selectall_as_map); use SL::Locale::String qw(t8); use Rose::Object::MakeMethods::Generic ( @@ -102,9 +103,7 @@ my %item_identity_fields = ( sub calculate { my ($self, $data) = @_; - die 'Need exactly one argument, either id, object or arrayref of ids or objects.' unless 2 == @_; - - return $self if !$data || ('ARRAY' eq ref $data && !@$data); + croak 'Need exactly one argument, either id, object or arrayref of ids or objects.' unless 2 == @_; $self->normalize_input($data); @@ -209,7 +208,7 @@ sub calculate_fill_up { sub write_to { my ($self, $objects) = @_; - die 'expecting array of objects' unless 'ARRAY' eq ref $objects; + croak 'expecting array of objects' unless 'ARRAY' eq ref $objects; my $shipped_qty = $self->shipped_qty; @@ -235,7 +234,9 @@ sub write_to { sub write_to_objects { my ($self) = @_; - die 'Can only use write_to_objects, when calculate was called with objects. Use write_to instead.' unless $self->objects_or_ids; + return unless @{ $self->oe_ids }; + + croak 'Can only use write_to_objects, when calculate was called with objects. Use write_to instead.' unless $self->objects_or_ids; $self->write_to($self->objects); } @@ -254,10 +255,11 @@ sub normalize_input { $self->objects_or_ids(!!blessed($data->[0])); if ($self->objects_or_ids) { - die 'unblessed object in data while expecting object' if any { !blessed($_) } @$data; + croak 'unblessed object in data while expecting object' if any { !blessed($_) } @$data; $self->objects($data); } else { - die 'object or reference in data while expecting ids' if any { ref($_) } @$data; + croak 'object or reference in data while expecting ids' if any { ref($_) } @$data; + croak 'ids need to be numbers' if any { ! ($_ * 1) } @$data; $self->oe_ids($data); } @@ -271,9 +273,9 @@ sub available_item_identity_fields { sub init_oe_ids { my ($self) = @_; - die 'oe_ids not initialized in id mode' if !$self->objects_or_ids; - die 'objects not initialized before accessing ids' if $self->objects_or_ids && !defined $self->objects; - die 'objects need to be Order or OrderItem' if any { ref($_) !~ /^SL::DB::Order(?:Item)?$/ } @{ $self->objects }; + croak 'oe_ids not initialized in id mode' if !$self->objects_or_ids; + croak 'objects not initialized before accessing ids' if $self->objects_or_ids && !defined $self->objects; + croak 'objects need to be Order or OrderItem' if any { ref($_) !~ /^SL::DB::Order(?:Item)?$/ } @{ $self->objects }; [ uniq map { ref($_) =~ /Item/ ? $_->trans_id : $_->id } @{ $self->objects } ] } @@ -325,7 +327,7 @@ SL::Helper::ShippedQty - Algorithmic module for calculating shipped qty $helper->calculate($oe_id); $helper->calculate(\@oe_ids); - # if these are items set elivered and shipped_qty + # if these are items set delivered and shipped_qty # if these are orders, iterate through their items and set delivered on order $helper->write_to($objects); @@ -485,6 +487,13 @@ was found it will be set to zero. C is guaranteed only to be the correct boolean value, but not any specific value. +Note: C will avoid loading unnecessary objects. This means if it is +called with an Order object that has not loaded its orderitems yet, only +C will be set in the Order object. A subsequent C<< +$order->orderitems->[0]->{delivered} >> will return C, and C<< +$order->orderitems->[0]->shipped_qty >> will invoke another implicit +calculation. + =item C Valid after L. Returns a hasref with shipped qtys by orderitems id. @@ -522,6 +531,8 @@ false, the match was made in the fill up stage. =back +=back + =head1 REPLACED FUNCTIONALITY =head2 delivered mode