1 package SL::Helper::Inventory::Allocation;
 
   5 my @attributes = qw(parts_id qty bin_id warehouse_id chargenumber bestbefore comment for_object_id);
 
   6 my %attributes = map { $_ => 1 } @attributes;
 
   7 my %mapped_attributes = (
 
   8   for_object_id => 'oe_id',
 
  11 for my $name (@attributes) {
 
  13   *{"SL::Helper::Inventory::Allocation::$name"} = sub { $_[0]{$name} };
 
  17   my ($class, %params) = @_;
 
  19   Carp::croak("missing attribute $_") for grep { !exists $params{$_}     } @attributes;
 
  20   Carp::croak("unknown attribute $_") for grep { !exists $attributes{$_} } keys %params;
 
  21   Carp::croak("$_ must be set")       for grep { !$params{$_} } qw(parts_id qty bin_id);
 
  22   Carp::croak("$_ must be positive")  for grep { !($params{$_} > 0) } qw(parts_id qty bin_id);
 
  24   bless { %params }, $class;
 
  28   my ($self, %params) = @_;
 
  30   SL::DB::Inventory->new(
 
  32       my $attr = $mapped_attributes{$_} // $_;
 
  33       $attr => $self->{$attr}
 
  45 SL::Helper::Inventory::Allocation - Inventory API allocation data structure
 
  49   # all of these need to be present
 
  50   my $allocation = SL::Helper::Inventory::Allocation->new(
 
  53     bin_id            => $bin_obj->id,
 
  54     warehouse_id      => $bin_obj->warehouse_id,
 
  55     chargenumber      => '1823772365',           # can be undef
 
  56     bestbefore        => undef,                  # can be undef
 
  57     for_object_id     => $order->id,             # can be undef
 
  63 The full documentation can be found in L<SL::Helper::Inventory>