6 use_ok 'Support::TestSetup';
9 use_ok 'SL::DB::Warehouse';
12 use_ok('SL::DB::Inventory');
14 use constant NAME => 'UnitTestObject';
16 Support::TestSetup::login();
18 # Clean up: remove test objects for part, warehouse, bin
19 my $part = SL::DB::Manager::Part->get_first(partnumber => NAME(), description => NAME());
21 SL::DB::Manager::Inventory->delete_all(where => [ parts_id => $part->id ]);
25 SL::DB::Manager::Bin ->delete_all(where => [ or => [ description => NAME() . "1", description => NAME() . "2" ] ]);
26 SL::DB::Manager::Warehouse->delete_all(where => [ description => NAME() ]);
29 $part = SL::DB::Part->new(unit => 'mg', description => NAME(), partnumber => NAME());
32 is(ref($part), 'SL::DB::Part', 'loading a part to test with id ' . $part->id);
34 my $wh = SL::DB::Warehouse->new(description => NAME(), invalid => 0);
36 is(ref $wh, 'SL::DB::Warehouse', 'loading a warehouse to test with id ' . $wh->id);
38 my $bin1 = SL::DB::Bin->new(description => NAME() . "1", warehouse_id => $wh->id);
40 is(ref $bin1, 'SL::DB::Bin', 'getting first bin to test with id ' . $bin1->id);
42 my $bin2 = SL::DB::Bin->new(description => NAME() . "2", warehouse_id => $wh->id);
44 is(ref $bin2, 'SL::DB::Bin', 'getting another bin to test with id ' . $bin2->id);
47 $::form->{l_warehouseid} = 'Y';
48 $::form->{l_binid} = 'Y';
49 my ($result) = WH->get_warehouse_report(
50 warehouse_id => $wh->id,
60 my ($arg_sub, @transfers) = @_;
61 my $before = $report->();
63 WH->transfer(@transfers);
65 my $after = $report->();
66 my @args = $arg_sub->($before, $after);
68 is $args[0], $args[1], $args[2];
71 test { shift->{qty}, shift->{qty} + 4, 'transfer one way' } {
72 transfer_type => 'transfer',
73 parts_id => $part->id,
74 src_warehouse_id => $wh->id,
75 dst_warehouse_id => $wh->id,
76 src_bin_id => $bin1->id,
77 dst_bin_id => $bin2->id,
82 #################################################
84 test { shift->{qty}, shift->{qty} - 4, 'and back' } {
85 transfer_type => 'transfer',
86 parts_id => $part->id,
87 src_warehouse_id => $wh->id,
88 dst_warehouse_id => $wh->id,
89 src_bin_id => $bin2->id,
90 dst_bin_id => $bin1->id,
95 #################################################
97 test {shift->{qty}, shift->{qty} + 4000000000, 'transfer one way with unit'} {
98 transfer_type => 'transfer',
99 parts_id => $part->id,
100 src_warehouse_id => $wh->id,
101 dst_warehouse_id => $wh->id,
102 src_bin_id => $bin1->id,
103 dst_bin_id => $bin2->id,
109 ##############################################
111 use_ok 'SL::DB::TransferType';
113 # object interface test
115 test { shift->{qty}, shift->{qty} + 6.2, 'object transfer one way' } {
116 transfer_type => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
124 #############################################
126 test { shift->{qty}, shift->{qty} - 6.2, 'full object transfer back' } {
127 transfer_type => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
130 src_warehouse => $wh,
132 dst_warehouse => $wh,
137 #############################################
139 test { shift->{qty}, shift->{qty}, 'back and forth in one transaction' } {
140 transfer_type => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
143 src_warehouse => $wh,
145 dst_warehouse => $wh,
149 transfer_type => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
152 src_warehouse => $wh,
154 dst_warehouse => $wh,
158 #############################################
160 test { shift->{qty}, shift->{qty}, 'warehouse reduced interface' } {
161 transfer_type => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
168 transfer_type => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
176 SL::DB::Manager::Inventory->delete_objects(where => [parts_id => $part->id]);