6 use_ok 'Support::TestSetup';
 
   8 use_ok 'SL::DB::Warehouse';
 
  11 use_ok('SL::DB::Inventory');
 
  14 Support::TestSetup::login();
 
  16 my $part = SL::DB::Part->new(unit => 'mg', description => 'TestObject');
 
  19 is(ref($part), 'SL::DB::Part', 'loading a part to test with id ' . $part->id);
 
  22 my $wh = SL::DB::Manager::Warehouse->get_first;
 
  23 is(ref $wh, 'SL::DB::Warehouse', 'loading a warehouse to test with id ' . $wh->id);
 
  25 my $bin1 = $wh->bins->[0];
 
  26 is(ref $bin1, 'SL::DB::Bin', 'getting first bin to test with id ' . $bin1->id);
 
  28 my $bin2 = $wh->bins->[1];
 
  29 is(ref $bin2, 'SL::DB::Bin', 'getting another bin to test with id ' . $bin2->id);
 
  32   $::form->{l_warehouseid} = 'Y';
 
  33   $::form->{l_binid} = 'Y';
 
  34   my ($result) = WH->get_warehouse_report(
 
  35     warehouse_id => $wh->id,
 
  45   my ($arg_sub, @transfers) = @_;
 
  46   my $before = $report->();
 
  48   WH->transfer(@transfers);
 
  50   my $after  = $report->();
 
  51   my @args   = $arg_sub->($before, $after);
 
  53   is $args[0], $args[1], $args[2];
 
  56 test { shift->{qty}, shift->{qty} + 4, 'transfer one way' } {
 
  57    transfer_type    => 'transfer',
 
  58    parts_id         => $part->id,
 
  59    src_warehouse_id => $wh->id,
 
  60    dst_warehouse_id => $wh->id,
 
  61    src_bin_id       => $bin1->id,
 
  62    dst_bin_id       => $bin2->id,
 
  67 #################################################
 
  69 test { shift->{qty}, shift->{qty} - 4, 'and back' } {
 
  70    transfer_type    => 'transfer',
 
  71    parts_id         => $part->id,
 
  72    src_warehouse_id => $wh->id,
 
  73    dst_warehouse_id => $wh->id,
 
  74    src_bin_id       => $bin2->id,
 
  75    dst_bin_id       => $bin1->id,
 
  80 #################################################
 
  82 test {shift->{qty}, shift->{qty} + 4000000000, 'transfer one way with unit'} {
 
  83    transfer_type    => 'transfer',
 
  84    parts_id         => $part->id,
 
  85    src_warehouse_id => $wh->id,
 
  86    dst_warehouse_id => $wh->id,
 
  87    src_bin_id       => $bin1->id,
 
  88    dst_bin_id       => $bin2->id,
 
  94 ##############################################
 
  96 use_ok 'SL::DB::TransferType';
 
  98 # object interface test
 
 100 test { shift->{qty}, shift->{qty} + 6.2, 'object transfer one way' } {
 
 101    transfer_type    => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
 
 109 #############################################
 
 111 test { shift->{qty}, shift->{qty} - 6.2, 'full object transfer back' } {
 
 112    transfer_type    => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
 
 115    src_warehouse    => $wh,
 
 117    dst_warehouse    => $wh,
 
 122 #############################################
 
 124 test { shift->{qty}, shift->{qty}, 'back and forth in one transaction' } {
 
 125    transfer_type    => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
 
 128    src_warehouse    => $wh,
 
 130    dst_warehouse    => $wh,
 
 134    transfer_type    => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
 
 137    src_warehouse    => $wh,
 
 139    dst_warehouse    => $wh,
 
 143 #############################################
 
 145 test { shift->{qty}, shift->{qty}, 'warehouse reduced interface' } {
 
 146    transfer_type    => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
 
 153    transfer_type    => SL::DB::Manager::TransferType->find_by(description => 'transfer'),
 
 161 SL::DB::Manager::Inventory->delete_objects(where => [parts_id => $part->id]);