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,
);
}
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';
bless { %params }, $class;
}
+
+ sub transfer_object {
+ my ($self, %params) = @_;
+
+ SL::DB::Inventory->new(
+ (map {
+ my $attr = $mapped_attributes{$_} // $_;
+ $attr => $self->{$attr}
+ } @attributes),
+ %params,
+ );
+ }
}
1;
=back
-C<chargenumber>, C<bestbefore> and C<for_object_id> may be C<undef> (but must
-still be present at creation time). Instances are considered immutable.
+C<chargenumber>, C<bestbefore> and C<for_object_id> and C<comment> may be
+C<undef> (but must still be present at creation time). Instances are considered
+immutable.
+Allocations also provide the method C<transfer_object> which will create a new
+C<SL::DB::Inventory> bject with all the playload.
=head1 CONSTRAINTS