|
Lines 3475-3531
subtest 'Set waiting flag' => sub {
Link Here
|
| 3475 |
}; |
3475 |
}; |
| 3476 |
|
3476 |
|
| 3477 |
subtest 'Cancel transfers on lost items' => sub { |
3477 |
subtest 'Cancel transfers on lost items' => sub { |
| 3478 |
plan tests => 6; |
3478 |
plan tests => 5; |
| 3479 |
my $library_1 = $builder->build( { source => 'Branch' } ); |
|
|
| 3480 |
my $patron_1 = $builder->build( { source => 'Borrower', value => { branchcode => $library_1->{branchcode}, categorycode => $patron_category->{categorycode} } } ); |
| 3481 |
my $library_2 = $builder->build( { source => 'Branch' } ); |
| 3482 |
my $patron_2 = $builder->build( { source => 'Borrower', value => { branchcode => $library_2->{branchcode}, categorycode => $patron_category->{categorycode} } } ); |
| 3483 |
my $biblio = $builder->build_sample_biblio({branchcode => $library->{branchcode}}); |
| 3484 |
my $item = $builder->build_sample_item({ |
| 3485 |
biblionumber => $biblio->biblionumber, |
| 3486 |
library => $library_1->{branchcode}, |
| 3487 |
}); |
| 3488 |
|
3479 |
|
| 3489 |
set_userenv( $library_2 ); |
3480 |
my $library_to = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 3490 |
my $reserve_id = AddReserve( |
3481 |
my $item = $builder->build_sample_item(); |
|
|
3482 |
my $old_transfer = $builder->build_object( |
| 3491 |
{ |
3483 |
{ |
| 3492 |
branchcode => $library_2->{branchcode}, |
3484 |
class => 'Koha::Item::Transfers', |
| 3493 |
borrowernumber => $patron_2->{borrowernumber}, |
3485 |
value => { |
| 3494 |
biblionumber => $item->biblionumber, |
3486 |
itemnumber => $item->itemnumber, |
| 3495 |
priority => 1, |
3487 |
frombranch => $item->holdingbranch, |
| 3496 |
itemnumber => $item->itemnumber, |
3488 |
tobranch => $library_to->branchcode, |
|
|
3489 |
reason => 'Manual', |
| 3490 |
datesent => \'NOW()', |
| 3491 |
datearrived => \'NOW()', |
| 3492 |
datecancelled => undef, |
| 3493 |
daterequested => \'NOW()' |
| 3494 |
} |
| 3495 |
} |
| 3496 |
); |
| 3497 |
my $transfer_1 = $builder->build_object( |
| 3498 |
{ |
| 3499 |
class => 'Koha::Item::Transfers', |
| 3500 |
value => { |
| 3501 |
itemnumber => $item->itemnumber, |
| 3502 |
frombranch => $item->holdingbranch, |
| 3503 |
tobranch => $library_to->branchcode, |
| 3504 |
reason => 'Manual', |
| 3505 |
datesent => undef, |
| 3506 |
datearrived => undef, |
| 3507 |
datecancelled => undef, |
| 3508 |
daterequested => \'NOW()' |
| 3509 |
} |
| 3510 |
} |
| 3511 |
); |
| 3512 |
my $transfer_2 = $builder->build_object( |
| 3513 |
{ |
| 3514 |
class => 'Koha::Item::Transfers', |
| 3515 |
value => { |
| 3516 |
itemnumber => $item->itemnumber, |
| 3517 |
frombranch => $item->holdingbranch, |
| 3518 |
tobranch => $library_to->branchcode, |
| 3519 |
reason => 'Manual', |
| 3520 |
datesent => \'NOW()', |
| 3521 |
datearrived => undef, |
| 3522 |
datecancelled => undef, |
| 3523 |
daterequested => \'NOW()' |
| 3524 |
} |
| 3497 |
} |
3525 |
} |
| 3498 |
); |
3526 |
); |
| 3499 |
|
3527 |
|
| 3500 |
#Return book and add transfer |
3528 |
# Simulate item being marked as lost |
| 3501 |
set_userenv( $library_1 ); |
|
|
| 3502 |
my $do_transfer = 1; |
| 3503 |
my ( $res, $rr ) = AddReturn( $item->barcode, $library_1->{branchcode} ); |
| 3504 |
ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id ); |
| 3505 |
C4::Circulation::transferbook({ |
| 3506 |
from_branch => $library_1->{branchcode}, |
| 3507 |
to_branch => $library_2->{branchcode}, |
| 3508 |
barcode => $item->barcode, |
| 3509 |
trigger => 'Reserve', |
| 3510 |
}); |
| 3511 |
my $hold = Koha::Holds->find( $reserve_id ); |
| 3512 |
is( $hold->found, 'T', 'Hold is in transit' ); |
| 3513 |
|
| 3514 |
#Check transfer exists and the items holding branch is the transfer destination branch before marking it as lost |
| 3515 |
my ($datesent,$frombranch,$tobranch) = GetTransfers($item->itemnumber); |
| 3516 |
is( $frombranch, $library_1->{branchcode}, 'The transfer is generated from the correct library'); |
| 3517 |
is( $tobranch, $library_2->{branchcode}, 'The transfer is generated to the correct library'); |
| 3518 |
my $itemcheck = Koha::Items->find($item->itemnumber); |
| 3519 |
is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Items holding branch is the transfers origination branch before it is marked as lost' ); |
| 3520 |
|
| 3521 |
#Simulate item being marked as lost and confirm the transfer is deleted and the items holding branch is the transfers source branch |
| 3522 |
$item->itemlost(1)->store; |
3529 |
$item->itemlost(1)->store; |
| 3523 |
LostItem( $item->itemnumber, 'test', 1 ); |
3530 |
LostItem( $item->itemnumber, 'test', 1 ); |
| 3524 |
($datesent,$frombranch,$tobranch) = GetTransfers($item->itemnumber); |
|
|
| 3525 |
is( $tobranch, undef, 'The transfer on the lost item has been deleted as the LostItemCancelOutstandingTransfer is enabled'); |
| 3526 |
$itemcheck = Koha::Items->find($item->itemnumber); |
| 3527 |
is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Lost item with cancelled hold has holding branch equallying the transfers source branch' ); |
| 3528 |
|
3531 |
|
|
|
3532 |
$transfer_1->discard_changes; |
| 3533 |
isnt($transfer_1->datecancelled, undef, "Queud transfer was cancelled upon item lost"); |
| 3534 |
is($transfer_1->cancellation_reason, 'ItemLost', "Cancellation reason was set to 'ItemLost'"); |
| 3535 |
$transfer_2->discard_changes; |
| 3536 |
isnt($transfer_2->datecancelled, undef, "Active transfer was cancelled upon item lost"); |
| 3537 |
is($transfer_2->cancellation_reason, 'ItemLost', "Cancellation reason was set to 'ItemLost'"); |
| 3538 |
$old_transfer->discard_changes; |
| 3539 |
is($old_transfer->datecancelled, undef, "Old transfers are unaffected"); |
| 3529 |
}; |
3540 |
}; |
| 3530 |
|
3541 |
|
| 3531 |
subtest 'CanBookBeIssued | is_overdue' => sub { |
3542 |
subtest 'CanBookBeIssued | is_overdue' => sub { |
| 3532 |
- |
|
|