Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4cb05cc1

Von Kivitendo Admin vor mehr als 1 Jahr hinzugefügt

  • ID 4cb05cc1379b91cd436088cbcb4f9ce2acff16e7
  • Vorgänger 4bd64342
  • Nachfolger c7ad052c

Disposition Manager - ein paar Änderungen

  • erster Testfall
  • _get_parts in action_list_parts ausgelagert (besser testbar)
  • Formatierung und Typos

Unterschiede anzeigen:

SL/Controller/DispositionsManager.pm
1 1
package SL::Controller::DispositionsManager;
2 2

  
3

  
4 3
use strict;
5 4

  
6 5
use parent qw(SL::Controller::Base);
......
12 11
sub action_list_parts {
13 12
  my ( $self ) = @_;
14 13

  
15
  my $query = <<SQL;
16
SELECT * FROM parts WHERE onhand <= rop AND rop != 0 AND id NOT IN( SELECT parts_id FROM purchase_basket) AND NOT obsolete
17
SQL
14
  my $parts = $self->_get_parts;
18 15

  
19
  my $parts = SL::DB::Manager::Part->get_objects_from_sql( sql => $query );
20 16
  $self->_setup_list_action_bar;
21 17
  $self->render('dispositionsmanager/list_parts', title => t8('Parts short onhand'), PARTS => $parts);
22

  
23

  
24 18
}
25 19

  
26 20
sub action_add_to_purchase_basket{
......
30 24
  foreach my $id (@{ $parts_to_add }) {
31 25
    my $part = SL::DB::Manager::Part->get_first( query => [ id => $id ] );
32 26
    my $basket_part = SL::DB::PurchaseBasket->new(
33
                              parts_id    => $part->id,
34
                              qty         => $part->min_order_qty,
35
                              description => $part->description,
36
                            );
27
      parts_id    => $part->id,
28
      qty         => $part->min_order_qty,
29
      description => $part->description,
30
    );
37 31
   $basket_part->save;
38 32
 }
39 33
 $self->action_show_basket;
......
46 40
  $::request->{layout}->add_javascripts('kivi.DispositionsManager.js');
47 41
  my $basket = SL::DB::Manager::PurchaseBasket->get_all( query => [ cleared => 'F' ],  with_objects => [ 'parts', 'parts.makemodels' ]);
48 42
  $self->_setup_show_basket_action_bar;
49
  $self->render('dispositionsmanager/show_purchase_basket', PARTS => $basket, title => "Purchasebasket" );
43
  $self->render('dispositionsmanager/show_purchase_basket', PARTS => $basket, title => "Purchase basket" );
