From 7bf726cae26f0f56b810822a8f5804344947785a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 27 Nov 2020 17:14:49 +0100 Subject: [PATCH] Inventory Helper: Allocation ausgelagert in eigene Datei --- SL/Helper/Inventory.pm | 37 +----------------- SL/Helper/Inventory/Allocation.pm | 65 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 36 deletions(-) create mode 100644 SL/Helper/Inventory/Allocation.pm diff --git a/SL/Helper/Inventory.pm b/SL/Helper/Inventory.pm index 366c0248e..73c60f191 100644 --- a/SL/Helper/Inventory.pm +++ b/SL/Helper/Inventory.pm @@ -14,6 +14,7 @@ use SL::MoreCommon qw(listify); use SL::DBUtils qw(selectall_hashref_query selectrow_query); use SL::DB::TransferType; use SL::Helper::Number qw(_format_number _round_number); +use SL::Helper::Inventory::Allocation; use SL::X; our @EXPORT_OK = qw(get_stock get_onhand allocate allocate_for_assembly produce_assembly check_constraints); @@ -370,42 +371,6 @@ sub default_show_bestbefore { $::instance_conf->get_show_bestbefore } -package SL::Helper::Inventory::Allocation { - my @attributes = qw(parts_id qty bin_id warehouse_id chargenumber bestbefore comment for_object_id); - my %attributes = map { $_ => 1 } @attributes; - my %mapped_attributes = ( - for_object_id => 'oe_id', - ); - - for my $name (@attributes) { - no strict 'refs'; - *{"SL::Helper::Inventory::Allocation::$name"} = sub { $_[0]{$name} }; - } - - sub new { - my ($class, %params) = @_; - - Carp::croak("missing attribute $_") for grep { !exists $params{$_} } @attributes; - Carp::croak("unknown attribute $_") for grep { !exists $attributes{$_} } keys %params; - Carp::croak("$_ must be set") for grep { !$params{$_} } qw(parts_id qty bin_id); - Carp::croak("$_ must be positive") for grep { !($params{$_} > 0) } qw(parts_id qty bin_id); - - bless { %params }, $class; - } - - sub transfer_object { - my ($self, %params) = @_; - - SL::DB::Inventory->new( - (map { - my $attr = $mapped_attributes{$_} // $_; - $attr => $self->{$attr} - } @attributes), - %params, - ); - } -} - 1; =encoding utf-8 diff --git a/SL/Helper/Inventory/Allocation.pm b/SL/Helper/Inventory/Allocation.pm new file mode 100644 index 000000000..e406bf40c --- /dev/null +++ b/SL/Helper/Inventory/Allocation.pm @@ -0,0 +1,65 @@ +package SL::Helper::Inventory::Allocation; + +use strict; + +my @attributes = qw(parts_id qty bin_id warehouse_id chargenumber bestbefore comment for_object_id); +my %attributes = map { $_ => 1 } @attributes; +my %mapped_attributes = ( + for_object_id => 'oe_id', +); + +for my $name (@attributes) { + no strict 'refs'; + *{"SL::Helper::Inventory::Allocation::$name"} = sub { $_[0]{$name} }; +} + +sub new { + my ($class, %params) = @_; + + Carp::croak("missing attribute $_") for grep { !exists $params{$_} } @attributes; + Carp::croak("unknown attribute $_") for grep { !exists $attributes{$_} } keys %params; + Carp::croak("$_ must be set") for grep { !$params{$_} } qw(parts_id qty bin_id); + Carp::croak("$_ must be positive") for grep { !($params{$_} > 0) } qw(parts_id qty bin_id); + + bless { %params }, $class; +} + +sub transfer_object { + my ($self, %params) = @_; + + SL::DB::Inventory->new( + (map { + my $attr = $mapped_attributes{$_} // $_; + $attr => $self->{$attr} + } @attributes), + %params, + ); +} + +1; + +=encoding utf-8 + +=head1 NAME + +SL::Helper::Inventory::Allocation - Inventory API allocation data structure + +=head1 SYNOPSIS + + # all of these need to be present + my $allocation = SL::Helper::Inventory::Allocation->new( + part_id => $part->id, + qty => 15, + bin_id => $bin_obj->id, + warehouse_id => $bin_obj->warehouse_id, + chargenumber => '1823772365', # can be undef + bestbefore => undef, # can be undef + for_object_id => $order->id, # can be undef + ); + + +=head1 SEE ALSO + +The full documentation can be found in L + +=cut -- 2.20.1