Revision 7fc41a37
Von Moritz Bunkus vor fast 2 Jahren hinzugefügt
SL/Helper/Inventory.pm | ||
---|---|---|
8 | 8 |
use List::UtilsBy qw(sort_by); |
9 | 9 |
use List::MoreUtils qw(any); |
10 | 10 |
use POSIX qw(ceil); |
11 |
use Scalar::Util qw(blessed); |
|
11 | 12 |
|
12 | 13 |
use SL::Locale::String qw(t8); |
13 | 14 |
use SL::MoreCommon qw(listify); |
... | ... | |
196 | 197 |
last if $rest_qty == 0; |
197 | 198 |
} |
198 | 199 |
if ($rest_qty > 0) { |
199 |
die SL::X::Inventory::Allocation->new( |
|
200 |
code => 'not enough to allocate', |
|
201 |
message => t8("can not allocate #1 units of #2, missing #3 units", _format_number($qty), $part->displayable_name, _format_number($rest_qty)), |
|
200 |
die SL::X::Inventory::Allocation::MissingQty->new( |
|
201 |
code => 'not enough to allocate', |
|
202 |
message => t8("can not allocate #1 units of #2, missing #3 units", _format_number($qty), $part->displayable_name, _format_number($rest_qty)), |
|
203 |
part_description => $part->displayable_name, |
|
204 |
to_allocate_qty => $qty, |
|
205 |
missing_qty => $rest_qty, |
|
202 | 206 |
); |
203 | 207 |
} else { |
204 | 208 |
if ($params{constraints}) { |
... | ... | |
228 | 232 |
$parts_to_allocate{ $assembly->part->id } += $assembly->qty * $qty; |
229 | 233 |
} |
230 | 234 |
|
231 |
my @allocations;
|
|
235 |
my (@allocations, @errors);
|
|
232 | 236 |
|
233 | 237 |
for my $part_id (keys %parts_to_allocate) { |
234 | 238 |
my $part = SL::DB::Part->load_cached($part_id); |
235 |
push @allocations, allocate(%params, part => $part, qty => $parts_to_allocate{$part_id}); |
|
236 |
if ($wh_strict) { |
|
237 |
die SL::X::Inventory::Allocation->new( |
|
238 |
code => "wrong warehouse for part", |
|
239 |
message => t8('Part #1 exists in warehouse #2, but not in warehouse #3 ', |
|
240 |
$part->partnumber . ' ' . $part->description, |
|
241 |
SL::DB::Manager::Warehouse->find_by(id => $allocations[-1]->{warehouse_id})->description, |
|
242 |
$wh->description), |
|
243 |
) unless $allocations[-1]->{warehouse_id} == $wh->id; |
|
244 |
} |
|
239 |
|
|
240 |
eval { |
|
241 |
push @allocations, allocate(%params, part => $part, qty => $parts_to_allocate{$part_id}); |
|
242 |
if ($wh_strict) { |
|
243 |
die SL::X::Inventory::Allocation->new( |
|
244 |
code => "wrong warehouse for part", |
|
245 |
message => t8('Part #1 exists in warehouse #2, but not in warehouse #3 ', |
|
246 |
$part->partnumber . ' ' . $part->description, |
|
247 |
SL::DB::Manager::Warehouse->find_by(id => $allocations[-1]->{warehouse_id})->description, |
|
248 |
$wh->description), |
|
249 |
) unless $allocations[-1]->{warehouse_id} == $wh->id; |
|
250 |
} |
|
251 |
1; |
|
252 |
} or do { |
|
253 |
my $ex = $@; |
|
254 |
die $ex unless blessed($ex) && $ex->can('rethrow'); |
|
255 |
|
|
256 |
if ($ex->isa('SL::X::Inventory::Allocation')) { |
|
257 |
push @errors, $@; |
|
258 |
} else { |
|
259 |
$ex->rethrow; |
|
260 |
} |
|
261 |
}; |
|
262 |
} |
|
263 |
|
|
264 |
if (@errors) { |
|
265 |
die SL::X::Inventory::Allocation::Multi->new( |
|
266 |
code => "multiple errors during allocation", |
|
267 |
message => "multiple errors during allocation", |
|
268 |
errors => \@errors, |
|
269 |
); |
|
245 | 270 |
} |
246 | 271 |
|
247 | 272 |
@allocations; |
Auch abrufbar als: Unified diff
Erzeugnis fertigen: alle möglichen Allokationsfehler auf einmal anzeigen