Revision ec1dc3e8
Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt
SL/Dev/ALL.pm | ||
---|---|---|
1 |
package SL::Dev::ALL; |
|
2 |
|
|
3 |
use strict; |
|
4 |
|
|
5 |
use SL::Dev::Part; |
|
6 |
use SL::Dev::CustomerVendor; |
|
7 |
use SL::Dev::Inventory; |
|
8 |
|
|
9 |
1; |
|
10 |
|
|
11 |
__END__ |
|
12 |
|
|
13 |
=pod |
|
14 |
|
|
15 |
=head1 NAME |
|
16 |
|
|
17 |
SL::Dev::ALL: Dependency-only package for all SL::Dev::* modules |
|
18 |
|
|
19 |
=head1 SYNOPSIS |
|
20 |
|
|
21 |
use SL::Dev::ALL; |
|
22 |
|
|
23 |
=head1 DESCRIPTION |
|
24 |
|
|
25 |
This module depends on all modules in SL/Dev/*.pm for the convenience of being |
|
26 |
able to write a simple C<use SL::Dev::ALL> and having everything loaded. This |
|
27 |
is supposed to be used only for test cases or in the kivitendo console. Normal |
|
28 |
modules should C<use> only the modules they actually need. |
|
29 |
|
|
30 |
To automatically include it in the console, add a line in the client section of |
|
31 |
the kivitendo.config, e.g. |
|
32 |
|
|
33 |
[console] |
|
34 |
autorun = require "bin/mozilla/common.pl"; |
|
35 |
= use SL::DB::Helper::ALL; |
|
36 |
= use SL::Dev::ALL; |
|
37 |
|
|
38 |
=head1 AUTHOR |
|
39 |
|
|
40 |
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt> |
|
41 |
|
|
42 |
=cut |
SL/Dev/CustomerVendor.pm | ||
---|---|---|
1 |
package SL::Dev::CustomerVendor; |
|
2 |
|
|
3 |
use base qw(Exporter); |
|
4 |
@EXPORT = qw(create_customer); |
|
5 |
|
|
6 |
use SL::DB::TaxZone; |
|
7 |
use SL::DB::Currency; |
|
8 |
use SL::DB::Customer; |
|
9 |
|
|
10 |
sub create_customer { |
|
11 |
my (%params) = @_; |
|
12 |
|
|
13 |
my ($taxzone, $currency); |
|
14 |
|
|
15 |
if ( my $taxzone_id = delete $params{taxzone_id} ) { |
|
16 |
$taxzone = SL::DB::Manager::TaxZone->find_by( id => $taxzone_id ) || die "Can't find taxzone_id"; |
|
17 |
} else { |
|
18 |
$taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || die "No taxzone 'Inland'"; |
|
19 |
} |
|
20 |
|
|
21 |
if ( my $currency_id = delete $params{currency_id} ) { |
|
22 |
$currency = SL::DB::Manager::Currency->find_by( id => $currency_id ) || die "Can't find currency_id"; |
|
23 |
} else { |
|
24 |
$currency = SL::DB::Manager::Currency->find_by( id => $::instance_conf->get_currency_id ); |
|
25 |
} |
|
26 |
|
|
27 |
my $customer = SL::DB::Customer->new( name => delete $params{name} || 'Testkunde', |
|
28 |
currency_id => $currency->id, |
|
29 |
taxzone_id => $taxzone->id, |
|
30 |
); |
|
31 |
$customer->assign_attributes( %params ); |
|
32 |
return $customer; |
|
33 |
} |
|
34 |
|
|
35 |
1; |
|
36 |
|
|
37 |
__END__ |
|
38 |
|
|
39 |
=head1 NAME |
|
40 |
|
|
41 |
SL::Dev::CustomerVendor - create customer and vendor objects for testing, with minimal defaults |
|
42 |
|
|
43 |
=head1 FUNCTIONS |
|
44 |
|
|
45 |
=head2 C<create_customer %PARAMS> |
|
46 |
|
|
47 |
Creates a new customer. |
|
48 |
|
|
49 |
Minimal usage, default values, without saving to database: |
|
50 |
|
|
51 |
my $customer = SL::Dev::CustomerVendor::create_customer(); |
|
52 |
|
|
53 |
Complex usage, overwriting some defaults, and save to database: |
|
54 |
SL::Dev::CustomerVendor::create_customer(name => 'Test customer', |
|
55 |
hourly_rate => 50, |
|
56 |
taxzone_id => 2, |
|
57 |
)->save; |
|
58 |
|
|
59 |
|
|
60 |
=head1 BUGS |
|
61 |
|
|
62 |
Nothing here yet. |
|
63 |
|
|
64 |
=head1 AUTHOR |
|
65 |
|
|
66 |
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt> |
|
67 |
|
|
68 |
=cut |
|
69 |
1; |
SL/Dev/Inventory.pm | ||
---|---|---|
1 |
package SL::Dev::Inventory; |
|
2 |
|
|
3 |
use base qw(Exporter); |
|
4 |
@EXPORT = qw(create_warehouse_and_bins set_stock); |
|
5 |
|
|
6 |
use SL::DB::Warehouse; |
|
7 |
use SL::DB::Bin; |
|
8 |
use SL::DB::Inventory; |
|
9 |
use SL::DB::TransferType; |
|
10 |
use SL::DB::Employee; |
|
11 |
|
|
12 |
sub create_warehouse_and_bins { |
|
13 |
my (%params) = @_; |
|
14 |
|
|
15 |
my $number_of_bins = $params{number_of_bins} || 5; |
|
16 |
my $wh = SL::DB::Warehouse->new(description => $params{warehouse_description} || "Warehouse", invalid => 0); |
|
17 |
for my $i ( 1 .. $number_of_bins ) { |
|
18 |
$wh->add_bins( SL::DB::Bin->new(description => ( $params{bin_description} || "Bin" ) . " $i" ) ); |
|
19 |
} |
|
20 |
$wh->save; |
|
21 |
return ($wh, $wh->bins->[0]); |
|
22 |
} |
|
23 |
|
|
24 |
sub set_stock { |
|
25 |
my ($part, %params) = @_; |
|
26 |
|
|
27 |
die "first argument is not a part" unless ref($part) eq 'SL::DB::Part'; |
|
28 |
|
|
29 |
die "no default warehouse" unless $part->warehouse_id or $part->bin_id; |
|
30 |
|
|
31 |
die "Can't determine employee" unless SL::DB::Manager::Employee->current; |
|
32 |
|
|
33 |
die "qty is missing or not positive" unless $params{qty} and $params{qty} > 0; |
|
34 |
|
|
35 |
my $transfer_type_description = delete $params{transfer_type} || 'stock'; |
|
36 |
my $transfer_type = SL::DB::Manager::TransferType->find_by( description => $transfer_type_description, direction => 'in' ); |
|
37 |
|
|
38 |
my $shippingdate; |
|
39 |
if ( $params{shippingdate} ) { |
|
40 |
$shippingdate = $::locale->parse_date_to_object(delete $params{shippingdate}); |
|
41 |
} else { |
|
42 |
$shippingdate = DateTime->today; |
|
43 |
}; |
|
44 |
|
|
45 |
my ($trans_id) = $part->db->dbh->selectrow_array("select nextval('id')", {}); |
|
46 |
|
|
47 |
SL::DB::Inventory->new( |
|
48 |
parts_id => $part->id, |
|
49 |
bin_id => $part->bin_id, |
|
50 |
warehouse_id => $part->warehouse_id, |
|
51 |
employee_id => $params{employee_id} || SL::DB::Manager::Employee->current->id, |
|
52 |
trans_type_id => $transfer_type->id, |
|
53 |
comment => $params{comment}, |
|
54 |
shippingdate => $shippingdate, |
|
55 |
qty => $params{qty}, |
|
56 |
trans_id => $trans_id, |
|
57 |
)->save; |
|
58 |
} |
|
59 |
|
|
60 |
1; |
|
61 |
|
|
62 |
__END__ |
|
63 |
|
|
64 |
=head1 NAME |
|
65 |
|
|
66 |
SL::Dev::Inventory - create inventory-related objects for testing, with minimal |
|
67 |
defaults |
|
68 |
|
|
69 |
=head1 FUNCTIONS |
|
70 |
|
|
71 |
=head2 C<create_warehouse_and_bins %PARAMS> |
|
72 |
|
|
73 |
Creates a new warehouse and bins, and immediately saves them. Returns the |
|
74 |
warehouse and the first bin object. |
|
75 |
my ($wh, $bin) = SL::Dev::Inventory::create_warehouse_and_bins(); |
|
76 |
|
|
77 |
Create named warehouse with 10 bins: |
|
78 |
my ($wh, $bin) = SL::Dev::Inventory::create_warehouse_and_bins(warehouse_description => 'Testlager', |
|
79 |
bin_description => 'Testlagerplatz', |
|
80 |
number_of_bins => 10, |
|
81 |
); |
|
82 |
To access the second bin: |
|
83 |
my $bin2 = $wh->bins->[1]; |
|
84 |
|
|
85 |
=head2 C<set_stock $part, %PARAMS> |
|
86 |
|
|
87 |
Increase the stock level of a certain part by creating an inventory event. Currently |
|
88 |
only positive stock levels can be set. To access the updated onhand the part |
|
89 |
object needs to be loaded afterwards. |
|
90 |
|
|
91 |
my $part = SL::DB::Manager::Part->find_by(partnumber => '1'); |
|
92 |
SL::Dev::Inventory::set_stock($part, 5); |
|
93 |
$part->load; |
|
94 |
|
|
95 |
=head1 BUGS |
|
96 |
|
|
97 |
Nothing here yet. |
|
98 |
|
|
99 |
=head1 AUTHOR |
|
100 |
|
|
101 |
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt> |
|
102 |
|
|
103 |
=cut |
SL/Dev/Part.pm | ||
---|---|---|
1 |
package SL::Dev::Part; |
|
2 |
|
|
3 |
use base qw(Exporter); |
|
4 |
@EXPORT = qw(create_part create_service); |
|
5 |
|
|
6 |
use SL::DB::Part; |
|
7 |
use SL::DB::Unit; |
|
8 |
use SL::DB::Buchungsgruppe; |
|
9 |
|
|
10 |
sub create_part { |
|
11 |
my (%params) = @_; |
|
12 |
|
|
13 |
my ($buchungsgruppe, $unit); |
|
14 |
$buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group"; |
|
15 |
$unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "No unit"; |
|
16 |
|
|
17 |
my $part = SL::DB::Part->new_part( |
|
18 |
description => 'Test part', |
|
19 |
sellprice => '10', |
|
20 |
lastcost => '5', |
|
21 |
buchungsgruppen_id => $buchungsgruppe->id, |
|
22 |
unit => $unit->name, |
|
23 |
); |
|
24 |
$part->assign_attributes( %params ); |
|
25 |
return $part; |
|
26 |
} |
|
27 |
|
|
28 |
sub create_service { |
|
29 |
my (%params) = @_; |
|
30 |
|
|
31 |
my ($buchungsgruppe, $unit); |
|
32 |
$buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || die "No accounting group"; |
|
33 |
$unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "No unit"; |
|
34 |
|
|
35 |
my $part = SL::DB::Part->new_service( |
|
36 |
description => 'Test service', |
|
37 |
sellprice => '10', |
|
38 |
lastcost => '5', |
|
39 |
buchungsgruppen_id => $buchungsgruppe->id, |
|
40 |
unit => $unit->name, |
|
41 |
); |
|
42 |
$part->assign_attributes( %params ); |
|
43 |
return $part; |
|
44 |
} |
|
45 |
|
|
46 |
1; |
|
47 |
|
|
48 |
__END__ |
|
49 |
|
|
50 |
=head1 NAME |
|
51 |
|
|
52 |
SL::Dev::Part - create part objects for testing, with minimal defaults |
|
53 |
|
|
54 |
=head1 FUNCTIONS |
|
55 |
|
|
56 |
=head2 C<create_part %PARAMS> |
|
57 |
|
|
58 |
Creates a new part (part_type = part). |
|
59 |
|
|
60 |
Minimal usage, default values, without saving to database: |
|
61 |
|
|
62 |
my $part = SL::Dev::Part::create_part(); |
|
63 |
|
|
64 |
Create a test part with a default warehouse and bin and save it: |
|
65 |
|
|
66 |
my $wh = SL::Dev::Inventory::create_warehouse_and_bins()->save; |
|
67 |
my $part1 = SL::Dev::Part::create_part(partnumber => 'a123', |
|
68 |
description => 'Testpart 1', |
|
69 |
warehouse_id => $wh->id, |
|
70 |
bin_id => $wh->bins->[0]->id, |
|
71 |
)->save; |
|
72 |
|
|
73 |
=head1 TODO |
|
74 |
|
|
75 |
=over 2 |
|
76 |
|
|
77 |
=item * create_assembly |
|
78 |
|
|
79 |
=back |
|
80 |
|
|
81 |
=head1 BUGS |
|
82 |
|
|
83 |
Nothing here yet. |
|
84 |
|
|
85 |
=head1 AUTHOR |
|
86 |
|
|
87 |
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt> |
|
88 |
|
|
89 |
=cut |
Auch abrufbar als: Unified diff
SL::Dev::* - neue Helpermodule für Testcases und console
Mit Funktionen zum Generieren von Artikeln, Kunden und Lager- und
Lagerplätzen.