5 use Support::TestSetup;
10 use SL::Dev::Inventory;
12 Support::TestSetup::login();
16 my ($wh1, $bin1_1) = SL::Dev::Inventory::create_warehouse_and_bins(
17 warehouse_description => 'Testlager',
18 bin_description => 'Testlagerplatz',
21 my $bin1_2 = $wh1->bins->[1];
22 my ($wh2, $bin2_1) = SL::Dev::Inventory::create_warehouse_and_bins(
23 warehouse_description => 'Testlager 2',
24 bin_description => 'Testlagerplatz 2',
28 my $today = DateTime->today;
29 my $yesterday = $today->clone->add(days => -1);
31 my $part = SL::Dev::Part::create_part->save;
32 SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_1->id, qty => 7, shippingdate => $yesterday);
33 SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_1->id, qty => 5);
34 SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_1->id, abs_qty => 8); # apply -4 to get qty 8 in bin1_1
35 SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_2->id, qty => 9);
37 SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin2_1->id, abs_qty => 10);
38 SL::Dev::Inventory::transfer_stock(part => $part,
39 from_bin => $wh2->bins->[0],
40 to_bin => $wh2->bins->[1],
44 is( SL::DB::Manager::Part->get_all_count(), 1, "total number of parts created is 1");
45 is( $part->get_stock == 27 , 1 , "total stock of part is 27");
46 is( $part->get_stock(shippingdate => $yesterday) == 7 , 1 , "total stock of part was 7 yesterday");
47 is( $part->get_stock(shippingdate => $today) == 27 , 1 , "total stock of part is 27");
48 is( $part->get_stock(bin_id => $bin1_1->id) == 8 , 1 , "total stock of part in bin1_1 is 8");
49 is( $part->get_stock(warehouse_id => $wh1->id) == 17 , 1 , "total stock of part in wh1 is 17");
50 is( $part->get_stock(warehouse_id => $wh2->id) == 10 , 1 , "total stock of part in wh2 is 10");
51 is( $part->get_stock(bin_id => $wh2->bins->[0]->id) == 8 , 1 , "total stock of part in wh2 2nd bin is 8 after transfer");
52 is( $part->get_stock(bin_id => $wh2->bins->[1]->id) == 2 , 1 , "total stock of part in wh2 2nd bin is 2 after transfer");
58 "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(Inventory Part Bin Warehouse);