Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9a052b24

Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt

  • ID 9a052b243b8b30d2ca9fe8d06b1260bdeffac8c5
  • Vorgänger 6dfdb5a7
  • Nachfolger a445f9c1

SL::Dev::Part - assembly und assortment anlegen

Unterschiede anzeigen:

SL/Dev/Part.pm
11 11
sub create_part {
12 12
  my (%params) = @_;
13 13

  
14
  my ($buchungsgruppe, $unit);
15
  $buchungsgruppe  = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group";
16
  $unit            = SL::DB::Manager::Unit->find_by(name => 'Stck')                          || die "No unit";
17

  
18 14
  my $part = SL::DB::Part->new_part(
19 15
    description        => 'Test part',
20 16
    sellprice          => '10',
21 17
    lastcost           => '5',
22
    buchungsgruppen_id => $buchungsgruppe->id,
23
    unit               => $unit->name,
18
    buchungsgruppen_id => _default_buchungsgruppe()->id,
19
    unit               => _default_unit()->name
24 20
  );
25 21
  $part->assign_attributes( %params );
26 22
  return $part;
......
29 25
sub create_service {
30 26
  my (%params) = @_;
31 27

  
32
  my ($buchungsgruppe, $unit);
33
  $buchungsgruppe  = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group";
34
  $unit            = SL::DB::Manager::Unit->find_by(name => 'Stck')                          || die "No unit";
35

  
36 28
  my $part = SL::DB::Part->new_service(
37 29
    description        => 'Test service',
38 30
    sellprice          => '10',
39 31
    lastcost           => '5',
40
    buchungsgruppen_id => $buchungsgruppe->id,
41
    unit               => $unit->name,
32
    buchungsgruppen_id => _default_buchungsgruppe()->id,
33
    unit               => _default_unit()->name
42 34
  );
43 35
  $part->assign_attributes( %params );
44 36
  return $part;
45 37
}
46 38

  
39
sub create_assembly {
40
  my (%params) = @_;
41

  
42
  my @parts;
43
  my $part1 = SL::Dev::Part::create_part(partnumber   => 'ap1',
44
                                         description  => 'Testpart',
45
                                        )->save;
46
  push(@parts, $part1);
47

  
48
  my $number_of_parts = delete $params{number_of_parts} || 3;
49

  
50
  for my $i ( 2 .. $number_of_parts ) {
51
    my $part = $parts[0]->clone_and_reset;
52
    $part->partnumber(  $part->partnumber  . " " . $i );
53
    $part->description( $part->description . " " . $i );
54
    $part->save;
55
    push(@parts, $part);
56
  }
57

  
58
  my $assembly = SL::DB::Part->new_assembly(
59
    partnumber         => 'as1',
60
    description        => 'Test Assembly',
61
    sellprice          => '10',
62
    lastcost           => '5',
63
    buchungsgruppen_id => _default_buchungsgruppe()->id,
64
    unit               => _default_unit()->name
65
  );
66

  
67
  foreach my $part ( @parts ) {
68
    $assembly->add_assemblies( SL::DB::Assembly->new(parts_id => $part->id, qty => 1, bom => 1) );
69
  }
70
  $assembly->assign_attributes( %params );
71
  return $assembly;
72
}
73

  
74
sub create_assortment {
75
  my (%params) = @_;
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);
91
  }
92

  
93
  my $assortment = SL::DB::Part->new_assortment(
94
    partnumber         => 'as1',
95
    description        => 'Test Assortment',
96
    sellprice          => '10',
97
    lastcost           => '5',
98
    buchungsgruppen_id => _default_buchungsgruppe()->id,
99
    unit               => _default_unit()->name
100
  );
101

  
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
  $assortment->assign_attributes( %params );
112
  return $assortment;
113
}
114

  
115

  
116
sub _default_buchungsgruppe {
117
  return SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group";
118
}
119

  
120
sub _default_unit {
121
  return SL::DB::Manager::Unit->find_by(name => 'Stck') || die "No unit";
122
}
123

  
124

  
47 125
1;
48 126

  
49 127
__END__
......
71 149
                                         bin_id       => $wh->bins->[0]->id,
72 150
                                        )->save;
73 151

  
74
=head1 TODO
152
=head2 C<create_service %PARAMS>
153

  
154
Creates a new service (part_type = service).
155

  
156
Minimal usage, default values, without saving to database:
157

  
158
  my $part = SL::Dev::Part::create_service();
159

  
160
=head2 C<create_assembly %PARAMS>
161

  
162
Create a new assembly (part_type = assembly).
75 163

  
76
=over 2
164
By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1).
77 165

  
78
=item * create_assembly
166
  my $assembly = SL::Dev::Part::create_assembly->save;
79 167

  
80
=back
168
Create a new assembly with 10 parts:
169

  
170
  my $assembly = SL::Dev::Part::create_assembly(number_of_parts => 10)->save;
171

  
172
=head2 C<create_assortment %PARAMS>
173

  
174
Create a new assortment (part_type = assortment).
175

  
176
By default 3 parts (p1, p2, p3) are created and saved as an assortment.
177

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

  
180
Create a new assortment with 10 parts:
181

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

  
184

  
185
=head1 TODO
186

  
187
Nothing here yet.
81 188

  
82 189
=head1 BUGS
83 190

  

Auch abrufbar als: Unified diff