Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision cf3a8cf7

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

  • ID cf3a8cf79ac2f6228b298ef260f3471490c3132b
  • Vorgänger c878cea9
  • Nachfolger 63410aa6

SL::Dev: EXPORT rewrite und create/new split

- SL::Dev module exportieren nicht mehr ungefragt
- SL::Dev::ALL exportiert jetzt den übergebenen tag aus allen Modulen
- Funktionen nicht nicht speichern (Part/CustomerVendor) heißen jetzt
"new_X" anstatt "create_X"

Unterschiede anzeigen:

SL/Dev/ALL.pm
2 2

  
3 3
use strict;
4 4

  
5
use Exporter;
5 6
use SL::Dev::Part;
6 7
use SL::Dev::CustomerVendor;
7 8
use SL::Dev::Inventory;
8 9
use SL::Dev::Record;
9 10
use SL::Dev::Payment;
10 11

  
12
sub import {
13
  no strict "refs";
14
  for (qw(Part CustomerVendor Inventory Record Payment)) {
15
    Exporter::export_to_level("SL::Dev::$_", 1, @_);
16
  }
17
}
18

  
19

  
11 20
1;
12 21

  
13 22
__END__
SL/Dev/CustomerVendor.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(create_customer create_vendor);
5
our @EXPORT_OK = qw(new_customer new_vendor);
6
our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
6 7

  
7 8
use SL::DB::TaxZone;
8 9
use SL::DB::Currency;
9 10
use SL::DB::Customer;
10 11

  
11
sub create_customer {
12
sub new_customer {
12 13
  my (%params) = @_;
13 14

  
14 15
  my $taxzone    = _check_taxzone(delete $params{taxzone_id});
......
22 23
  return $customer;
23 24
}
24 25

  
25
sub create_vendor {
26
sub new_vendor {
26 27
  my (%params) = @_;
27 28

  
28 29
  my $taxzone    = _check_taxzone(delete $params{taxzone_id});
......
69 70

  
70 71
=head1 FUNCTIONS
71 72

  
72
=head2 C<create_customer %PARAMS>
73
=head2 C<new_customer %PARAMS>
73 74

  
74 75
Creates a new customer.
75 76

  
......
87 88
If neither taxzone_id or currency_id (both are NOT NULL) are passed as params
88 89
then default values are used.
89 90

  
90
=head2 C<create_vendor %PARAMS>
91
=head2 C<new_vendor %PARAMS>
91 92

  
92 93
Creates a new vendor.
93 94

  
SL/Dev/File.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(create_scanned create_uploaded create_created get_all_count get_all get_all_versions delete_all);
5
our @EXPORT_OK = qw(create_scanned create_uploaded create_created);
6
our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
6 7

  
7 8
use SL::DB::File;
8 9

  
10
my %common_params = (
11
  object_id   => 1,
12
  object_type => 'sales_order',
13
);
14

  
9 15
sub create_scanned {
10 16
  my (%params) = @_;
11 17
  $params{source}    = 'scanner1';
......
38 44
  my (%params) = @_;
39 45

  
40 46
  my $fileobj = SL::File->save(
41
    object_id          => 1,
42
    object_type        => 'sales_order',
47
    %common_params,
43 48
    mime_type          => 'text/plain',
44 49
    description        => 'Test File',
45 50
    file_type          => $params{file_type},
......
51 56
  return $fileobj;
52 57
}
53 58

  
54
sub get_all_count {
55
  my ($class,%params) = @_;
56
  $params{object_id}   = 1;
57
  $params{object_type} = 'sales_order';
58
  return SL::File->get_all_count(%params);
59
}
60

  
61
sub get_all {
62
  my ($class,%params) = @_;
63
  $params{object_id}   = 1;
64
  $params{object_type} = 'sales_order';
65
  SL::File->get_all(%params);
66
}
67

  
68
sub get_all_versions {
69
  my ($class,%params) = @_;
70
  $params{object_id}   = 1;
71
  $params{object_type} = 'sales_order';
72
  SL::File->get_all_versions(%params);
73
}
59
sub get_all          { SL::File->get_all         (%common_params, @_) }
60
sub get_all_count    { SL::File->get_all_count   (%common_params, @_) }
61
sub get_all_versions { SL::File->get_all_versions(%common_params, @_) }
62
sub delete_all       { SL::File->delete_all      (%common_params, @_) }
74 63

  
75
sub delete_all {
76
  my ($class,%params) = @_;
77
  $params{object_id}   = 1;
78
  $params{object_type} = 'sales_order';
79
  SL::File->delete_all(%params);
80
}
81 64
1;
82 65

  
83 66
__END__
......
94 77

  
95 78
=head2 C<create_created %PARAMS>
96 79

  
97
=head2 C<delete_all>
98

  
99 80
=head1 AUTHOR
100 81

  
101 82
Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
SL/Dev/Inventory.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(
5
our @EXPORT_OK = qw(
6 6
  create_warehouse_and_bins set_stock transfer_stock
7 7
  transfer_sales_delivery_order transfer_purchase_delivery_order
8 8
  transfer_delivery_order_item transfer_in transfer_out
9 9
);
10
our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
10 11

  
11 12
use SL::DB::Warehouse;
12 13
use SL::DB::Bin;
SL/Dev/Part.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(create_part create_service create_assembly create_assortment);
5
our @EXPORT_OK = qw(new_part new_service new_assembly new_assortment);
6
our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
6 7

  
7 8
use SL::DB::Part;
8 9
use SL::DB::Unit;
9 10
use SL::DB::Buchungsgruppe;
10 11

  
11
sub create_part {
12
sub new_part {
12 13
  my (%params) = @_;
13 14

  
14 15
  my $part = SL::DB::Part->new_part(
......
22 23
  return $part;
23 24
}
24 25

  
25
sub create_service {
26
sub new_service {
26 27
  my (%params) = @_;
27 28

  
28 29
  my $part = SL::DB::Part->new_service(
......
36 37
  return $part;
37 38
}
38 39

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

  
42 43
  my $assnumber       = delete $params{assnumber};
......
48 49
    $assembly_items = delete $params{assembly_items};
49 50
  } else {
50 51
    for my $i ( 1 .. delete $params{number_of_parts} || 3) {
51
      my $part = SL::Dev::Part::create_part(partnumber  => "$base_partnumber $i",
52
                                            description => "Testpart $i",
53
                                           )->save;
52
      my $part = new_part(partnumber  => "$base_partnumber $i",
53
                             description => "Testpart $i",
54
                            )->save;
54 55
      push( @{$assembly_items}, SL::DB::Assembly->new(parts_id => $part->id,
55 56
                                                      qty      => 1,
56 57
                                                      position => $i,
......
71 72
  return $assembly;
72 73
}
73 74

  
74
sub create_assortment {
75
sub new_assortment {
75 76
  my (%params) = @_;
76 77

  
77 78
  my $assnumber       = delete $params{assnumber};
......
83 84
    $assortment_items = delete $params{assortment_items};
84 85
  } else {
85 86
    for my $i ( 1 .. delete $params{number_of_parts} || 3) {
86
      my $part = SL::Dev::Part::create_part(partnumber  => "$base_partnumber $i",
87
                                            description => "Testpart $i",
88
                                           )->save;
87
      my $part = new_part(partnumber  => "$base_partnumber $i",
88
                             description => "Testpart $i",
89
                            )->save;
89 90
      push( @{$assortment_items}, SL::DB::AssortmentItem->new(parts_id => $part->id,
90 91
                                                              qty      => 1,
91 92
                                                              position => $i,
......
126 127

  
127 128
SL::Dev::Part - create part objects for testing, with minimal defaults
128 129

  
130
=head1 SYNOPSIS
131

  
132
  use SL::DEV::Part qw(new_part new_assembly new_service new_assortment);
133

  
134
  # simple default objects
135
  my $part     = new_part()->save;
136
  my $assembly = new_assembly()->save;
137
  my $service  = new_service()->save;
138
  my $assortment = new_assortment()->save;
139

  
140
  # pass additional params to the generated object
141
  # see individual functions for special parameters
142
  my $part     = new_part(
143
    partnumber   => 'Test 001',
144
    warehouse_id => $bin->warehouse->id,
145
    bin_id       => $bin->id,
146
  );
147

  
129 148
=head1 FUNCTIONS
130 149

  
131
=head2 C<create_part %PARAMS>
150
=head2 C<new_part %PARAMS>
132 151

  
133 152
Creates a new part (part_type = part).
134 153

  
135
Minimal usage, default values, without saving to database:
154
=head2 C<new_service %PARAMS>
155

  
156
Creates a new service (part_type = service).
136 157

  
137
  my $part = SL::Dev::Part::create_part();
158
=head2 C<new_assembly %PARAMS>
138 159

  
139
Create a test part with a default warehouse and bin and save it:
160
Create a new assembly (part_type = assembly).
140 161

  
141
  my $wh    = SL::Dev::Inventory::create_warehouse_and_bins()->save;
142
  my $part1 = SL::Dev::Part::create_part(partnumber   => 'a123',
143
                                         description  => 'Testpart 1',
144
                                         warehouse_id => $wh->id,
145
                                         bin_id       => $wh->bins->[0]->id,
146
                                        )->save;
162
Special params:
147 163

  
148
=head2 C<create_service %PARAMS>
164
=over 2
149 165

  
150
Creates a new service (part_type = service).
166
=item * C<number_of_parts>
151 167

  
152
Minimal usage, default values, without saving to database:
168
The number of automatically created assembly parts.
153 169

  
154
  my $part = SL::Dev::Part::create_service();
170
=item * C<assnumber>
155 171

  
156
=head2 C<create_assembly %PARAMS>
172
the partnumber of the assembly
157 173

  
158
Create a new assembly (part_type = assembly).
174
=item * C<partnumber>
159 175

  
160
Params: assnumber:  the partnumber of the assembly
161
        partnumber: the partnumber of the first assembly part to be created
176
the partnumber of the first assembly part to be created
162 177

  
163
By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1).
178
=back
164 179

  
165
  my $assembly = SL::Dev::Part::create_assembly->save;
180
By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1).
166 181

  
167 182
Create a new assembly with 10 parts, the assembly gets partnumber 'Ass1' and the
168 183
parts get partnumbers 'Testpart 1' to 'Testpart 10':
169 184

  
170
  my $assembly = SL::Dev::Part::create_assembly(number_of_parts => 10,
171
                                                partnumber      => 'Testpart',
172
                                                assnumber       => 'Ass1'
173
                                               )->save;
185
  my $assembly = SL::Dev::Part::new_assembly(
186
    number_of_parts => 10,
187
    partnumber      => 'Testpart',
188
    assnumber       => 'Ass1'
189
  )->save;
174 190

  
175 191
Create an assembly with specific parts:
192

  
176 193
  my $assembly_item_1 = SL::DB::Assembly->new( parts_id => $part1->id, qty => 3, position => 1);
177 194
  my $assembly_item_2 = SL::DB::Assembly->new( parts_id => $part2->id, qty => 3, position => 2);
178
  my $assembly_part   = SL::Dev::Part::create_assembly( assnumber      => 'Assembly 1',
179
                                                        description    => 'Assembly test',
180
                                                        sellprice      => $part1->sellprice + $part2->sellprice,
181
                                                        assembly_items => [ $assembly_item_1, $assembly_item_2 ],
182
                                                      )->save;
195
  my $assembly_part   = new_assembly(
196
    assnumber      => 'Assembly 1',
197
    description    => 'Assembly test',
198
    sellprice      => $part1->sellprice + $part2->sellprice,
199
    assembly_items => [ $assembly_item_1, $assembly_item_2 ],
200
  );
183 201

  
184
=head2 C<create_assortment %PARAMS>
202
=head2 C<new_assortment %PARAMS>
185 203

  
186 204
Create a new assortment (part_type = assortment).
187 205

  
188
By default 3 parts (p1, p2, p3) are created and saved as an assortment.
206
Special params:
207

  
208
=over 2
209

  
210
=item * C<number_of_parts>
211

  
212
The number of automatically created assembly parts.
189 213

  
190
  my $assortment = SL::Dev::Part::create_assortment->save;
214
=item * C<assnumber>
215

  
216
the partnumber of the assortment
217

  
218
=item * C<partnumber>
219

  
220
the partnumber of the first assembly part to be created
221

  
222
=back
223

  
224
By default 3 parts (p1, p2, p3) are created and saved as an assortment.
191 225

  
192 226
Create a new assortment with 10 automatically created parts using the
193 227
number_of_parts param:
194 228

  
195
  my $assortment = SL::Dev::Part::create_assortment(number_of_parts => 10)->save;
229
  my $assortment = new_assortment(number_of_parts => 10)->save;
196 230

  
197 231
Create an assortment with a certain name and pass some assortment_item Objects
198 232
from newly created parts:
199 233

  
200
  my $part1             = SL::Dev::Part::create_part( sellprice => '7.77')->save;
201
  my $part2             = SL::Dev::Part::create_part( sellprice => '6.66')->save;
234
  my $part1             = new_part(sellprice => 7.77)->save;
235
  my $part2             = new_part(sellprice => 6.66)->save;
202 236
  my $assortment_item_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1);
203 237
  my $assortment_item_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2);
204
  my $assortment_part   = SL::Dev::Part::create_assortment( assnumber        => 'Assortment 1',
205
                                                            description      => 'assortment test',
206
                                                            sellprice        => (3*$part1->sellprice + 3*$part2->sellprice),
207
                                                            lastcost         => (3*$part1->lastcost  + 3*$part2->lastcost),
208
                                                            assortment_items => [ $assortment_item_1, $assortment_item_2 ],
209
                                                          )->save;
238
  my $assortment_part   = SL::Dev::Part::new_assortment(
239
    assnumber        => 'Assortment 1',
240
    description      => 'assortment test',
241
    sellprice        => (3*$part1->sellprice + 3*$part2->sellprice),
242
    lastcost         => (3*$part1->lastcost  + 3*$part2->lastcost),
243
    assortment_items => [ $assortment_item_1, $assortment_item_2 ],
244
  )->save;
210 245

  
211 246
=head1 TODO
212 247

  
SL/Dev/Payment.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(create_payment_terms create_bank_account create_bank_transaction);
5
our @EXPORT_OK = qw(create_payment_terms create_bank_account create_bank_transaction create_sepa_export create_sepa_export_item);
6
our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
6 7

  
7 8
use SL::DB::PaymentTerm;
8 9
use SL::DB::BankAccount;
SL/Dev/Record.pm
2 2

  
3 3
use strict;
4 4
use base qw(Exporter);
5
our @EXPORT = qw(create_invoice_item create_sales_invoice create_credit_note create_order_item  create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_purchase_delivery_order create_project);
5
our @EXPORT_OK = qw(create_invoice_item create_sales_invoice create_credit_note create_order_item  create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_purchase_delivery_order create_project);
6
our %EXPORT_TAGS = (ALL => \@EXPORT_OK);
6 7

  
7 8
use SL::DB::Invoice;
8 9
use SL::DB::InvoiceItem;
9 10
use SL::DB::Employee;
10
use SL::Dev::Part;
11
use SL::Dev::CustomerVendor;
11
use SL::Dev::Part qw(new_part);
12
use SL::Dev::CustomerVendor qw(new_vendor new_customer);
12 13
use SL::DB::Project;
13 14
use SL::DB::ProjectStatus;
14 15
use SL::DB::ProjectType;
......
28 29
  my $invoiceitems = delete $params{invoiceitems} // _create_two_items($record_type);
29 30
  _check_items($invoiceitems, $record_type);
30 31

  
31
  my $customer = delete $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save;
32
  my $customer = delete $params{customer} // new_customer(name => 'Testcustomer')->save;
32 33
  die "illegal customer" unless defined $customer && ref($customer) eq 'SL::DB::Customer';
33 34

  
34 35
  my $invoice = SL::DB::Invoice->new(
......
59 60
  my $invoiceitems = delete $params{invoiceitems} // _create_two_items($record_type);
60 61
  _check_items($invoiceitems, $record_type);
61 62

  
62
  my $customer = delete $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save;
63
  my $customer = delete $params{customer} // new_customer(name => 'Testcustomer')->save;
63 64
  die "illegal customer" unless defined $customer && ref($customer) eq 'SL::DB::Customer';
64 65

  
65 66
  # adjust qty for credit note items
......
93 94
  my $orderitems = delete $params{orderitems} // _create_two_items($record_type);
94 95
  _check_items($orderitems, $record_type);
95 96

  
96
  my $customer = $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save;
97
  my $customer = $params{customer} // new_customer(name => 'Testcustomer')->save;
97 98
  die "illegal customer" unless ref($customer) eq 'SL::DB::Customer';
98 99

  
99 100
  my $delivery_order = SL::DB::DeliveryOrder->new(
......
121 122
  my $orderitems = delete $params{orderitems} // _create_two_items($record_type);
122 123
  _check_items($orderitems, $record_type);
123 124

  
124
  my $vendor = $params{vendor} // SL::Dev::CustomerVendor::create_vendor(name => 'Testvendor')->save;
125
  my $vendor = $params{vendor} // new_vendor(name => 'Testvendor')->save;
125 126
  die "illegal customer" unless ref($vendor) eq 'SL::DB::Vendor';
126 127

  
127 128
  my $delivery_order = SL::DB::DeliveryOrder->new(
......
151 152

  
152 153
  my $save = delete $params{save} // 0;
153 154

  
154
  my $customer = $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save;
155
  my $customer = $params{customer} // new_customer(name => 'Testcustomer')->save;
155 156
  die "illegal customer" unless ref($customer) eq 'SL::DB::Customer';
156 157

  
157 158
  my $order = SL::DB::Order->new(
......
182 183

  
183 184
  my $save = delete $params{save} // 0;
184 185

  
185
  my $vendor = $params{vendor} // SL::Dev::CustomerVendor::create_vendor(name => 'Testvendor')->save;
186
  my $vendor = $params{vendor} // new_vendor(name => 'Testvendor')->save;
186 187
  die "illegal vendor" unless ref($vendor) eq 'SL::DB::Vendor';
187 188

  
188 189
  my $order = SL::DB::Order->new(
......
263 264
sub _create_two_items {
264 265
  my ($record_type) = @_;
265 266

  
266
  my $part1 = SL::Dev::Part::create_part(description => 'Testpart 1',
267
                                         sellprice   => 12,
268
                                        )->save;
269
  my $part2 = SL::Dev::Part::create_part(description => 'Testpart 2',
270
                                         sellprice   => 10,
271
                                        )->save;
267
  my $part1 = new_part(description => 'Testpart 1',
268
                       sellprice   => 12,
269
                      )->save;
270
  my $part2 = new_part(description => 'Testpart 2',
271
                       sellprice   => 10,
272
                      )->save;
272 273
  my $item1 = _create_item(record_type => $record_type, part => $part1, qty => 5);
273 274
  my $item2 = _create_item(record_type => $record_type, part => $part2, qty => 8);
274 275
  return [ $item1, $item2 ];

Auch abrufbar als: Unified diff