Revision 4720b32a
Von Sven Schöling vor mehr als 7 Jahren hinzugefügt
SL/Helper/ShippedQty.pm | ||
---|---|---|
3 | 3 |
use strict; |
4 | 4 |
use parent qw(Rose::Object); |
5 | 5 |
|
6 |
use SL::AM;
|
|
6 |
use Carp;
|
|
7 | 7 |
use Scalar::Util qw(blessed); |
8 |
use SL::DBUtils qw(selectall_hashref_query selectall_as_map); |
|
9 | 8 |
use List::Util qw(min); |
10 | 9 |
use List::MoreUtils qw(any all uniq); |
11 | 10 |
use List::UtilsBy qw(partition_by); |
11 |
use SL::AM; |
|
12 |
use SL::DBUtils qw(selectall_hashref_query selectall_as_map); |
|
12 | 13 |
use SL::Locale::String qw(t8); |
13 | 14 |
|
14 | 15 |
use Rose::Object::MakeMethods::Generic ( |
... | ... | |
102 | 103 |
sub calculate { |
103 | 104 |
my ($self, $data) = @_; |
104 | 105 |
|
105 |
die 'Need exactly one argument, either id, object or arrayref of ids or objects.' unless 2 == @_;
|
|
106 |
croak 'Need exactly one argument, either id, object or arrayref of ids or objects.' unless 2 == @_;
|
|
106 | 107 |
|
107 | 108 |
$self->normalize_input($data); |
108 | 109 |
|
... | ... | |
207 | 208 |
sub write_to { |
208 | 209 |
my ($self, $objects) = @_; |
209 | 210 |
|
210 |
die 'expecting array of objects' unless 'ARRAY' eq ref $objects;
|
|
211 |
croak 'expecting array of objects' unless 'ARRAY' eq ref $objects;
|
|
211 | 212 |
|
212 | 213 |
my $shipped_qty = $self->shipped_qty; |
213 | 214 |
|
... | ... | |
235 | 236 |
|
236 | 237 |
return unless @{ $self->oe_ids }; |
237 | 238 |
|
238 |
die 'Can only use write_to_objects, when calculate was called with objects. Use write_to instead.' unless $self->objects_or_ids;
|
|
239 |
croak 'Can only use write_to_objects, when calculate was called with objects. Use write_to instead.' unless $self->objects_or_ids;
|
|
239 | 240 |
|
240 | 241 |
$self->write_to($self->objects); |
241 | 242 |
} |
... | ... | |
254 | 255 |
$self->objects_or_ids(!!blessed($data->[0])); |
255 | 256 |
|
256 | 257 |
if ($self->objects_or_ids) { |
257 |
die 'unblessed object in data while expecting object' if any { !blessed($_) } @$data;
|
|
258 |
croak 'unblessed object in data while expecting object' if any { !blessed($_) } @$data;
|
|
258 | 259 |
$self->objects($data); |
259 | 260 |
} else { |
260 |
die 'object or reference in data while expecting ids' if any { ref($_) } @$data;
|
|
261 |
die 'ids need to be numbers' if any { ! ($_ * 1) } @$data;
|
|
261 |
croak 'object or reference in data while expecting ids' if any { ref($_) } @$data;
|
|
262 |
croak 'ids need to be numbers' if any { ! ($_ * 1) } @$data;
|
|
262 | 263 |
$self->oe_ids($data); |
263 | 264 |
} |
264 | 265 |
|
... | ... | |
272 | 273 |
sub init_oe_ids { |
273 | 274 |
my ($self) = @_; |
274 | 275 |
|
275 |
die 'oe_ids not initialized in id mode' if !$self->objects_or_ids;
|
|
276 |
die 'objects not initialized before accessing ids' if $self->objects_or_ids && !defined $self->objects;
|
|
277 |
die 'objects need to be Order or OrderItem' if any { ref($_) !~ /^SL::DB::Order(?:Item)?$/ } @{ $self->objects };
|
|
276 |
croak 'oe_ids not initialized in id mode' if !$self->objects_or_ids;
|
|
277 |
croak 'objects not initialized before accessing ids' if $self->objects_or_ids && !defined $self->objects;
|
|
278 |
croak 'objects need to be Order or OrderItem' if any { ref($_) !~ /^SL::DB::Order(?:Item)?$/ } @{ $self->objects };
|
|
278 | 279 |
|
279 | 280 |
[ uniq map { ref($_) =~ /Item/ ? $_->trans_id : $_->id } @{ $self->objects } ] |
280 | 281 |
} |
Auch abrufbar als: Unified diff
ShippedQty: Abgefangene API Fehler auf Carp::croak umgestellt.
So werden die aus der Sicht des callers geschmissen.