Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7bf726ca

Von Sven Schöling vor mehr als 3 Jahren hinzugefügt

  • ID 7bf726cae26f0f56b810822a8f5804344947785a
  • Vorgänger 726e362a
  • Nachfolger c591d7cc

Inventory Helper: Allocation ausgelagert in eigene Datei

Unterschiede anzeigen:

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
SL/Helper/Inventory/Allocation.pm
1
package SL::Helper::Inventory::Allocation;
2

  
3
use strict;
4

  
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',
9
);
10

  
11
for my $name (@attributes) {
12
  no strict 'refs';
13
  *{"SL::Helper::Inventory::Allocation::$name"} = sub { $_[0]{$name} };
14
}
15

  
16
sub new {
17
  my ($class, %params) = @_;
18

  
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);
23

  
24
  bless { %params }, $class;
25
}
26

  
27
sub transfer_object {
28
  my ($self, %params) = @_;
29

  
30
  SL::DB::Inventory->new(
31
    (map {
32
      my $attr = $mapped_attributes{$_} // $_;
33
      $attr => $self->{$attr}
34
    } @attributes),
35
    %params,
36
  );
37
}
38

  
39
1;
40

  
41
=encoding utf-8
42

  
43
=head1 NAME
44

  
45
SL::Helper::Inventory::Allocation - Inventory API allocation data structure
46

  
47
=head1 SYNOPSIS
48

  
49
  # all of these need to be present
50
  my $allocation = SL::Helper::Inventory::Allocation->new(
51
    part_id           => $part->id,
52
    qty               => 15,
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
58
  );
59

  
60

  
61
=head1 SEE ALSO
62

  
63
The full documentation can be found in L<SL::Helper::Inventory>
64

  
65
=cut

Auch abrufbar als: Unified diff