Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision a7a4d403

Von Tamino Steinert vor etwa 1 Jahr hinzugefügt

  • ID a7a4d403f6015a9dca8834b813f1999377efd5f5
  • Vorgänger 6d3fd0b0
  • Nachfolger c307d4a1

DispositionManager: Tests hinzugefügt

Unterschiede anzeigen:

SL/Dev/Part.pm
141 141
  # see individual functions for special parameters
142 142
  my $part     = new_part(
143 143
    partnumber   => 'Test 001',
144
    warehouse_id => $bin->warehouse->id,
145
    bin_id       => $bin->id,
144
    rop          => 20,
146 145
  );
147 146

  
148 147
=head1 FUNCTIONS
t/controllers/disposition_manager/disposition_manager.t
1
use strict;
2
use Test::More tests => 9;
3

  
4
use lib 't';
5
use Support::TestSetup;
6
use Test::Exception;
7
use SL::DB::Part;
8
use SL::DB::Inventory;
9
use SL::DB::MakeModel;
10
use SL::DB::PurchaseBasketItem;
11
use SL::Controller::DispositionManager;
12
use DateTime;
13
use Data::Dumper;
14
use SL::Dev::Part qw(new_part);
15
use SL::Dev::Inventory qw(create_warehouse_and_bins set_stock);
16
use SL::Dev::CustomerVendor qw(new_vendor);
17

  
18
use utf8;
19

  
20
Support::TestSetup::login();
21
clear_up();
22

  
23
my ($wh, $bin) = create_warehouse_and_bins();
24
my $vendor = new_vendor()->save;
25

  
26
my $part1 = new_part(
27
  partnumber   => 'TP 1',
28
  description  => 'Testpart 1 rop no stock',
29
  sellprice    => 5,
30
  lastcost     => 3,
31
  rop          => 20,
32
  order_qty    => 1,
33
  warehouse_id => $wh->id,
34
  bin_id       => $bin->id,
35
  makemodels   => [ _create_makemodel_for_vendor(vendor => $vendor) ],
36
)->save;
37

  
38
my $part2 = new_part(
39
  partnumber   => 'TP 2',
40
  description  => 'Testpart 2 norop',
41
  rop          => 60,
42
  order_qty    => 2,
43
)->save;
44
set_stock(part => $part2, bin_id => $bin->id, qty => 80);
45

  
46
for my $i (1 .. 10) {
47
  my $part = new_part(
48
    partnumber   => "TPO $i",
49
    description  => "Testpart onhand $i",
50
    rop          => 50,
51
    order_qty    => $i+2,
52
    sellprice    => 5,
53
    lastcost     => 3,
54
    warehouse_id => $wh->id,
55
    bin_id       => $bin->id,
56
    makemodels   => [ _create_makemodel_for_vendor(vendor => $vendor) ],
57
  )->save;
58
  set_stock(part => $part, bin_id => $bin->id, qty => ($i * 10));
59
}
60

  
61
my $controller = SL::Controller::DispositionManager->new();
62
my $reorder_parts = $controller->_get_parts;
63
is(scalar @{$reorder_parts}, 5, "found 5 parts where onhand < rop");
64

  
65
# die; # die here if you want to test making basket manually
66

  
67
note('creating purchase basket items');
68
$::form = Support::TestSetup->create_new_form;
69
$::form->{ids} = [ map { $_->id } @{$reorder_parts} ];
70

  
71
# call action_add_to_purchase_basket while redirecting rendered HTML output
72
my $output;
73
open(my $outputFH, '>', \$output) or die;
74
my $oldFH = select $outputFH;
75
$controller->action_add_to_purchase_basket;
76
select $oldFH;
77
close $outputFH;
78

  
79
is(SL::DB::Manager::PurchaseBasketItem->get_all_count(), 5, "5 items in purchase basket ok");
80

  
81
# die; # die here if you want to test creating purchase orders manually
82

  
83
note('making purchase order from purchase basket items');
84
my $purchase_basket_items = SL::DB::Manager::PurchaseBasketItem->get_all;
85
$::form = Support::TestSetup->create_new_form;
86
$::form->{ids}        = [ map { $_->id       } @{ $purchase_basket_items } ];
87
$::form->{vendor_ids} = [ map { $vendor->id  } @{ $purchase_basket_items } ];
88

  
89
open($outputFH, '>', \$output) or die;
90
$oldFH = select $outputFH;
91
$controller->action_transfer_to_purchase_order;
92
select $oldFH;
93
close $outputFH;
94

  
95
is(SL::DB::Manager::Order->get_all_count( where => [ SL::DB::Manager::Order->type_filter('purchase_order') ] ), 1, "1 purchase order created ok");
96
is(SL::DB::Manager::PurchaseBasketItem->get_all_count(), 0, "purchase basket empty after purchase order was created");
97

  
98
my $purchase_order = SL::DB::Manager::Order->get_first();
99

  
100
is( scalar @{$purchase_order->items}, 5, "Purchase order has 5 item ok");
101
# print "PART\n";
102
# print Dumper($part1);
103
my $first_item = $purchase_order->items_sorted->[0];
104
# print "FIRST\n";
105
# print Dumper($first_item);
106
is( $first_item->parts_id, $part1->id, "Purchase order: first item is part1");
107
is( $first_item->qty, '20.00000', "Purchase order: first item has qty 20");
108
cmp_ok( $purchase_order->netamount, '==', 240, "Purchase order: netamount ok");
109
is( $first_item->active_price_source, 'makemodel/' . $part1->makemodels->[0]->id, "Purchase order: first item has correct active_price_source" . $first_item->part->partnumber);
110

  
111
clear_up();
112
done_testing();
113

  
114
sub clear_up {
115
  my %params = @_;
116
  SL::DB::Manager::Inventory->delete_all(all => 1);
117
  SL::DB::Manager::Order->delete_all(all => 1);
118
  SL::DB::Manager::PurchaseBasketItem->delete_all(all => 1);
119
  SL::DB::Manager::MakeModel->delete_all(all => 1);
120
  SL::DB::Manager::Part->delete_all(all => 1);
121
  SL::DB::Manager::Vendor->delete_all(all => 1);
122
  SL::DB::Manager::Customer->delete_all(all => 1);
123
  SL::DB::Manager::Bin->delete_all(all => 1);
124
  SL::DB::Manager::Warehouse->delete_all(all => 1);
125
};
126

  
127
sub _create_makemodel_for_vendor {
128
  my %params = @_;
129

  
130
  my $vendor = delete $params{vendor};
131
  die "no vendor" unless ref($vendor) eq 'SL::DB::Vendor';
132

  
133
  my $mm = SL::DB::MakeModel->new(make          => $vendor->id,
134
                                  model         => '',
135
                                  lastcost      => 2,
136
                                  sortorder     => 1,
137
                                 );
138
  $mm->assign_attributes( %params );
139
  return $mm;
140
}
141

  
142
1;

Auch abrufbar als: Unified diff