Lines 63-70
subtest 'Basic object tests' => sub {
Link Here
|
63 |
); |
63 |
); |
64 |
|
64 |
|
65 |
# Relationship to rota |
65 |
# Relationship to rota |
66 |
isa_ok( $sritem->itemnumber, 'Koha::Item', "Fetched related item." ); |
66 |
isa_ok( $sritem->item, 'Koha::Item', "Fetched related item." ); |
67 |
is( $sritem->itemnumber->itemnumber, $itm->itemnumber, "Related rota OK." ); |
67 |
is( $sritem->item->itemnumber, $itm->itemnumber, "Related rota OK." ); |
68 |
|
68 |
|
69 |
# Relationship to stage |
69 |
# Relationship to stage |
70 |
isa_ok( $sritem->stage, 'Koha::StockRotationStage', "Fetched related stage." ); |
70 |
isa_ok( $sritem->stage, 'Koha::StockRotationStage', "Fetched related stage." ); |
Lines 89-96
subtest 'Tests for needs_repatriating' => sub {
Link Here
|
89 |
} |
89 |
} |
90 |
); |
90 |
); |
91 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
91 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
92 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id); |
92 |
$dbitem->item->homebranch($dbitem->stage->branchcode_id); |
93 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id); |
93 |
$dbitem->item->holdingbranch($dbitem->stage->branchcode_id); |
94 |
$dbitem->stage->position(1); |
94 |
$dbitem->stage->position(1); |
95 |
|
95 |
|
96 |
my $dbrota = $dbitem->stage->rota; |
96 |
my $dbrota = $dbitem->stage->rota; |
Lines 109-115
subtest 'Tests for needs_repatriating' => sub {
Link Here
|
109 |
); |
109 |
); |
110 |
|
110 |
|
111 |
my $branch = $builder->build({ source => 'Branch' }); |
111 |
my $branch = $builder->build({ source => 'Branch' }); |
112 |
$dbitem->itemnumber->holdingbranch($branch->{branchcode}); |
112 |
$dbitem->item->holdingbranch($branch->{branchcode}); |
113 |
|
113 |
|
114 |
# - homebranch != holdingbranch [1] |
114 |
# - homebranch != holdingbranch [1] |
115 |
is( |
115 |
is( |
Lines 118-125
subtest 'Tests for needs_repatriating' => sub {
Link Here
|
118 |
); |
118 |
); |
119 |
|
119 |
|
120 |
# Set to incorrect homebranch. |
120 |
# Set to incorrect homebranch. |
121 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id); |
121 |
$dbitem->item->holdingbranch($dbitem->stage->branchcode_id); |
122 |
$dbitem->itemnumber->homebranch($branch->{branchcode}); |
122 |
$dbitem->item->homebranch($branch->{branchcode}); |
123 |
# - homebranch != stockrotationstage.branch & not in transit [1] |
123 |
# - homebranch != stockrotationstage.branch & not in transit [1] |
124 |
is( |
124 |
is( |
125 |
$dbitem->needs_repatriating, 1, |
125 |
$dbitem->needs_repatriating, 1, |
Lines 149-171
subtest "Tests for repatriate." => sub {
Link Here
|
149 |
} |
149 |
} |
150 |
} |
150 |
} |
151 |
); |
151 |
); |
152 |
my $item_id = $sritem_1->itemnumber->itemnumber; |
152 |
my $item_id = $sritem_1->item->itemnumber; |
153 |
my $srstage_1 = $sritem_1->stage; |
153 |
my $srstage_1 = $sritem_1->stage; |
154 |
$sritem_1->discard_changes; |
154 |
$sritem_1->discard_changes; |
155 |
$sritem_1->stage->position(1); |
155 |
$sritem_1->stage->position(1); |
156 |
$sritem_1->stage->duration(50); |
156 |
$sritem_1->stage->duration(50); |
157 |
my $branch = $builder->build({ source => 'Branch' }); |
157 |
my $branch = $builder->build({ source => 'Branch' }); |
158 |
$sritem_1->itemnumber->holdingbranch($branch->{branchcode}); |
158 |
$sritem_1->item->holdingbranch($branch->{branchcode}); |
159 |
|
159 |
|
160 |
# Test a straight up repatriate |
160 |
# Test a straight up repatriate |
161 |
ok($sritem_1->repatriate, "Repatriation done."); |
161 |
ok($sritem_1->repatriate, "Repatriation done."); |
162 |
my $intransfer = $sritem_1->itemnumber->get_transfer; |
162 |
my $intransfer = $sritem_1->item->get_transfer; |
163 |
is($intransfer->frombranch, $branch->{branchcode}, "Origin correct."); |
163 |
is($intransfer->frombranch, $branch->{branchcode}, "Origin correct."); |
164 |
is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct."); |
164 |
is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct."); |
165 |
|
165 |
|
166 |
# Reset |
166 |
# Reset |
167 |
$intransfer->datearrived(dt_from_string())->store; |
167 |
$intransfer->datearrived(dt_from_string())->store; |
168 |
$sritem_1->itemnumber->holdingbranch($branch->{branchcode}); |
168 |
$sritem_1->item->holdingbranch($branch->{branchcode}); |
169 |
|
169 |
|
170 |
# Setup a conflicting manual transfer |
170 |
# Setup a conflicting manual transfer |
171 |
my $item = Koha::Items->find($item_id); |
171 |
my $item = Koha::Items->find($item_id); |
Lines 179-185
subtest "Tests for repatriate." => sub {
Link Here
|
179 |
|
179 |
|
180 |
# Reset |
180 |
# Reset |
181 |
$intransfer->datearrived(dt_from_string())->store; |
181 |
$intransfer->datearrived(dt_from_string())->store; |
182 |
$sritem_1->itemnumber->holdingbranch($branch->{branchcode}); |
182 |
$sritem_1->item->holdingbranch($branch->{branchcode}); |
183 |
|
183 |
|
184 |
# Confirm that stockrotation ignores transfer limits |
184 |
# Confirm that stockrotation ignores transfer limits |
185 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
185 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
Lines 188-200
subtest "Tests for repatriate." => sub {
Link Here
|
188 |
{ |
188 |
{ |
189 |
fromBranch => $branch->{branchcode}, |
189 |
fromBranch => $branch->{branchcode}, |
190 |
toBranch => $srstage_1->branchcode_id, |
190 |
toBranch => $srstage_1->branchcode_id, |
191 |
itemtype => $sritem_1->itemnumber->effective_itemtype, |
191 |
itemtype => $sritem_1->item->effective_itemtype, |
192 |
} |
192 |
} |
193 |
)->store; |
193 |
)->store; |
194 |
|
194 |
|
195 |
# Stockrotation should overrule transfer limits |
195 |
# Stockrotation should overrule transfer limits |
196 |
ok($sritem_1->repatriate, "Repatriation done regardless of transfer limits."); |
196 |
ok($sritem_1->repatriate, "Repatriation done regardless of transfer limits."); |
197 |
$intransfer = $sritem_1->itemnumber->get_transfer; |
197 |
$intransfer = $sritem_1->item->get_transfer; |
198 |
is($intransfer->frombranch, $branch->{branchcode}, "Origin correct."); |
198 |
is($intransfer->frombranch, $branch->{branchcode}, "Origin correct."); |
199 |
is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct."); |
199 |
is($intransfer->tobranch, $sritem_1->stage->branchcode_id, "Target Correct."); |
200 |
|
200 |
|
Lines 229-236
subtest "Tests for needs_advancing." => sub {
Link Here
|
229 |
} |
229 |
} |
230 |
); |
230 |
); |
231 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
231 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
232 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id); |
232 |
$dbitem->item->homebranch($dbitem->stage->branchcode_id); |
233 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id); |
233 |
$dbitem->item->holdingbranch($dbitem->stage->branchcode_id); |
234 |
$dbitem->stage->position(1); |
234 |
$dbitem->stage->position(1); |
235 |
$dbitem->stage->duration(50); |
235 |
$dbitem->stage->duration(50); |
236 |
|
236 |
|
Lines 267-273
subtest "Tests for needs_advancing." => sub {
Link Here
|
267 |
)->store; |
267 |
)->store; |
268 |
is($dbitem->needs_advancing, 1, "Ready to be advanced."); |
268 |
is($dbitem->needs_advancing, 1, "Ready to be advanced."); |
269 |
$dbtransfer->delete; |
269 |
$dbtransfer->delete; |
270 |
warning_is {$dbitem->needs_advancing} "We have no historical branch transfer for itemnumber " . $dbitem->itemnumber->itemnumber . "; This should not have happened!", "Missing transfer is warned."; |
270 |
warning_is {$dbitem->needs_advancing} "We have no historical branch transfer for itemnumber " . $dbitem->item->itemnumber . "; This should not have happened!", "Missing transfer is warned."; |
271 |
|
271 |
|
272 |
$schema->storage->txn_rollback; |
272 |
$schema->storage->txn_rollback; |
273 |
}; |
273 |
}; |
Lines 286-298
subtest "Tests for advance." => sub {
Link Here
|
286 |
} |
286 |
} |
287 |
); |
287 |
); |
288 |
$sritem_1->discard_changes; |
288 |
$sritem_1->discard_changes; |
289 |
$sritem_1->itemnumber->holdingbranch($sritem_1->stage->branchcode_id); |
289 |
$sritem_1->item->holdingbranch($sritem_1->stage->branchcode_id); |
290 |
my $item_id = $sritem_1->itemnumber->itemnumber; |
290 |
my $item_id = $sritem_1->item->itemnumber; |
291 |
my $srstage_1 = $sritem_1->stage; |
291 |
my $srstage_1 = $sritem_1->stage; |
292 |
$srstage_1->position(1)->duration(50)->store; # Configure stage. |
292 |
$srstage_1->position(1)->duration(50)->store; # Configure stage. |
293 |
# Configure item |
293 |
# Configure item |
294 |
$sritem_1->itemnumber->holdingbranch($srstage_1->branchcode_id)->store; |
294 |
$sritem_1->item->holdingbranch($srstage_1->branchcode_id)->store; |
295 |
$sritem_1->itemnumber->homebranch($srstage_1->branchcode_id)->store; |
295 |
$sritem_1->item->homebranch($srstage_1->branchcode_id)->store; |
296 |
# Sanity check |
296 |
# Sanity check |
297 |
is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage sanity check."); |
297 |
is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage sanity check."); |
298 |
|
298 |
|
Lines 333-350
subtest "Tests for advance." => sub {
Link Here
|
333 |
## Test results |
333 |
## Test results |
334 |
is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated."); |
334 |
is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated."); |
335 |
is( |
335 |
is( |
336 |
$sritem_1->itemnumber->homebranch, |
336 |
$sritem_1->item->homebranch, |
337 |
$srstage_2->branchcode_id, |
337 |
$srstage_2->branchcode_id, |
338 |
"Item homebranch updated" |
338 |
"Item homebranch updated" |
339 |
); |
339 |
); |
340 |
my $transfer_request = $sritem_1->itemnumber->get_transfer; |
340 |
my $transfer_request = $sritem_1->item->get_transfer; |
341 |
is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct."); |
341 |
is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct."); |
342 |
is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target Correct."); |
342 |
is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target Correct."); |
343 |
is($transfer_request->datesent, undef, "Transfer requested, but not sent."); |
343 |
is($transfer_request->datesent, undef, "Transfer requested, but not sent."); |
344 |
|
344 |
|
345 |
# Arrive at new branch |
345 |
# Arrive at new branch |
346 |
$transfer_request->datearrived(dt_from_string())->store; |
346 |
$transfer_request->datearrived(dt_from_string())->store; |
347 |
$sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store; |
347 |
$sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store; |
348 |
|
348 |
|
349 |
# Test a cyclical advance |
349 |
# Test a cyclical advance |
350 |
ok($sritem_1->advance, "Cyclical advancement done."); |
350 |
ok($sritem_1->advance, "Cyclical advancement done."); |
Lines 353-369
subtest "Tests for advance." => sub {
Link Here
|
353 |
## Test results |
353 |
## Test results |
354 |
is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage updated."); |
354 |
is($sritem_1->stage->stage_id, $srstage_1->stage_id, "Stage updated."); |
355 |
is( |
355 |
is( |
356 |
$sritem_1->itemnumber->homebranch, |
356 |
$sritem_1->item->homebranch, |
357 |
$srstage_1->branchcode_id, |
357 |
$srstage_1->branchcode_id, |
358 |
"Item homebranch updated" |
358 |
"Item homebranch updated" |
359 |
); |
359 |
); |
360 |
$transfer_request = $sritem_1->itemnumber->get_transfer; |
360 |
$transfer_request = $sritem_1->item->get_transfer; |
361 |
is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct."); |
361 |
is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct."); |
362 |
is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct."); |
362 |
is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct."); |
363 |
|
363 |
|
364 |
# Arrive at new branch |
364 |
# Arrive at new branch |
365 |
$transfer_request->datearrived(dt_from_string())->store; |
365 |
$transfer_request->datearrived(dt_from_string())->store; |
366 |
$sritem_1->itemnumber->holdingbranch($srstage_1->branchcode_id)->store; |
366 |
$sritem_1->item->holdingbranch($srstage_1->branchcode_id)->store; |
367 |
|
367 |
|
368 |
# Confirm that stockrotation ignores transfer limits |
368 |
# Confirm that stockrotation ignores transfer limits |
369 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
369 |
t::lib::Mocks::mock_preference('UseBranchTransferLimits', 1); |
Lines 372-378
subtest "Tests for advance." => sub {
Link Here
|
372 |
{ |
372 |
{ |
373 |
fromBranch => $srstage_1->branchcode_id, |
373 |
fromBranch => $srstage_1->branchcode_id, |
374 |
toBranch => $srstage_2->branchcode_id, |
374 |
toBranch => $srstage_2->branchcode_id, |
375 |
itemtype => $sritem_1->itemnumber->effective_itemtype, |
375 |
itemtype => $sritem_1->item->effective_itemtype, |
376 |
} |
376 |
} |
377 |
)->store; |
377 |
)->store; |
378 |
|
378 |
|
Lines 382-398
subtest "Tests for advance." => sub {
Link Here
|
382 |
## Test results |
382 |
## Test results |
383 |
is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated ignoring transfer limits."); |
383 |
is($sritem_1->stage->stage_id, $srstage_2->stage_id, "Stage updated ignoring transfer limits."); |
384 |
is( |
384 |
is( |
385 |
$sritem_1->itemnumber->homebranch, |
385 |
$sritem_1->item->homebranch, |
386 |
$srstage_2->branchcode_id, |
386 |
$srstage_2->branchcode_id, |
387 |
"Item homebranch updated ignoring transfer limits" |
387 |
"Item homebranch updated ignoring transfer limits" |
388 |
); |
388 |
); |
389 |
$transfer_request = $sritem_1->itemnumber->get_transfer; |
389 |
$transfer_request = $sritem_1->item->get_transfer; |
390 |
is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct ignoring transfer limits."); |
390 |
is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct ignoring transfer limits."); |
391 |
is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct ignoring transfer limits."); |
391 |
is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct ignoring transfer limits."); |
392 |
|
392 |
|
393 |
# Arrive at new branch |
393 |
# Arrive at new branch |
394 |
$transfer_request->datearrived(dt_from_string())->store; |
394 |
$transfer_request->datearrived(dt_from_string())->store; |
395 |
$sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store; |
395 |
$sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store; |
396 |
|
396 |
|
397 |
# Setup a conflicting manual transfer |
397 |
# Setup a conflicting manual transfer |
398 |
my $item = Koha::Items->find($item_id); |
398 |
my $item = Koha::Items->find($item_id); |
Lines 413-426
subtest "Tests for advance." => sub {
Link Here
|
413 |
isnt($transfer_request->datecancelled, undef, "Conflicting manual transfer was cancelled"); |
413 |
isnt($transfer_request->datecancelled, undef, "Conflicting manual transfer was cancelled"); |
414 |
|
414 |
|
415 |
# StockRotationAdvance transfer added |
415 |
# StockRotationAdvance transfer added |
416 |
$transfer_request = $sritem_1->itemnumber->get_transfer; |
416 |
$transfer_request = $sritem_1->item->get_transfer; |
417 |
is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer added"); |
417 |
is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer added"); |
418 |
is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct."); |
418 |
is($transfer_request->frombranch, $srstage_2->branchcode_id, "Origin correct."); |
419 |
is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct."); |
419 |
is($transfer_request->tobranch, $srstage_1->branchcode_id, "Target correct."); |
420 |
|
420 |
|
421 |
# Arrive at new branch |
421 |
# Arrive at new branch |
422 |
$transfer_request->datearrived(dt_from_string())->store; |
422 |
$transfer_request->datearrived(dt_from_string())->store; |
423 |
$sritem_1->itemnumber->holdingbranch($srstage_1->branchcode_id)->store; |
423 |
$sritem_1->item->holdingbranch($srstage_1->branchcode_id)->store; |
424 |
|
424 |
|
425 |
# Setup a conflicting reserve transfer |
425 |
# Setup a conflicting reserve transfer |
426 |
$item->request_transfer({ to => $srstage_2->branchcode, reason => "Reserve" }); |
426 |
$item->request_transfer({ to => $srstage_2->branchcode, reason => "Reserve" }); |
Lines 442-448
subtest "Tests for advance." => sub {
Link Here
|
442 |
# StockRotationAdvance transfer added |
442 |
# StockRotationAdvance transfer added |
443 |
my $transfer_requests = Koha::Item::Transfers->search( |
443 |
my $transfer_requests = Koha::Item::Transfers->search( |
444 |
{ |
444 |
{ |
445 |
itemnumber => $sritem_1->itemnumber->itemnumber, |
445 |
itemnumber => $sritem_1->item->itemnumber, |
446 |
datearrived => undef, |
446 |
datearrived => undef, |
447 |
datecancelled => undef |
447 |
datecancelled => undef |
448 |
} |
448 |
} |
Lines 451-467
subtest "Tests for advance." => sub {
Link Here
|
451 |
|
451 |
|
452 |
# Arrive at new branch |
452 |
# Arrive at new branch |
453 |
$transfer_request->datearrived(dt_from_string())->store; |
453 |
$transfer_request->datearrived(dt_from_string())->store; |
454 |
$sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store; |
454 |
$sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store; |
455 |
|
455 |
|
456 |
# StockRotationAdvance transfer added |
456 |
# StockRotationAdvance transfer added |
457 |
$transfer_request = $sritem_1->itemnumber->get_transfer; |
457 |
$transfer_request = $sritem_1->item->get_transfer; |
458 |
is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer remains after reserve is met"); |
458 |
is($transfer_request->reason, 'StockrotationAdvance', "StockrotationAdvance transfer remains after reserve is met"); |
459 |
is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct."); |
459 |
is($transfer_request->frombranch, $srstage_1->branchcode_id, "Origin correct."); |
460 |
is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct."); |
460 |
is($transfer_request->tobranch, $srstage_2->branchcode_id, "Target correct."); |
461 |
|
461 |
|
462 |
# Arrive at new branch |
462 |
# Arrive at new branch |
463 |
$transfer_request->datearrived(dt_from_string())->store; |
463 |
$transfer_request->datearrived(dt_from_string())->store; |
464 |
$sritem_1->itemnumber->holdingbranch($srstage_2->branchcode_id)->store; |
464 |
$sritem_1->item->holdingbranch($srstage_2->branchcode_id)->store; |
465 |
|
465 |
|
466 |
# Checked out item, advanced to next stage, checkedout from next stage |
466 |
# Checked out item, advanced to next stage, checkedout from next stage |
467 |
# transfer should be generated, but not initiated |
467 |
# transfer should be generated, but not initiated |
Lines 502-508
subtest "Tests for advance." => sub {
Link Here
|
502 |
|
502 |
|
503 |
# Arrive at new branch |
503 |
# Arrive at new branch |
504 |
$transfer_request->datearrived(dt_from_string())->store; |
504 |
$transfer_request->datearrived(dt_from_string())->store; |
505 |
$sritem_1->itemnumber->holdingbranch($srstage_3->branchcode_id)->store; |
505 |
$sritem_1->item->holdingbranch($srstage_3->branchcode_id)->store; |
506 |
|
506 |
|
507 |
# Advance again, Remove from rota. |
507 |
# Advance again, Remove from rota. |
508 |
ok($sritem_1->advance, "Non-cyclical advance."); |
508 |
ok($sritem_1->advance, "Non-cyclical advance."); |
Lines 543-550
subtest "Tests for investigate (singular)." => sub {
Link Here
|
543 |
} |
543 |
} |
544 |
); |
544 |
); |
545 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
545 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
546 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
546 |
$dbitem->item->homebranch($dbitem->stage->branchcode_id)->store; |
547 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store; |
547 |
$dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store; |
548 |
is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates."); |
548 |
is($dbitem->investigate->{reason}, 'initiation', "fresh item at stagebranch initiates."); |
549 |
|
549 |
|
550 |
# Test item not at stagebranch with branchtransfer history ['repatriation'] |
550 |
# Test item not at stagebranch with branchtransfer history ['repatriation'] |
Lines 560-567
subtest "Tests for investigate (singular)." => sub {
Link Here
|
560 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
560 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
561 |
my $dbtransfer = Koha::Item::Transfer->new({ |
561 |
my $dbtransfer = Koha::Item::Transfer->new({ |
562 |
'itemnumber' => $dbitem->itemnumber_id, |
562 |
'itemnumber' => $dbitem->itemnumber_id, |
563 |
'frombranch' => $dbitem->itemnumber->homebranch, |
563 |
'frombranch' => $dbitem->item->homebranch, |
564 |
'tobranch' => $dbitem->itemnumber->homebranch, |
564 |
'tobranch' => $dbitem->item->homebranch, |
565 |
'datesent' => dt_from_string(), |
565 |
'datesent' => dt_from_string(), |
566 |
'datearrived' => dt_from_string(), |
566 |
'datearrived' => dt_from_string(), |
567 |
'reason' => "StockrotationAdvance", |
567 |
'reason' => "StockrotationAdvance", |
Lines 581-594
subtest "Tests for investigate (singular)." => sub {
Link Here
|
581 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
581 |
$dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
582 |
$dbtransfer = Koha::Item::Transfer->new({ |
582 |
$dbtransfer = Koha::Item::Transfer->new({ |
583 |
'itemnumber' => $dbitem->itemnumber_id, |
583 |
'itemnumber' => $dbitem->itemnumber_id, |
584 |
'frombranch' => $dbitem->itemnumber->homebranch, |
584 |
'frombranch' => $dbitem->item->homebranch, |
585 |
'tobranch' => $dbitem->stage->branchcode_id, |
585 |
'tobranch' => $dbitem->stage->branchcode_id, |
586 |
'datesent' => dt_from_string(), |
586 |
'datesent' => dt_from_string(), |
587 |
'datearrived' => dt_from_string(), |
587 |
'datearrived' => dt_from_string(), |
588 |
'reason' => "StockrotationAdvance", |
588 |
'reason' => "StockrotationAdvance", |
589 |
})->store; |
589 |
})->store; |
590 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
590 |
$dbitem->item->homebranch($dbitem->stage->branchcode_id)->store; |
591 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store; |
591 |
$dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store; |
592 |
is($dbitem->investigate->{reason}, 'not-ready', "older item at stagebranch not-ready."); |
592 |
is($dbitem->investigate->{reason}, 'not-ready', "older item at stagebranch not-ready."); |
593 |
|
593 |
|
594 |
# Test item due for advancement ['advancement'] |
594 |
# Test item due for advancement ['advancement'] |
Lines 608-621
subtest "Tests for investigate (singular)." => sub {
Link Here
|
608 |
my $arrived_duration = DateTime::Duration->new( days => 52); |
608 |
my $arrived_duration = DateTime::Duration->new( days => 52); |
609 |
$dbtransfer = Koha::Item::Transfer->new({ |
609 |
$dbtransfer = Koha::Item::Transfer->new({ |
610 |
'itemnumber' => $dbitem->itemnumber_id, |
610 |
'itemnumber' => $dbitem->itemnumber_id, |
611 |
'frombranch' => $dbitem->itemnumber->homebranch, |
611 |
'frombranch' => $dbitem->item->homebranch, |
612 |
'tobranch' => $dbitem->stage->branchcode_id, |
612 |
'tobranch' => $dbitem->stage->branchcode_id, |
613 |
'datesent' => dt_from_string() - $sent_duration, |
613 |
'datesent' => dt_from_string() - $sent_duration, |
614 |
'datearrived' => dt_from_string() - $arrived_duration, |
614 |
'datearrived' => dt_from_string() - $arrived_duration, |
615 |
'reason' => "StockrotationAdvance", |
615 |
'reason' => "StockrotationAdvance", |
616 |
})->store; |
616 |
})->store; |
617 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
617 |
$dbitem->item->homebranch($dbitem->stage->branchcode_id)->store; |
618 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store; |
618 |
$dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store; |
619 |
is($dbitem->investigate->{reason}, 'advancement', |
619 |
is($dbitem->investigate->{reason}, 'advancement', |
620 |
"Item ready for advancement."); |
620 |
"Item ready for advancement."); |
621 |
|
621 |
|
Lines 636-649
subtest "Tests for investigate (singular)." => sub {
Link Here
|
636 |
$arrived_duration = DateTime::Duration->new( days => 52); |
636 |
$arrived_duration = DateTime::Duration->new( days => 52); |
637 |
$dbtransfer = Koha::Item::Transfer->new({ |
637 |
$dbtransfer = Koha::Item::Transfer->new({ |
638 |
'itemnumber' => $dbitem->itemnumber_id, |
638 |
'itemnumber' => $dbitem->itemnumber_id, |
639 |
'frombranch' => $dbitem->itemnumber->homebranch, |
639 |
'frombranch' => $dbitem->item->homebranch, |
640 |
'tobranch' => $dbitem->stage->branchcode_id, |
640 |
'tobranch' => $dbitem->stage->branchcode_id, |
641 |
'datesent' => dt_from_string() - $sent_duration, |
641 |
'datesent' => dt_from_string() - $sent_duration, |
642 |
'datearrived' => dt_from_string() - $arrived_duration, |
642 |
'datearrived' => dt_from_string() - $arrived_duration, |
643 |
'reason' => "StockrotationAdvance", |
643 |
'reason' => "StockrotationAdvance", |
644 |
})->store; |
644 |
})->store; |
645 |
$dbitem->itemnumber->homebranch($dbitem->stage->branchcode_id)->store; |
645 |
$dbitem->item->homebranch($dbitem->stage->branchcode_id)->store; |
646 |
$dbitem->itemnumber->holdingbranch($dbitem->stage->branchcode_id)->store; |
646 |
$dbitem->item->holdingbranch($dbitem->stage->branchcode_id)->store; |
647 |
is($dbitem->investigate->{reason}, 'in-demand', |
647 |
is($dbitem->investigate->{reason}, 'in-demand', |
648 |
"Item advances, but in-demand."); |
648 |
"Item advances, but in-demand."); |
649 |
|
649 |
|
Lines 664-670
subtest "Tests for investigate (singular)." => sub {
Link Here
|
664 |
$arrived_duration = DateTime::Duration->new( days => 52); |
664 |
$arrived_duration = DateTime::Duration->new( days => 52); |
665 |
$dbtransfer = Koha::Item::Transfer->new({ |
665 |
$dbtransfer = Koha::Item::Transfer->new({ |
666 |
'itemnumber' => $dbitem->itemnumber_id, |
666 |
'itemnumber' => $dbitem->itemnumber_id, |
667 |
'frombranch' => $dbitem->itemnumber->homebranch, |
667 |
'frombranch' => $dbitem->item->homebranch, |
668 |
'tobranch' => $dbitem->stage->branchcode_id, |
668 |
'tobranch' => $dbitem->stage->branchcode_id, |
669 |
'datesent' => dt_from_string() - $sent_duration, |
669 |
'datesent' => dt_from_string() - $sent_duration, |
670 |
'datearrived' => dt_from_string() - $arrived_duration, |
670 |
'datearrived' => dt_from_string() - $arrived_duration, |
Lines 686-697
subtest "Tests for toggle_indemand" => sub {
Link Here
|
686 |
}); |
686 |
}); |
687 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
687 |
my $dbitem = Koha::StockRotationItems->find($sritem->{itemnumber_id}); |
688 |
my $firstbranch = $dbitem->stage->branchcode_id; |
688 |
my $firstbranch = $dbitem->stage->branchcode_id; |
689 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
689 |
$dbitem->item->holdingbranch($firstbranch)->store; |
690 |
my $dbstage = $dbitem->stage; |
690 |
my $dbstage = $dbitem->stage; |
691 |
$dbstage->position(1)->duration(50)->store; # Configure stage. |
691 |
$dbstage->position(1)->duration(50)->store; # Configure stage. |
692 |
# Configure item |
692 |
# Configure item |
693 |
$dbitem->itemnumber->holdingbranch($firstbranch)->store; |
693 |
$dbitem->item->holdingbranch($firstbranch)->store; |
694 |
$dbitem->itemnumber->homebranch($firstbranch)->store; |
694 |
$dbitem->item->homebranch($firstbranch)->store; |
695 |
# Sanity check |
695 |
# Sanity check |
696 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check."); |
696 |
is($dbitem->stage->stage_id, $dbstage->stage_id, "Stage sanity check."); |
697 |
|
697 |
|
Lines 715-721
subtest "Tests for toggle_indemand" => sub {
Link Here
|
715 |
# Test an item in transfer, toggle cancels transfer and resets indemand. |
715 |
# Test an item in transfer, toggle cancels transfer and resets indemand. |
716 |
ok($dbitem->advance, "Advancement done."); |
716 |
ok($dbitem->advance, "Advancement done."); |
717 |
$dbitem->get_from_storage; |
717 |
$dbitem->get_from_storage; |
718 |
my $transfer = $dbitem->itemnumber->get_transfer; |
718 |
my $transfer = $dbitem->item->get_transfer; |
719 |
is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected'); |
719 |
is(ref($transfer), 'Koha::Item::Transfer', 'Item set to in transfer as expected'); |
720 |
is($transfer->frombranch, $firstbranch, 'Transfer from set correctly'); |
720 |
is($transfer->frombranch, $firstbranch, 'Transfer from set correctly'); |
721 |
is($transfer->tobranch, $secondbranch, 'Transfer to set correctly'); |
721 |
is($transfer->tobranch, $secondbranch, 'Transfer to set correctly'); |
Lines 727-733
subtest "Tests for toggle_indemand" => sub {
Link Here
|
727 |
isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected'); |
727 |
isnt($updated_transfer->datearrived, undef, 'Transfer datearrived set as expected'); |
728 |
is($dbitem->indemand, 0, "Item retains indemand as expected."); |
728 |
is($dbitem->indemand, 0, "Item retains indemand as expected."); |
729 |
is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.'); |
729 |
is($dbitem->stage_id, $dbstage->id, 'Item stage reset as expected.'); |
730 |
is($dbitem->itemnumber->homebranch, $firstbranch, 'Item homebranch reset as expected.'); |
730 |
is($dbitem->item->homebranch, $firstbranch, 'Item homebranch reset as expected.'); |
731 |
|
731 |
|
732 |
$schema->storage->txn_rollback; |
732 |
$schema->storage->txn_rollback; |
733 |
}; |
733 |
}; |
734 |
- |
|
|