Revision 7eee416a
Von Bernd Bleßmann vor 10 Monaten hinzugefügt
SL/Helper/Inventory.pm | ||
---|---|---|
6 | 6 |
use Exporter qw(import); |
7 | 7 |
use List::Util qw(min sum); |
8 | 8 |
use List::UtilsBy qw(sort_by); |
9 |
use List::MoreUtils qw(any); |
|
9 |
use List::MoreUtils qw(any none);
|
|
10 | 10 |
use POSIX qw(ceil); |
11 | 11 |
use Scalar::Util qw(blessed); |
12 | 12 |
|
... | ... | |
18 | 18 |
use SL::Helper::Inventory::Allocation; |
19 | 19 |
use SL::X; |
20 | 20 |
|
21 |
our @EXPORT_OK = qw(get_stock get_onhand allocate allocate_for_assembly produce_assembly check_constraints); |
|
21 |
our @EXPORT_OK = qw(get_stock get_onhand allocate allocate_for_assembly produce_assembly check_constraints check_allocations_for_assembly);
|
|
22 | 22 |
our %EXPORT_TAGS = (ALL => \@EXPORT_OK); |
23 | 23 |
|
24 | 24 |
sub _get_stock_onhand { |
... | ... | |
354 | 354 |
|
355 | 355 |
# check whether allocations are sane |
356 | 356 |
if (!$params{no_check_allocations} && !$params{auto_allocate}) { |
357 |
my %allocations_by_part; |
|
358 |
for (@$allocations) { |
|
359 |
$allocations_by_part{$_->parts_id} //= 0; |
|
360 |
$allocations_by_part{$_->parts_id} += $_->qty; |
|
361 |
} |
|
362 |
|
|
363 |
for my $assembly ($part->assemblies) { |
|
364 |
next if $assembly->part->type eq 'service' && !$consume_service; |
|
365 |
$allocations_by_part{ $assembly->parts_id } -= $assembly->qty * $qty; |
|
366 |
} |
|
367 |
|
|
368 | 357 |
die SL::X::Inventory::Allocation->new( |
369 | 358 |
code => "allocations are insufficient for production", |
370 | 359 |
message => t8('can not allocate enough resources for production'), |
371 |
) if any { $_ < 0 } values %allocations_by_part;
|
|
360 |
) if !check_allocations_for_assembly(part => $part, qty => $qty, allocations => $allocations);
|
|
372 | 361 |
} |
373 | 362 |
|
374 | 363 |
my @transfers; |
... | ... | |
411 | 400 |
@transfers; |
412 | 401 |
} |
413 | 402 |
|
403 |
sub check_allocations_for_assembly { |
|
404 |
my (%params) = @_; |
|
405 |
|
|
406 |
my $part = $params{part} or Carp::croak('check_allocations_for_assembly needs a part'); |
|
407 |
my $qty = $params{qty} or Carp::croak('check_allocations_for_assembly needs a qty'); |
|
408 |
|
|
409 |
my $consume_service = $::instance_conf->get_produce_assembly_transfer_service; |
|
410 |
|
|
411 |
my $allocations = $params{allocations}; |
|
412 |
|
|
413 |
my %allocations_by_part; |
|
414 |
for (@{ $allocations || []}) { |
|
415 |
$allocations_by_part{$_->parts_id} //= 0; |
|
416 |
$allocations_by_part{$_->parts_id} += $_->qty; |
|
417 |
} |
|
418 |
|
|
419 |
for my $assembly ($part->assemblies) { |
|
420 |
next if $assembly->part->type eq 'service' && !$consume_service; |
|
421 |
$allocations_by_part{ $assembly->parts_id } -= $assembly->qty * $qty; |
|
422 |
} |
|
423 |
|
|
424 |
return none { $_ < 0 } values %allocations_by_part; |
|
425 |
} |
|
426 |
|
|
414 | 427 |
sub default_show_bestbefore { |
415 | 428 |
$::instance_conf->get_show_bestbefore |
416 | 429 |
} |
... | ... | |
661 | 674 |
|
662 | 675 |
=item * produce_assembly |
663 | 676 |
|
677 |
=item * check_allocations_for_assembly PARAMS |
|
678 |
|
|
679 |
Checks if enough quantity is allocated for production. Returns a trueish |
|
680 |
value if there is enough allocated, a falsish one otherwise. |
|
681 |
|
|
682 |
Accepted parameters: |
|
683 |
|
|
684 |
=over 4 |
|
685 |
|
|
686 |
=item * part |
|
687 |
|
|
688 |
The part object to be assembled. Mandatory. |
|
689 |
|
|
690 |
=item * qty |
|
691 |
|
|
692 |
The quantity of the part to be assembled. Mandatory. |
|
693 |
|
|
694 |
=item * allocations |
|
695 |
|
|
696 |
An array ref of the allocations. |
|
697 |
|
|
698 |
=back |
|
664 | 699 |
|
665 | 700 |
=back |
666 | 701 |
|
Auch abrufbar als: Unified diff
S:H:Inventory: produce_assembly: Prüfung der Allokierung ausgelagert