Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0b68d45d

Von Jan Büren vor etwa 3 Jahren hinzugefügt

  • ID 0b68d45da337a155d69fe2417a3c27a1689c5642
  • Vorgänger 0af9f88c
  • Nachfolger 0929128e

CSV-Import Inventory mehr Testfälle (target_qty und Kommentare)

Unterschiede anzeigen:

t/controllers/csvimport/inventory.t
29 29
  clear_up();
30 30
  create_standard_stock();
31 31

  
32

  
33

  
34 32
}
35 33
reset_state();
36 34

  
......
129 127
is(SL::Helper::Inventory::get_stock(part => $part1), "25.00000", 'simple get_stock works');
130 128
is(SL::Helper::Inventory::get_onhand(part => $part1), "25.00000", 'simple get_onhand works');
131 129

  
130
my ($trans_id, $inv_obj, $tt);
131
# add some stuff
132

  
132 133
$file = \<<EOL;
133 134
warehouse,bin,partnumber,qty,chargenumber,comment,employee_id,shippingdate
134 135
Warehouse,"Bin 1","ap 1",3.4
135 136
EOL
136 137
$entries = test_import($file, $settings1);
137 138
$entry = $entries->[0];
138
diag Dumper($entry->{object}->trans_id);
139 139
is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred";
140 140
is $entry->{object}->qty, "3.4", "Valid qty accepted";  # evals to text
141 141
is(SL::Helper::Inventory::get_stock(part => $part1),  "28.40000",  'simple add (stock) qty works');
142 142
is(SL::Helper::Inventory::get_onhand(part => $part1), "28.40000", 'simple add (onhand) qty works');
143 143

  
144 144
# now check the real Inventory entry
145
my $trans_id = $entry->{object}->trans_id;
146
my $inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id);
145
$trans_id = $entry->{object}->trans_id;
146
$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id);
147 147

  
148 148
# we expect one entry for one trans_id
149 149
is ref $inv_obj, "SL::DB::Inventory",             "One inventory object, no array or undef";
......
153 153
is ref $inv_obj->shippingdate, 'DateTime',        "Valid DateTime for shippingdate";
154 154
is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set";
155 155

  
156
my $tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id);
156
$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id);
157 157

  
158 158
is ref $tt, 'SL::DB::TransferType',       "Valid TransferType, no undef";
159 159
is $tt->direction, 'in',                  "Transfer direction correct";
160 160
is $tt->description, 'correction',        "Transfer description correct";
161 161

  
162
# remove some stuff
163

  
164
$file = \<<EOL;
165
warehouse,bin,partnumber,qty,chargenumber,comment,employee_id,shippingdate
166
Warehouse,"Bin 1","ap 1",-13.4
167
EOL
168
$entries = test_import($file, $settings1);
169
$entry = $entries->[0];
170
is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred";
171
is $entry->{object}->qty, "-13.4", "Valid qty accepted";  # evals to text
172
is(SL::Helper::Inventory::get_stock(part => $part1),  "15.00000",  'simple add (stock) qty works');
173
is(SL::Helper::Inventory::get_onhand(part => $part1), "15.00000", 'simple add (onhand) qty works');
174

  
175
# now check the real Inventory entry
176
$trans_id = $entry->{object}->trans_id;
177
$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id);
178

  
179
# we expect one entry for one trans_id
180
is ref $inv_obj, "SL::DB::Inventory",             "One inventory object, no array or undef";
181
is $inv_obj->qty == -13.4, 1,                       "Valid qty accepted";  # evals to text
182
is $inv_obj->comment, 'Lager Inventur Standard',  "Valid comment accepted";  # evals to text
183
is $inv_obj->employee_id, 1,                      "Employee valid";  # evals to text
184
is ref $inv_obj->shippingdate, 'DateTime',        "Valid DateTime for shippingdate";
185
is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set";
186

  
187
$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id);
188

  
189
is ref $tt, 'SL::DB::TransferType',       "Valid TransferType, no undef";
190
is $tt->direction, 'out',                  "Transfer direction correct";
191
is $tt->description, 'correction',        "Transfer description correct";
192

  
193
# repeat both test cases but with target qty instead of qty (should throw an error for neg. case)
194
# and customise comment
195
# add some stuff
196

  
197
$file = \<<EOL;
198
warehouse,bin,partnumber,target_qty,comment
199
Warehouse,"Bin 1","ap 1",3.4,"Alter, wir haben uns voll verhauen bei der aktuellen Zielmenge!"
200
EOL
201
$entries = test_import($file, $settings1);
202
$entry = $entries->[0];
203
is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred";
204
is $entry->{object}->qty, "-11.6", "Valid qty accepted";  # evals to text qty = target_qty - actual_qty
205
is(SL::Helper::Inventory::get_stock(part => $part1),  "3.40000",  'simple add (stock) qty works');
206
is(SL::Helper::Inventory::get_onhand(part => $part1), "3.40000", 'simple add (onhand) qty works');
207

  
208
# now check the real Inventory entry
209
$trans_id = $entry->{object}->trans_id;
210
$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id);
211

  
212
# we expect one entry for one trans_id
213
is ref $inv_obj, "SL::DB::Inventory",             "One inventory object, no array or undef";
214
is $inv_obj->qty == -11.6, 1,                       "Valid qty accepted";
215
is $inv_obj->comment,
216
  "Alter, wir haben uns voll verhauen bei der aktuellen Zielmenge!",  "Valid comment accepted";
