Lines 22-27
use Modern::Perl;
Link Here
|
22 |
use DateTime; |
22 |
use DateTime; |
23 |
use DateTime::Duration; |
23 |
use DateTime::Duration; |
24 |
use Koha::Database; |
24 |
use Koha::Database; |
|
|
25 |
use Koha::DateUtils; |
25 |
use Koha::Item::Transfer; |
26 |
use Koha::Item::Transfer; |
26 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
27 |
use Test::Warn; |
28 |
use Test::Warn; |
Lines 196-202
subtest "Tests for needs_advancing." => sub {
Link Here
|
196 |
'itemnumber' => $dbitem->itemnumber_id, |
197 |
'itemnumber' => $dbitem->itemnumber_id, |
197 |
'frombranch' => $dbitem->stage->branchcode_id, |
198 |
'frombranch' => $dbitem->stage->branchcode_id, |
198 |
'tobranch' => $dbitem->stage->branchcode_id, |
199 |
'tobranch' => $dbitem->stage->branchcode_id, |
199 |
'datesent' => DateTime->now, |
200 |
'datesent' => dt_from_string(), |
200 |
'datearrived' => undef, |
201 |
'datearrived' => undef, |
201 |
'reason' => "StockrotationAdvance", |
202 |
'reason' => "StockrotationAdvance", |
202 |
})->store; |
203 |
})->store; |
Lines 209-215
subtest "Tests for needs_advancing." => sub {
Link Here
|
209 |
$dbitem->fresh(0)->store; |
210 |
$dbitem->fresh(0)->store; |
210 |
|
211 |
|
211 |
# Test item will not be advanced if it has not spent enough time. |
212 |
# Test item will not be advanced if it has not spent enough time. |
212 |
$dbtransfer->datearrived(DateTime->now)->store; |
213 |
$dbtransfer->datearrived(dt_from_string())->store; |
213 |
is($dbitem->needs_advancing, 0, "Not ready to advance: Not spent enough time."); |
214 |
is($dbitem->needs_advancing, 0, "Not ready to advance: Not spent enough time."); |
214 |
# Test item will be advanced if it has not spent enough time, but is fresh. |
215 |
# Test item will be advanced if it has not spent enough time, but is fresh. |
215 |
$dbitem->fresh(1)->store; |
216 |
$dbitem->fresh(1)->store; |
Lines 218-227
subtest "Tests for needs_advancing." => sub {
Link Here
|
218 |
|
219 |
|
219 |
# Test item will be advanced if it has spent enough time. |
220 |
# Test item will be advanced if it has spent enough time. |
220 |
$dbtransfer->datesent( # Item was sent 100 days ago... |
221 |
$dbtransfer->datesent( # Item was sent 100 days ago... |
221 |
DateTime->now - DateTime::Duration->new( days => 100 ) |
222 |
dt_from_string() - DateTime::Duration->new( days => 100 ) |
222 |
)->store; |
223 |
)->store; |
223 |
$dbtransfer->datearrived( # And arrived 75 days ago. |
224 |
$dbtransfer->datearrived( # And arrived 75 days ago. |
224 |
DateTime->now - DateTime::Duration->new( days => 75 ) |
225 |
dt_from_string() - DateTime::Duration->new( days => 75 ) |
225 |
)->store; |
226 |
)->store; |
226 |
is($dbitem->needs_advancing, 1, "Ready to be advanced."); |
227 |
is($dbitem->needs_advancing, 1, "Ready to be advanced."); |
227 |
$dbtransfer->delete; |
228 |
$dbtransfer->delete; |
Lines 231-237
subtest "Tests for needs_advancing." => sub {
Link Here
|
231 |
}; |
232 |
}; |
232 |
|
233 |
|
233 |
subtest "Tests for advance." => sub { |
234 |
subtest "Tests for advance." => sub { |
234 |
plan tests => 15; |
235 |
plan tests => 23; |
235 |
$schema->storage->txn_begin; |
236 |
$schema->storage->txn_begin; |
236 |
|
237 |
|
237 |
my $sritem = $builder->build( |
238 |
my $sritem = $builder->build( |
Lines 289-310
subtest "Tests for advance." => sub {
Link Here
|
289 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
290 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
290 |
## Test results |
291 |
## Test results |
291 |
is($dbitem->stage->stage_id, $dbstage2->stage_id, "Stage updated."); |
292 |
is($dbitem->stage->stage_id, $dbstage2->stage_id, "Stage updated."); |
|
|
293 |
is( |
294 |
$dbitem->itemnumber->homebranch, |
295 |
$dbstage2->branchcode_id, |
296 |
"Item homebranch updated" |
297 |
); |
292 |
my $intransfer = $dbitem->itemnumber->get_transfer; |
298 |
my $intransfer = $dbitem->itemnumber->get_transfer; |
293 |
is($intransfer->frombranch, $dbstage->branchcode_id, "Origin correct."); |
299 |
is($intransfer->frombranch, $dbstage->branchcode_id, "Origin correct."); |
294 |
is($intransfer->tobranch, $dbstage2->branchcode_id, "Target Correct."); |
300 |
is($intransfer->tobranch, $dbstage2->branchcode_id, "Target Correct."); |
295 |
|
301 |
|
|
|
302 |
# Arrive at new branch |
303 |
$intransfer->datearrived(dt_from_string())->store; |
304 |
$dbitem->itemnumber->holdingbranch($srstage->{branchcode_id})->store; |
305 |
|
306 |
# Test a cyclical advance |
307 |
ok($dbitem->advance, "Cyclical advancement done."); |
308 |
## Refetch dbitem |
309 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
310 |
## Test results |
311 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage updated."); |
312 |
is( |
313 |
$dbitem->itemnumber->homebranch, |
314 |
$dbstage->branchcode_id, |
315 |
"Item homebranch updated" |
316 |
); |
317 |
$intransfer = $dbitem->itemnumber->get_transfer; |
318 |
is($intransfer->frombranch, $dbstage2->branchcode_id, "Origin correct."); |
319 |
is($intransfer->tobranch, $dbstage->branchcode_id, "Target correct."); |
320 |
|
321 |
# Arrive at new branch |
322 |
$intransfer->datearrived(dt_from_string())->store; |
323 |
$dbitem->itemnumber->holdingbranch($srstage->{branchcode_id})->store; |
324 |
|
296 |
$dbstage->rota->cyclical(0)->store; # Set Rota to non-cyclical. |
325 |
$dbstage->rota->cyclical(0)->store; # Set Rota to non-cyclical. |
297 |
|
326 |
|
|
|
327 |
# Advance again, to end of rota. |
328 |
ok($dbitem->advance, "Non-cyclical advance to last stage."); |
329 |
|
298 |
# Arrive at new branch |
330 |
# Arrive at new branch |
299 |
$intransfer->datearrived(DateTime->now)->store; |
331 |
$intransfer->datearrived(dt_from_string())->store; |
300 |
$dbitem->itemnumber->holdingbranch($srstage->{branchcode_id})->store; |
332 |
$dbitem->itemnumber->holdingbranch($srstage->{branchcode_id})->store; |
301 |
$dbitem->itemnumber->homebranch($srstage->{branchcode_id})->store; |
|
|
302 |
|
333 |
|
303 |
# Advance again, Remove from rota. |
334 |
# Advance again, Remove from rota. |
304 |
ok($dbitem->advance, "Non-cyclical advance."); |
335 |
ok($dbitem->advance, "Non-cyclical advance."); |
305 |
## Refetch dbitem |
336 |
## Refetch dbitem |
306 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
337 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
307 |
is($dbitem, undef, "StockRotationItem has been removed."); |
338 |
is($dbitem, undef, "StockRotationItem has been removed."); |
|
|
339 |
my $item = Koha::Items->find($sritem->{itemnumber_id}); |
340 |
is($item->homebranch, $srstage->{branchcode_id}, "Item homebranch remains"); |
308 |
|
341 |
|
309 |
$schema->storage->txn_rollback; |
342 |
$schema->storage->txn_rollback; |
310 |
}; |
343 |
}; |
Lines 356-363
subtest "Tests for investigate (singular)." => sub {
Link Here
|
356 |
'itemnumber' => $dbitem->itemnumber_id, |
389 |
'itemnumber' => $dbitem->itemnumber_id, |
357 |
'frombranch' => $dbitem->itemnumber->homebranch, |
390 |
'frombranch' => $dbitem->itemnumber->homebranch, |
358 |
'tobranch' => $dbitem->itemnumber->homebranch, |
391 |
'tobranch' => $dbitem->itemnumber->homebranch, |
359 |
'datesent' => DateTime->now, |
392 |
'datesent' => dt_from_string(), |
360 |
'datearrived' => DateTime->now, |
393 |
'datearrived' => dt_from_string(), |
361 |
'reason' => "StockrotationAdvance", |
394 |
'reason' => "StockrotationAdvance", |
362 |
})->store; |
395 |
})->store; |
363 |
is($dbitem->investigate->{reason}, 'repatriation', "older item repatriates."); |
396 |
is($dbitem->investigate->{reason}, 'repatriation', "older item repatriates."); |
Lines 377-384
subtest "Tests for investigate (singular)." => sub {
Link Here
|
377 |
'itemnumber' => $dbitem->itemnumber_id, |
410 |
'itemnumber' => $dbitem->itemnumber_id, |
378 |
'frombranch' => $dbitem->itemnumber->homebranch, |
411 |
'frombranch' => $dbitem->itemnumber->homebranch, |
379 |
'tobranch' => $dbitem->stage->branchcode_id, |
412 |
'tobranch' => $dbitem->stage->branchcode_id, |
380 |
'datesent' => DateTime->now, |
413 |
'datesent' => dt_from_string(), |
381 |
'datearrived' => DateTime->now, |
414 |
'datearrived' => dt_from_string(), |
382 |
'reason' => "StockrotationAdvance", |
415 |
'reason' => "StockrotationAdvance", |
383 |
})->store; |
416 |
})->store; |
384 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
417 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
Lines 404-411
subtest "Tests for investigate (singular)." => sub {
Link Here
|
404 |
'itemnumber' => $dbitem->itemnumber_id, |
437 |
'itemnumber' => $dbitem->itemnumber_id, |
405 |
'frombranch' => $dbitem->itemnumber->homebranch, |
438 |
'frombranch' => $dbitem->itemnumber->homebranch, |
406 |
'tobranch' => $dbitem->stage->branchcode_id, |
439 |
'tobranch' => $dbitem->stage->branchcode_id, |
407 |
'datesent' => DateTime->now - $sent_duration, |
440 |
'datesent' => dt_from_string() - $sent_duration, |
408 |
'datearrived' => DateTime->now - $arrived_duration, |
441 |
'datearrived' => dt_from_string() - $arrived_duration, |
409 |
'reason' => "StockrotationAdvance", |
442 |
'reason' => "StockrotationAdvance", |
410 |
})->store; |
443 |
})->store; |
411 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
444 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
Lines 432-439
subtest "Tests for investigate (singular)." => sub {
Link Here
|
432 |
'itemnumber' => $dbitem->itemnumber_id, |
465 |
'itemnumber' => $dbitem->itemnumber_id, |
433 |
'frombranch' => $dbitem->itemnumber->homebranch, |
466 |
'frombranch' => $dbitem->itemnumber->homebranch, |
434 |
'tobranch' => $dbitem->stage->branchcode_id, |
467 |
'tobranch' => $dbitem->stage->branchcode_id, |
435 |
'datesent' => DateTime->now - $sent_duration, |
468 |
'datesent' => dt_from_string() - $sent_duration, |
436 |
'datearrived' => DateTime->now - $arrived_duration, |
469 |
'datearrived' => dt_from_string() - $arrived_duration, |
437 |
'reason' => "StockrotationAdvance", |
470 |
'reason' => "StockrotationAdvance", |
438 |
})->store; |
471 |
})->store; |
439 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
472 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
Lines 460-467
subtest "Tests for investigate (singular)." => sub {
Link Here
|
460 |
'itemnumber' => $dbitem->itemnumber_id, |
493 |
'itemnumber' => $dbitem->itemnumber_id, |
461 |
'frombranch' => $dbitem->itemnumber->homebranch, |
494 |
'frombranch' => $dbitem->itemnumber->homebranch, |
462 |
'tobranch' => $dbitem->stage->branchcode_id, |
495 |
'tobranch' => $dbitem->stage->branchcode_id, |
463 |
'datesent' => DateTime->now - $sent_duration, |
496 |
'datesent' => dt_from_string() - $sent_duration, |
464 |
'datearrived' => DateTime->now - $arrived_duration, |
497 |
'datearrived' => dt_from_string() - $arrived_duration, |
465 |
'reason' => "StockrotationAdvance", |
498 |
'reason' => "StockrotationAdvance", |
466 |
})->store; |
499 |
})->store; |
467 |
is($dbitem->investigate->{reason}, 'repatriation', |
500 |
is($dbitem->investigate->{reason}, 'repatriation', |
468 |
- |
|
|