Revision 7bf726ca
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
SL/Helper/Inventory.pm | ||
---|---|---|
14 | 14 |
use SL::DBUtils qw(selectall_hashref_query selectrow_query); |
15 | 15 |
use SL::DB::TransferType; |
16 | 16 |
use SL::Helper::Number qw(_format_number _round_number); |
17 |
use SL::Helper::Inventory::Allocation; |
|
17 | 18 |
use SL::X; |
18 | 19 |
|
19 | 20 |
our @EXPORT_OK = qw(get_stock get_onhand allocate allocate_for_assembly produce_assembly check_constraints); |
... | ... | |
370 | 371 |
$::instance_conf->get_show_bestbefore |
371 | 372 |
} |
372 | 373 |
|
373 |
package SL::Helper::Inventory::Allocation { |
|
374 |
my @attributes = qw(parts_id qty bin_id warehouse_id chargenumber bestbefore comment for_object_id); |
|
375 |
my %attributes = map { $_ => 1 } @attributes; |
|
376 |
my %mapped_attributes = ( |
|
377 |
for_object_id => 'oe_id', |
|
378 |
); |
|
379 |
|
|
380 |
for my $name (@attributes) { |
|
381 |
no strict 'refs'; |
|
382 |
*{"SL::Helper::Inventory::Allocation::$name"} = sub { $_[0]{$name} }; |
|
383 |
} |
|
384 |
|
|
385 |
sub new { |
|
386 |
my ($class, %params) = @_; |
|
387 |
|
|
388 |
Carp::croak("missing attribute $_") for grep { !exists $params{$_} } @attributes; |
|
389 |
Carp::croak("unknown attribute $_") for grep { !exists $attributes{$_} } keys %params; |
|
390 |
Carp::croak("$_ must be set") for grep { !$params{$_} } qw(parts_id qty bin_id); |
|
391 |
Carp::croak("$_ must be positive") for grep { !($params{$_} > 0) } qw(parts_id qty bin_id); |
|
392 |
|
|
393 |
bless { %params }, $class; |
|
394 |
} |
|
395 |
|
|
396 |
sub transfer_object { |
|
397 |
my ($self, %params) = @_; |
|
398 |
|
|
399 |
SL::DB::Inventory->new( |
|
400 |
(map { |
|
401 |
my $attr = $mapped_attributes{$_} // $_; |
|
402 |
$attr => $self->{$attr} |
|
403 |
} @attributes), |
|
404 |
%params, |
|
405 |
); |
|
406 |
} |
|
407 |
} |
|
408 |
|
|
409 | 374 |
1; |
410 | 375 |
|
411 | 376 |
=encoding utf-8 |
Auch abrufbar als: Unified diff
Inventory Helper: Allocation ausgelagert in eigene Datei