Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision fb11389a

Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt

  • ID fb11389a2dcae27ae4dae48a4212255e5d33090a
  • Vorgänger 6e0fe1dc
  • Nachfolger 4438ac89

SL::Dev::Part - Sortimente erstellen überarbeitet

Man kann nun auch AssortmentItems übergeben.

Unterschiede anzeigen:

SL/Dev/Part.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(create_part create_service);
5
our @EXPORT = qw(create_part create_service create_assembly create_assortment);
6 6

  
7 7
use SL::DB::Part;
8 8
use SL::DB::Unit;
......
74 74
sub create_assortment {
75 75
  my (%params) = @_;
76 76

  
77
  my @parts;
78
  my $part1 = SL::Dev::Part::create_part(partnumber   => 'sp1',
79
                                         description  => 'Testpart assortment',
80
                                        )->save;
81
  push(@parts, $part1);
82

  
83
  my $number_of_parts = delete $params{number_of_parts} || 3;
84

  
85
  for my $i ( 2 .. $number_of_parts ) {
86
    my $part = $parts[0]->clone_and_reset;
87
    $part->partnumber(  ($part->partnumber  // '') . " " . $i );
88
    $part->description( ($part->description // '') . " " . $i );
89
    $part->save;
90
    push(@parts, $part);
77
  my $assortment_items = [];
78
  if ( $params{assortment_items} ) {
79
    $assortment_items = $params{assortment_items};
80
  } else {
81
    # no assortment items were passed, create a part, clone it several times
82
    # and add to assortment as assortment_items
83
    my @parts;
84
    my $part1 = SL::Dev::Part::create_part(partnumber   => 'sp1',
85
                                           description  => 'Testpart assortment',
86
                                          )->save;
87
    push(@parts, $part1);
88

  
89
    my $number_of_parts = delete $params{number_of_parts} || 3;
90

  
91
    for my $i ( 2 .. $number_of_parts ) {
92
      my $part = $parts[0]->clone_and_reset;
93
      $part->partnumber(  ($part->partnumber  // '') . " " . $i );
94
      $part->description( ($part->description // '') . " " . $i );
95
      $part->save;
96
      push(@parts, $part);
97
    }
98
    my $position = 0;
99
    foreach my $part ( @parts ) {
100
      push( @{$assortment_items}, SL::DB::AssortmentItem->new(parts_id => $part->id,
101
                                                              qty      => 1,
102
                                                              position => $position++,
103
                                                              charge   => 1,
104
                                                              unit     => $part->unit,
105
                                                             ));
106
    }
91 107
  }
92 108

  
93 109
  my $assortment = SL::DB::Part->new_assortment(
......
95 111
    description        => 'Test Assortment',
96 112
    sellprice          => '10',
97 113
    lastcost           => '5',
114
    assortment_items   => $assortment_items,
98 115
    buchungsgruppen_id => _default_buchungsgruppe()->id,
99 116
    unit               => _default_unit()->name
100 117
  );
101 118

  
102
  my $position = 0;
103
  foreach my $part ( @parts ) {
104
    $assortment->add_assortment_items( SL::DB::AssortmentItem->new(parts_id => $part->id,
105
                                                                   qty      => 1,
106
                                                                   position => $position++,
107
                                                                   charge   => 1,
108
                                                                   unit     => $part->unit,
109
                                                                  ));
110
  }
111 119
  $assortment->assign_attributes( %params );
112 120
  return $assortment;
113 121
}
......
177 185

  
178 186
  my $assortment = SL::Dev::Part::create_assortment->save;
179 187

  
180
Create a new assortment with 10 parts:
188
Create a new assortment with 10 automatically created parts using the
189
number_of_parts param:
181 190

  
182 191
  my $assortment = SL::Dev::Part::create_assortment(number_of_parts => 10)->save;
183 192

  
193
Create an assortment with a certain name and pass some assortment_item Objects
194
from newly created parts:
195

  
196
  my $part1             = SL::Dev::Part::create_part( sellprice => '7.77')->save;
197
  my $part2             = SL::Dev::Part::create_part( sellprice => '6.66')->save;
198
  my $assortment_item_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1);
199
  my $assortment_item_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2);
200
  my $assortment_part   = SL::Dev::Part::create_assortment( partnumber  => 'Assortment 1',
201
                                                            description => 'assortment test',
202
                                                            sellprice   => '0',
203
                                                            part_type   => 'assortment',
204
                                                            assortment_items => [ $assortment_item_1, $assortment_item_2 ],
205
                                                          )->save;
184 206

  
185 207
=head1 TODO
186 208

  

Auch abrufbar als: Unified diff