From 5d7aadc1f54825821263c6cc6e405e124f09af3d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 23 Oct 2020 20:03:11 +0200 Subject: [PATCH] Inventory::Allocation: transfer_object --- SL/Helper/Inventory.pm | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/SL/Helper/Inventory.pm b/SL/Helper/Inventory.pm index b7d30b966..777801cf4 100644 --- a/SL/Helper/Inventory.pm +++ b/SL/Helper/Inventory.pm @@ -330,14 +330,12 @@ sub produce_assembly { my @transfers; for my $allocation (@$allocations) { my $oe_id = delete $allocation->{for_object_id}; - push @transfers, SL::DB::Inventory->new( + push @transfers, $allocation->transfer_object( trans_id => $trans_id, - %$allocation, qty => -$allocation->qty, trans_type => $trans_type_out, shippingdate => $shippingdate, employee => SL::DB::Manager::Employee->current, - oe_id => $allocation->for_object_id, ); } @@ -375,6 +373,9 @@ sub default_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'; @@ -391,6 +392,18 @@ package SL::Helper::Inventory::Allocation { bless { %params }, $class; } + + sub transfer_object { + my ($self, %params) = @_; + + SL::DB::Inventory->new( + (map { + my $attr = $mapped_attributes{$_} // $_; + $attr => $self->{$attr} + } @attributes), + %params, + ); + } } 1; @@ -725,9 +738,12 @@ The object may be an order, productionorder or other objects =back -C, C and C may be C (but must -still be present at creation time). Instances are considered immutable. +C, C and C and C may be +C (but must still be present at creation time). Instances are considered +immutable. +Allocations also provide the method C which will create a new +C bject with all the playload. =head1 CONSTRAINTS -- 2.20.1