217
is $inv_obj->employee_id, 1,                      "Employee valid";
218
is ref $inv_obj->shippingdate, 'DateTime',        "Valid DateTime for shippingdate";
219
is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set";
220

  
221
$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id);
222

  
223
is ref $tt, 'SL::DB::TransferType',       "Valid TransferType, no undef";
224
is $tt->direction, 'out',                  "Transfer direction correct";
225
is $tt->description, 'correction',        "Transfer description correct";
226

  
227
# remove some stuff, but too much
228

  
229
$file = \<<EOL;
230
warehouse,bin,partnumber,target_qty,comment
231
Warehouse,"Bin 1","ap 1",-13.4,"Jetzt stimmt aber alles"
232
EOL
233
$entries = test_import($file, $settings1);
234
$entry = $entries->[0];
235
is scalar @{ $entry->{errors} }, 1, "One error for invalid data occurred";
236
is $entry->{object}->qty, undef, "No data accepted";  # evals to text
237
is(SL::Helper::Inventory::get_stock(part => $part1),  "3.40000",  'simple add (stock) qty works');
238
is(SL::Helper::Inventory::get_onhand(part => $part1), "3.40000", 'simple add (onhand) qty works');
239

  
240
# now check the real Inventory entry
241
$trans_id = $entry->{object}->trans_id;
242
$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id);
243

  
244
is ref $trans_id, '',         "No trans_id -> undef";
245
is ref $inv_obj,  '',         "No inventory object -> undef";
246

  
247
# add some stuff, but realistic value
248

  
249
$file = \<<EOL;
250
warehouse,bin,partnumber,target_qty,comment
251
Warehouse,"Bin 1","ap 1",33.75,"Jetzt wirklich"
252
EOL
253
$entries = test_import($file, $settings1);
254
$entry = $entries->[0];
255
is scalar @{ $entry->{errors} }, 0, "No error for valid data occurred";
256
is $entry->{object}->qty, "30.35", "Valid qty accepted";  # evals to text qty = target_qty - actual_qty
257
is(SL::Helper::Inventory::get_stock(part => $part1),  "33.75000",  'simple add (stock) qty works');
258
is(SL::Helper::Inventory::get_onhand(part => $part1), "33.75000", 'simple add (onhand) qty works');
259

  
260
# now check the real Inventory entry
261
$trans_id = $entry->{object}->trans_id;
262
$inv_obj = SL::DB::Manager::Inventory->find_by(trans_id => $trans_id);
263

  
264
# we expect one entry for one trans_id
265
is ref $inv_obj, "SL::DB::Inventory",             "One inventory object, no array or undef";
266
is $inv_obj->qty == 30.35, 1,                       "Valid qty accepted";
267
is $inv_obj->comment,
268
  "Jetzt wirklich",  "Valid comment accepted";
269
is $inv_obj->employee_id, 1,                      "Employee valid";
270
is ref $inv_obj->shippingdate, 'DateTime',        "Valid DateTime for shippingdate";
271
is $inv_obj->shippingdate, DateTime->today_local, "Default shippingdate set";
272

  
273
$tt = SL::DB::Manager::TransferType->find_by(id => $inv_obj->trans_type_id);
274

  
275
is ref $tt, 'SL::DB::TransferType',       "Valid TransferType, no undef";
276
is $tt->direction, 'in',                  "Transfer direction correct";
277
is $tt->description, 'correction',        "Transfer description correct";
278

  
279

  
162 280
clear_up(); # remove all data at end of tests
163 281

  
164 282
# end of tests
......
210 328

  
211 329

  
212 330
1;
213

  
214
#####
215
# vim: ft=perl
216
# set emacs to perl mode
217
# Local Variables:
218
# mode: perl
219
# End:

Auch abrufbar als: Unified diff