View | Details | Raw Unified | Return to bug 27281
Collapse All | Expand All

(-)a/t/db_dependent/Circulation.t (-44 / +54 lines)
Lines 3389-3445 subtest 'Set waiting flag' => sub { Link Here
3389
};
3389
};
3390
3390
3391
subtest 'Cancel transfers on lost items' => sub {
3391
subtest 'Cancel transfers on lost items' => sub {
3392
    plan tests => 6;
3392
    plan tests => 5;
3393
    my $library_1 = $builder->build( { source => 'Branch' } );
3394
    my $patron_1 = $builder->build( { source => 'Borrower', value => { branchcode => $library_1->{branchcode}, categorycode => $patron_category->{categorycode} } } );
3395
    my $library_2 = $builder->build( { source => 'Branch' } );
3396
    my $patron_2  = $builder->build( { source => 'Borrower', value => { branchcode => $library_2->{branchcode}, categorycode => $patron_category->{categorycode} } } );
3397
    my $biblio = $builder->build_sample_biblio({branchcode => $library->{branchcode}});
3398
    my $item   = $builder->build_sample_item({
3399
        biblionumber  => $biblio->biblionumber,
3400
        library    => $library_1->{branchcode},
3401
    });
3402
3393
3403
    set_userenv( $library_2 );
3394
    my $library_to = $builder->build_object( { class => 'Koha::Libraries' } );
3404
    my $reserve_id = AddReserve(
3395
    my $item   = $builder->build_sample_item();
3396
    my $old_transfer = $builder->build_object(
3405
        {
3397
        {
3406
            branchcode     => $library_2->{branchcode},
3398
            class => 'Koha::Item::Transfers',
3407
            borrowernumber => $patron_2->{borrowernumber},
3399
            value => {
3408
            biblionumber   => $item->biblionumber,
3400
                itemnumber    => $item->itemnumber,
3409
            priority       => 1,
3401
                frombranch    => $item->holdingbranch,
3410
            itemnumber     => $item->itemnumber,
3402
                tobranch      => $library_to->branchcode,
3403
                reason        => 'Manual',
3404
                datesent      => \'NOW()',
3405
                datearrived   => \'NOW()',
3406
                datecancelled => undef,
3407
                daterequested => \'NOW()'
3408
            }
3409
        }
3410
    );
3411
    my $transfer_1 = $builder->build_object(
3412
        {
3413
            class => 'Koha::Item::Transfers',
3414
            value => {
3415
                itemnumber    => $item->itemnumber,
3416
                frombranch    => $item->holdingbranch,
3417
                tobranch      => $library_to->branchcode,
3418
                reason        => 'Manual',
3419
                datesent      => undef,
3420
                datearrived   => undef,
3421
                datecancelled => undef,
3422
                daterequested => \'NOW()'
3423
            }
3424
        }
3425
    );
3426
    my $transfer_2 = $builder->build_object(
3427
        {
3428
            class => 'Koha::Item::Transfers',
3429
            value => {
3430
                itemnumber    => $item->itemnumber,
3431
                frombranch    => $item->holdingbranch,
3432
                tobranch      => $library_to->branchcode,
3433
                reason        => 'Manual',
3434
                datesent      => \'NOW()',
3435
                datearrived   => undef,
3436
                datecancelled => undef,
3437
                daterequested => \'NOW()'
3438
            }
3411
        }
3439
        }
3412
    );
3440
    );
3413
3441
3414
    #Return book and add transfer
3442
    # Simulate item being marked as lost
3415
    set_userenv( $library_1 );
3416
    my $do_transfer = 1;
3417
    my ( $res, $rr ) = AddReturn( $item->barcode, $library_1->{branchcode} );
3418
    ModReserveAffect( $item->itemnumber, undef, $do_transfer, $reserve_id );
3419
    C4::Circulation::transferbook({
3420
        from_branch => $library_1->{branchcode},
3421
        to_branch => $library_2->{branchcode},
3422
        barcode   => $item->barcode,
3423
        trigger   => 'Reserve',
3424
    });
3425
    my $hold = Koha::Holds->find( $reserve_id );
3426
    is( $hold->found, 'T', 'Hold is in transit' );
3427
3428
    #Check transfer exists and the items holding branch is the transfer destination branch before marking it as lost
3429
    my ($datesent,$frombranch,$tobranch) = GetTransfers($item->itemnumber);
3430
    is( $frombranch, $library_1->{branchcode}, 'The transfer is generated from the correct library');
3431
    is( $tobranch, $library_2->{branchcode}, 'The transfer is generated to the correct library');
3432
    my $itemcheck = Koha::Items->find($item->itemnumber);
3433
    is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Items holding branch is the transfers origination branch before it is marked as lost' );
3434
3435
    #Simulate item being marked as lost and confirm the transfer is deleted and the items holding branch is the transfers source branch
3436
    $item->itemlost(1)->store;
3443
    $item->itemlost(1)->store;
3437
    LostItem( $item->itemnumber, 'test', 1 );
3444
    LostItem( $item->itemnumber, 'test', 1 );
3438
    ($datesent,$frombranch,$tobranch) = GetTransfers($item->itemnumber);
3439
    is( $tobranch, undef, 'The transfer on the lost item has been deleted as the LostItemCancelOutstandingTransfer is enabled');
3440
    $itemcheck = Koha::Items->find($item->itemnumber);
3441
    is( $itemcheck->holdingbranch, $library_1->{branchcode}, 'Lost item with cancelled hold has holding branch equallying the transfers source branch' );
3442
3445
3446
    $transfer_1->discard_changes;
3447
    isnt($transfer_1->datecancelled, undef, "Queud transfer was cancelled upon item lost");
3448
    is($transfer_1->cancellation_reason, 'ItemLost', "Cancellation reason was set to 'ItemLost'");
3449
    $transfer_2->discard_changes;
3450
    isnt($transfer_2->datecancelled, undef, "Active transfer was cancelled upon item lost");
3451
    is($transfer_2->cancellation_reason, 'ItemLost', "Cancellation reason was set to 'ItemLost'");
3452
    $old_transfer->discard_changes;
3453
    is($old_transfer->datecancelled, undef, "Old transfers are unaffected");
3443
};
3454
};
3444
3455
3445
subtest 'CanBookBeIssued | is_overdue' => sub {
3456
subtest 'CanBookBeIssued | is_overdue' => sub {
3446
- 

Return to bug 27281