50 44
}
51 45

  
52 46
sub action_transfer_to_purchase_order {
......
118 112

  
119 113
}
120 114

  
115
sub _get_parts {
116
  my ($self) = @_;
117

  
118
  my $query = <<SQL;
119
SELECT *
120
  FROM parts
121
 WHERE onhand <= rop
122
   AND rop != 0
123
   AND id NOT IN( SELECT parts_id FROM purchase_basket ) AND NOT obsolete
124
SQL
125

  
126
  return SL::DB::Manager::Part->get_objects_from_sql( sql => $query );
127
};
128

  
129

  
121 130
sub _setup_list_action_bar {
122 131
  my ($self) = @_;
123 132
  for my $bar ($::request->layout->get('actionbar')) {
......
155 164

  
156 165
=head1 NAME
157 166

  
158
SL::Controller::DispositionsManager Controller to manage purchaseorders for parts
167
SL::Controller::DispositionsManager Controller to manage purchase orders for parts
159 168

  
160 169
=head1 DESCRIPTION
161 170

  
162
This Controller shows a list of parts using the filter minimum stock (rop).
171
This controller shows a list of parts using the filter minimum stock (rop).
163 172
From this list it is possible to put parts in a purchase basket to order.
164 173
It's also possible to put parts from the parts edit form in the purchase basket.
165 174

  
166
From the purchase basket you can create a purchaseorder by using the filter vendor.
175
From the purchase basket you can create a purchase order by using the filter vendor.
167 176
The quantity to order will be prefilled by the value min_qty_to_order from parts or
168
makemodel(vendor_parts) or default qty 1.
177
makemodel(vendor_parts) or default to qty 1.
169 178

  
170 179
Tables:
171 180

  
......
175 184

  
176 185
=back
177 186

  
178
Depencies:
187
Dependencies:
179 188

  
180 189
=over 2
181 190

  
......
200 209

  
201 210
=item C<action_show_basket>
202 211

  
203
Shows a list with parts wich are in the basket.
204
This List can be filtered by vendor. Then you can create a purchaseorder.
212
Shows a list with parts which are in the basket.
213
This list can be filtered by vendor. Then you can create a purchase order.
205 214

  
206 215
=item C<action_transfer_to_purchase_order>
207 216

  
208 217
Transfers the marked and by vendor filtered parts to a purchase order.
209
Deletes the entry in the purchasebasket.
218
Deletes the entry in the purchase basket.
210 219

  
211 220
=back
212 221

  
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;
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::PurchaseBasket;
11
use SL::Controller::DispositionsManager;
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

  
22
clear_up();
23

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

  
27
my $part1 = new_part(
28
  partnumber   => 'Testpart 1 rop no stock',
29
  rop          => 20,
30
  warehouse_id => $wh->id,
31
  bin_id       => $bin->id,
32
  makemodels   => [ _create_makemodel_for_vendor(vendor => $vendor) ],
33
)->save;
34

  
35
my $part2 = new_part(
36
  partnumber   => 'Testpart 2 rop with stock',
37
  rop          => 60,
38
)->save;
39
set_stock(part => $part2, bin_id => $bin->id, qty => 10);
40

  
41
my $part3 = new_part(
42
  partnumber   => 'Testpart 3 norop',
43
  rop          => 60,
44
)->save;
45
set_stock(part => $part3, bin_id => $bin->id, qty => 80);
46

  
47
my $controller = SL::Controller::DispositionsManager->new();
48
my $parts = $controller->_get_parts;
49

  
50
is(scalar @{$parts}, 2, "found 2 parts that are below rop");
51

  
52
done_testing();
53
# clear_up();
54

  
55
sub clear_up {
56
  my %params = @_;
57
  SL::DB::Manager::Inventory->delete_all(all => 1);
58
  SL::DB::Manager::Order->delete_all(all => 1);
59
  SL::DB::Manager::PurchaseBasket->delete_all(all => 1);
60
  SL::DB::Manager::MakeModel->delete_all(all => 1);
61
  SL::DB::Manager::Part->delete_all(all => 1);
62
  SL::DB::Manager::Vendor->delete_all(all => 1);
63
  SL::DB::Manager::Bin->delete_all(all => 1);
64
  SL::DB::Manager::Warehouse->delete_all(all => 1);
65
};
66

  
67
sub _create_makemodel_for_vendor {
68
  my %params = @_;
69

  
70
  my $vendor = delete $params{vendor};
71
  die "no vendor" unless ref($vendor) eq 'SL::DB::Vendor';
72

  
73
  my $mm = SL::DB::MakeModel->new(make          => $vendor->id,
74
                                  model         => '',
75
                                  min_order_qty => '1',
76
                                  lastcost      => 0,
77
                                  sortorder     => 1,
78
                                 );
79
  $mm->assign_attributes( %params );
80
  return $mm;
81
}
82

  
83
1;
templates/webpages/dispositionsmanager/list_parts.html
22 22
        <td>[% IF part.makemodels.size %][% L.checkbox_tag('id[]', checked = '1',  value=part.id) %][% ELSE %][% 'No Vendor' | $T8 %][% END %]</td>
23 23
        <td>[% HTML.escape(part.partnumber) %] </td>
24 24
        <td>[% HTML.escape(part.description) %]</td>
25
        <td>[% part.onhand_as_number %]        </td>
26
        <td>[% part.rop_as_number %]           </td>
27
        <td>[% part.min_order_qty_as_number %] </td>
25
        <td class="numeric">[% part.onhand_as_number %]</td>
26
        <td class="numeric">[% part.rop_as_number %]           </td>
27
        <td class="numeric">[% part.min_order_qty_as_number %] </td>
28 28
      </tr>
29 29
      [% END %]
30 30
    [% END %]

Auch abrufbar als: Unified diff