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

(-)a/Koha/Hold.pm (-7 / +8 lines)
Lines 889-907 sub fill { Link Here
889
    return $self;
889
    return $self;
890
}
890
}
891
891
892
=head3 revert_waiting
892
=head3 revert_found
893
893
894
    $hold->revert_waiting();
894
    $hold->revert_found();
895
895
896
Reverts a 'waiting' hold back to a regular hold with a priority of 1.
896
Reverts any 'found' hold back to a regular hold with a priority of 1.
897
This method can revert holds in 'waiting' (W), 'in transit' (T), or 'in processing' (P) status.
897
898
898
=cut
899
=cut
899
900
900
sub revert_waiting {
901
sub revert_found {
901
    my ( $self, $params ) = @_;
902
    my ( $self, $params ) = @_;
902
903
903
    Koha::Exceptions::InvalidStatus->throw( invalid_status => 'hold_not_waiting' )
904
    Koha::Exceptions::InvalidStatus->throw( invalid_status => 'hold_not_found' )
904
        unless $self->is_waiting;
905
        unless $self->is_found;
905
906
906
    $self->_result->result_source->schema->txn_do(
907
    $self->_result->result_source->schema->txn_do(
907
        sub {
908
        sub {
Lines 919-925 sub revert_waiting { Link Here
919
                { no_triggers => 1 }
920
                { no_triggers => 1 }
920
            );
921
            );
921
922
922
            ## Fix up the currently waiting reserve
923
            ## Fix up the currently found reserve
923
            $self->set(
924
            $self->set(
924
                {
925
                {
925
                    priority       => 1,
926
                    priority       => 1,
(-)a/t/db_dependent/Koha/Hold.t (-16 / +113 lines)
Lines 1262-1270 subtest 'strings_map() tests' => sub { Link Here
1262
    $schema->txn_rollback;
1262
    $schema->txn_rollback;
1263
};
1263
};
1264
1264
1265
subtest 'revert_waiting() tests' => sub {
1265
subtest 'revert_found() tests' => sub {
1266
1266
1267
    plan tests => 3;
1267
    plan tests => 5;
1268
1268
1269
    subtest 'item-level holds tests' => sub {
1269
    subtest 'item-level holds tests' => sub {
1270
1270
Lines 1318-1325 subtest 'revert_waiting() tests' => sub { Link Here
1318
        is( $hold->priority, 0, "'priority' set to 0" );
1318
        is( $hold->priority, 0, "'priority' set to 0" );
1319
        ok( $hold->is_waiting, 'Hold set to waiting' );
1319
        ok( $hold->is_waiting, 'Hold set to waiting' );
1320
1320
1321
        # Revert the waiting status
1321
        # Revert the found status
1322
        $hold->revert_waiting();
1322
        $hold->revert_found();
1323
1323
1324
        is( $hold->waitingdate, undef, "'waitingdate' reset" );
1324
        is( $hold->waitingdate, undef, "'waitingdate' reset" );
1325
        ok( !$hold->is_waiting, 'Hold no longer set to waiting' );
1325
        ok( !$hold->is_waiting, 'Hold no longer set to waiting' );
Lines 1342-1361 subtest 'revert_waiting() tests' => sub { Link Here
1342
1342
1343
        $hold->set_waiting();
1343
        $hold->set_waiting();
1344
1344
1345
        # Revert the waiting status, RealTimeHoldsQueue => shouldn't add a test
1345
        # Revert the found status, RealTimeHoldsQueue => shouldn't add a test
1346
        $hold->revert_waiting();
1346
        $hold->revert_found();
1347
1347
1348
        my $log_count_after =
1348
        my $log_count_after =
1349
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count;
1349
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count;
1350
        is( $log_count, $log_count_after, "No logging is added for ->revert_waiting() when HoldsLog is disabled" );
1350
        is( $log_count, $log_count_after, "No logging is added for ->revert_found() when HoldsLog is disabled" );
1351
1351
1352
        # Set as 'processing' to test the exception behavior
1352
        # Set as regular hold (not found) to test the exception behavior
1353
        $hold->found('P');
1353
        $hold->found(undef);
1354
        throws_ok { $hold->revert_waiting() }
1354
        throws_ok { $hold->revert_found() }
1355
        'Koha::Exceptions::InvalidStatus',
1355
        'Koha::Exceptions::InvalidStatus',
1356
            "Hold is not in 'waiting' status, exception thrown";
1356
            "Hold is not in 'found' status, exception thrown";
1357
1357
1358
        is( $@->invalid_status, 'hold_not_waiting', "'invalid_status' set the right value" );
1358
        is( $@->invalid_status, 'hold_not_found', "'invalid_status' set the right value" );
1359
1359
1360
        $schema->storage->txn_rollback;
1360
        $schema->storage->txn_rollback;
1361
    };
1361
    };
Lines 1399-1406 subtest 'revert_waiting() tests' => sub { Link Here
1399
        is( $hold->priority, 0, "'priority' set to 0" );
1399
        is( $hold->priority, 0, "'priority' set to 0" );
1400
        ok( $hold->is_waiting, 'Hold set to waiting' );
1400
        ok( $hold->is_waiting, 'Hold set to waiting' );
1401
1401
1402
        # Revert the waiting status
1402
        # Revert the found status
1403
        $hold->revert_waiting();
1403
        $hold->revert_found();
1404
1404
1405
        is( $hold->waitingdate, undef, "'waitingdate' reset" );
1405
        is( $hold->waitingdate, undef, "'waitingdate' reset" );
1406
        ok( !$hold->is_waiting, 'Hold no longer set to waiting' );
1406
        ok( !$hold->is_waiting, 'Hold no longer set to waiting' );
Lines 1478-1484 subtest 'revert_waiting() tests' => sub { Link Here
1478
        $hold->set_waiting()->discard_changes();
1478
        $hold->set_waiting()->discard_changes();
1479
        is( $hold->priority, 0, "'priority' set to 0" );
1479
        is( $hold->priority, 0, "'priority' set to 0" );
1480
1480
1481
        $hold->revert_waiting()->discard_changes();
1481
        $hold->revert_found()->discard_changes();
1482
        is( $hold->priority, 1, "'priority' set to 1" );
1482
        is( $hold->priority, 1, "'priority' set to 1" );
1483
1483
1484
        my $holds = $item->biblio->holds;
1484
        my $holds = $item->biblio->holds;
Lines 1493-1496 subtest 'revert_waiting() tests' => sub { Link Here
1493
1493
1494
        $schema->storage->txn_rollback;
1494
        $schema->storage->txn_rollback;
1495
    };
1495
    };
1496
1497
    subtest 'in transit holds tests' => sub {
1498
1499
        plan tests => 8;
1500
1501
        $schema->storage->txn_begin;
1502
1503
        my $item   = $builder->build_sample_item;
1504
        my $patron = $builder->build_object(
1505
            {
1506
                class => 'Koha::Patrons',
1507
                value => { branchcode => $item->homebranch }
1508
            }
1509
        );
1510
1511
        # Create item-level hold
1512
        my $hold = Koha::Holds->find(
1513
            AddReserve(
1514
                {
1515
                    branchcode     => $item->homebranch,
1516
                    borrowernumber => $patron->borrowernumber,
1517
                    biblionumber   => $item->biblionumber,
1518
                    priority       => 1,
1519
                    itemnumber     => $item->itemnumber,
1520
                }
1521
            )
1522
        );
1523
1524
        # Mark it in transit
1525
        $hold->set_transfer();
1526
1527
        is( $hold->priority, 0, "'priority' set to 0" );
1528
        ok( $hold->is_in_transit, 'Hold set to in transit' );
1529
        is( $hold->found, 'T', "'found' set to 'T'" );
1530
1531
        # Revert the found status
1532
        $hold->revert_found();
1533
1534
        ok( !$hold->is_in_transit, 'Hold no longer set to in transit' );
1535
        ok( !$hold->is_found,      'Hold no longer has found status' );
1536
        is( $hold->found,    undef, "'found' reset to undef" );
1537
        is( $hold->priority, 1,     "'priority' set to 1" );
1538
        is(
1539
            $hold->itemnumber, $item->itemnumber,
1540
            'Itemnumber should not be removed when the found status is reverted'
1541
        );
1542
1543
        $schema->storage->txn_rollback;
1544
    };
1545
1546
    subtest 'in processing holds tests' => sub {
1547
1548
        plan tests => 8;
1549
1550
        $schema->storage->txn_begin;
1551
1552
        my $item   = $builder->build_sample_item;
1553
        my $patron = $builder->build_object(
1554
            {
1555
                class => 'Koha::Patrons',
1556
                value => { branchcode => $item->homebranch }
1557
            }
1558
        );
1559
1560
        # Create item-level hold
1561
        my $hold = Koha::Holds->find(
1562
            AddReserve(
1563
                {
1564
                    branchcode     => $item->homebranch,
1565
                    borrowernumber => $patron->borrowernumber,
1566
                    biblionumber   => $item->biblionumber,
1567
                    priority       => 1,
1568
                    itemnumber     => $item->itemnumber,
1569
                }
1570
            )
1571
        );
1572
1573
        # Mark it in processing
1574
        $hold->set_processing();
1575
1576
        is( $hold->priority, 0, "'priority' set to 0" );
1577
        ok( $hold->is_in_processing, 'Hold set to in processing' );
1578
        is( $hold->found, 'P', "'found' set to 'P'" );
1579
1580
        # Revert the found status
1581
        $hold->revert_found();
1582
1583
        ok( !$hold->is_in_processing, 'Hold no longer set to in processing' );
1584
        ok( !$hold->is_found,         'Hold no longer has found status' );
1585
        is( $hold->found,    undef, "'found' reset to undef" );
1586
        is( $hold->priority, 1,     "'priority' set to 1" );
1587
        is(
1588
            $hold->itemnumber, $item->itemnumber,
1589
            'Itemnumber should not be removed when the found status is reverted'
1590
        );
1591
1592
        $schema->storage->txn_rollback;
1593
    };
1496
};
1594
};
1497
- 

Return to bug 40671