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

(-)a/C4/Circulation.pm (+36 lines)
Lines 4222-4227 sub LostItem{ Link Here
4222
    while (my $transfer = $transfers->next) {
4222
    while (my $transfer = $transfers->next) {
4223
        $transfer->cancel({ reason => 'ItemLost', force => 1 });
4223
        $transfer->cancel({ reason => 'ItemLost', force => 1 });
4224
    }
4224
    }
4225
4226
    # RevertLostBibLevelHolds
4227
    my $hold = Koha::Holds->find( { itemnumber => $itemnumber, found => { '!=' => undef } } );
4228
    if ( C4::Context->preference('RevertLostBibLevelHolds') && defined $hold ) {
4229
4230
        # syspref is enabled and there is a waiting hold for this item
4231
        if ( $hold->item_level_hold && defined $params->{cancel_reserve} ) {
4232
            if ( $params->{cancel_reserve} ) {
4233
4234
                # cancel item-level hold
4235
                $hold->cancel;
4236
            } else {    # eq 'revert'
4237
                        # revert item-level hold's waiting status
4238
                $hold = C4::Reserves::RevertWaitingStatus( { itemnumber => $itemnumber } );
4239
            }
4240
        }
4241
        if ( !$hold->item_level_hold ) {
4242
4243
            # revert biblio-level hold's waiting status
4244
            $hold = C4::Reserves::RevertWaitingStatus( { itemnumber => $itemnumber } );
4245
        }
4246
    }
4247
4248
    # SendLostHoldNotices
4249
    if ( C4::Context->preference('SendLostHoldNotices') && defined $hold && $item->itemlost ) {
4250
        my $letter = C4::Letters::GetPreparedLetter(
4251
            module      => 'reserves',
4252
            letter_code => 'LOST_WAITING_HOLD',
4253
            branchcode  => $hold->branchcode,
4254
            tables      => {
4255
                borrowers => $hold->borrowernumber,
4256
                branches  => $hold->branchcode,
4257
            },
4258
        );
4259
        C4::Message->enqueue( $letter, $hold->borrower, 'email' );
4260
    }
4225
}
4261
}
4226
4262
4227
sub GetOfflineOperations {
4263
sub GetOfflineOperations {
(-)a/catalogue/moredetail.pl (+5 lines)
Lines 249-254 foreach my $item (@items){ Link Here
249
249
250
    $item_info->{nomod} = !$patron->can_edit_items_from( $item->homebranch );
250
    $item_info->{nomod} = !$patron->can_edit_items_from( $item->homebranch );
251
251
252
    if ( C4::Context->preference('RevertLostBibLevelHolds') ) {
253
        $item_info->{waiting_holds} =
254
            $item->holds( { found => [ 'W', 'T' ], item_level_hold => { '!=' => 0 } } )->count;
255
    }
256
252
    push @item_data, $item_info;
257
    push @item_data, $item_info;
253
}
258
}
254
259
(-)a/catalogue/updateitem.pl (-10 / +25 lines)
Lines 29-45 my $cgi= CGI->new; Link Here
29
29
30
checkauth($cgi, 0, {circulate => 'circulate_remaining_permissions'}, 'intranet');
30
checkauth($cgi, 0, {circulate => 'circulate_remaining_permissions'}, 'intranet');
31
31
32
my $op = $cgi->param('op') || "";
32
my $op                                = $cgi->param('op') || "";
33
my $biblionumber=$cgi->param('biblionumber');
33
my $biblionumber                      = $cgi->param('biblionumber');
34
my $itemnumber=$cgi->param('itemnumber');
34
my $itemnumber                        = $cgi->param('itemnumber');
35
my $biblioitemnumber=$cgi->param('biblioitemnumber');
35
my $biblioitemnumber                  = $cgi->param('biblioitemnumber');
36
my $itemlost=$cgi->param('itemlost');
36
my $itemlost                          = $cgi->param('itemlost');
37
my $itemnotes=$cgi->param('itemnotes');
37
my $itemnotes                         = $cgi->param('itemnotes');
38
my $itemnotes_nonpublic=$cgi->param('itemnotes_nonpublic');
38
my $itemnotes_nonpublic               = $cgi->param('itemnotes_nonpublic');
39
my $withdrawn=$cgi->param('withdrawn');
39
my $withdrawn                         = $cgi->param('withdrawn');
40
my $damaged=$cgi->param('damaged');
40
my $damaged                           = $cgi->param('damaged');
41
my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority');
41
my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority');
42
my $bookable = $cgi->param('bookable');
42
my $bookable                          = $cgi->param('bookable');
43
my $cancelhold                        = $cgi->param('cancelhold');
44
my $reverthold                        = $cgi->param('reverthold');
45
my $redirecturl                       = $cgi->param('redirecturl');
46
47
if ( defined $cancelhold ) {
48
    LostItem( $itemnumber, 'moredetail', 0, { cancel_reserve => $cancelhold } );
49
} elsif ( defined $reverthold ) {
50
    $cancelhold = 0;
51
    LostItem( $itemnumber, 'moredetail', 0, { cancel_reserve => $cancelhold } );
52
} else {
53
    $cancelhold = undef;
54
}
55
if ( defined $redirecturl ) {
56
    print $cgi->redirect( $redirecturl . $biblionumber );
57
}
43
58
44
my $confirm=$cgi->param('confirm');
59
my $confirm=$cgi->param('confirm');
45
my $dbh = C4::Context->dbh;
60
my $dbh = C4::Context->dbh;
(-)a/cataloguing/additem.pl (+13 lines)
Lines 796-801 my @ig = Koha::Biblio::ItemGroups->search( { biblio_id => $biblionumber } )->as_ Link Here
796
#sort by display order
796
#sort by display order
797
my @sorted_ig = sort { $a->display_order <=> $b->display_order } @ig;
797
my @sorted_ig = sort { $a->display_order <=> $b->display_order } @ig;
798
798
799
if ( C4::Context->preference('RevertLostBibLevelHolds') ) {
800
    my @lostitems = Koha::Items->search( { biblionumber => $biblionumber, itemlost => { '!=' => 0 } } )->as_list;
801
802
    # find if any of these lost items have waiting holds
803
    my @waitinglostitems;
804
    foreach my $lostitem (@lostitems) {
805
        if ( $lostitem->holds( { found => [ 'W', 'T' ], item_level_hold => 1 } )->count > 0 ) {
806
            push( @waitinglostitems, $lostitem );
807
        }
808
    }
809
    $template->param( waitinglostitems => \@waitinglostitems );
810
}
811
799
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
812
# what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit.
800
$template->param(
813
$template->param(
801
    biblio           => $biblio,
814
    biblio           => $biblio,
(-)a/installer/data/mysql/atomicupdate/bug_20844-add_LOST_WAITING_HOLD_notice.perl (+6 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{INSERT IGNORE INTO letter (module, code, branchcode, name, is_html, title, message_transport_type, content) VALUES ('reserves','LOST_WAITING_HOLD','','Waiting hold marked lost','0','Your waiting hold has been marked lost','email',"Dear [% borrower.firstname %] [% borrowers.surname %],<br><br>Your hold awaiting pickup is no longer available. The item is lost.<br><br>Please contact the library for more information.<br><br>Thank you,<br><br>[% branch.branchname %]") });
4
5
    NewVersion( $DBversion, 20844, "Add LOST_WAITING_HOLD notice");
6
}
(-)a/installer/data/mysql/atomicupdate/bug_20844-add_RevertLostBibLevelHolds_syspref.perl (+6 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('RevertLostBibLevelHolds', '0', NULL, 'If an item is marked as lost after being allocated for a biblio-level hold, revert the hold from its waiting status', 'YesNo') });
4
5
    NewVersion( $DBversion, 20844, "Add RevertLostBibLevelHolds system preference");
6
}
(-)a/installer/data/mysql/atomicupdate/bug_20844-add_SendLostHoldNotices_syspref.perl (+6 lines)
Line 0 Link Here
1
$DBversion = 'XXX';
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('SendLostHoldNotices', '0', NULL, 'Send a notice to a borrower if their reserved and waiting item is marked as lost', 'YesNo') });
4
5
    NewVersion( $DBversion, 20844, "Add SendLostHoldNotices system preference");
6
}
(-)a/installer/data/mysql/en/mandatory/sample_notices.yml (+19 lines)
Lines 2512-2514 tables: Link Here
2512
            - "Your hold on [% hold.biblio.title %] ([% hold.biblio.id %]) has been confirmed."
2512
            - "Your hold on [% hold.biblio.title %] ([% hold.biblio.id %]) has been confirmed."
2513
            - "You will be notified by the library when your item is available for pickup."
2513
            - "You will be notified by the library when your item is available for pickup."
2514
            - "Thank you!"
2514
            - "Thank you!"
2515
2516
        - module: reserves
2517
          code: LOST_WAITING_HOLD
2518
          branchcode: ""
2519
          name: "Waiting hold marked lost"
2520
          is_html: 0
2521
          title: "Your waiting hold has been marked lost"
2522
          message_transport_type: email
2523
          lang: default
2524
          content:
2525
            - "Dear [% borrower.firstname %] [% borrowers.surname %],"
2526
            - ""
2527
            - "Your hold awaiting pickup is no longer available. The item is lost."
2528
            - ""
2529
            - "Please contact the library for more information."
2530
            - ""
2531
            - "Thank you,"
2532
            - ""
2533
            - "[% branch.branchname %]"
(-)a/installer/data/mysql/mandatory/sysprefs.sql (+2 lines)
Lines 677-682 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
677
('ReturnBeforeExpiry','0',NULL,'If ON, checkout will be prevented if returndate is after patron card expiry','YesNo'),
677
('ReturnBeforeExpiry','0',NULL,'If ON, checkout will be prevented if returndate is after patron card expiry','YesNo'),
678
('ReturnLog','1',NULL,'If ON, enables the circulation (returns) log','YesNo'),
678
('ReturnLog','1',NULL,'If ON, enables the circulation (returns) log','YesNo'),
679
('ReturnpathDefault','',NULL,'Use this email address as return path or bounce address for undeliverable emails','Free'),
679
('ReturnpathDefault','',NULL,'Use this email address as return path or bounce address for undeliverable emails','Free'),
680
('RevertLostBibLevelHolds', '0', NULL, 'If an item is marked as lost after being allocated for a biblio-level hold, revert the hold from its waiting status', 'YesNo'),
680
('RisExportAdditionalFields',  '', NULL ,  'Define additional RIS tags to export from MARC records in YAML format as an associative array with either a marc tag/subfield combination as the value, or a list of tag/subfield combinations.',  'textarea'),
681
('RisExportAdditionalFields',  '', NULL ,  'Define additional RIS tags to export from MARC records in YAML format as an associative array with either a marc tag/subfield combination as the value, or a list of tag/subfield combinations.',  'textarea'),
681
('RoundFinesAtPayment','0', NULL,'If enabled any fines with fractions of a cent will be rounded to the nearest cent when payments are coll    ected. e.g. 1.004 will be paid off by a 1.00 payment','YesNo'),
682
('RoundFinesAtPayment','0', NULL,'If enabled any fines with fractions of a cent will be rounded to the nearest cent when payments are coll    ected. e.g. 1.004 will be paid off by a 1.00 payment','YesNo'),
682
('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
683
('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'),
Lines 702-707 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
702
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
703
('SelfCheckReceiptPrompt','1','NULL','If ON, print receipt dialog pops up when self checkout is finished','YesNo'),
703
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
704
('SelfCheckTimeout','120','','Define the number of seconds before the Web-based Self Checkout times out a patron','Integer'),
704
('SendAllEmailsTo','',NULL,'All emails will be redirected to this email if it is not empty','free'),
705
('SendAllEmailsTo','',NULL,'All emails will be redirected to this email if it is not empty','free'),
706
('SendLostHoldNotices', '0', NULL, 'Send a notice to a borrower if their reserved and waiting item is marked as lost', 'YesNo'),
705
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
707
('SeparateHoldings','0',NULL,'Separate current branch holdings from other holdings','YesNo'),
706
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
708
('SeparateHoldingsBranch','homebranch','homebranch|holdingbranch','Branch used to separate holdings','Choice'),
707
('SerialsDefaultEmailAddress', '', NULL, 'Default email address used as reply-to for notices sent by the serials module.', 'Free'),
709
('SerialsDefaultEmailAddress', '', NULL, 'Default email address used as reply-to for notices sent by the serials module.', 'Free'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (+12 lines)
Lines 745-750 Circulation: Link Here
745
            - pref: HoldRatioDefault
745
            - pref: HoldRatioDefault
746
              class: integer
746
              class: integer
747
            - "."
747
            - "."
748
        -
749
            - pref: RevertLostBibLevelHolds
750
              choices:
751
                  1: Revert
752
                  0: "Don't revert"
753
            - waiting status of a hold if the allocated item is marked as Lost.
754
        -
755
            - pref: SendLostHoldNotices
756
              choices:
757
                  yes: Send
758
                  no: "Don't send"
759
            - a notice to a borrower if their reserved and waiting item is marked as Lost.
748
        -
760
        -
749
            - In the staff interface, split the holds queue into separate tables by
761
            - In the staff interface, split the holds queue into separate tables by
750
            - pref: HoldsSplitQueue
762
            - pref: HoldsSplitQueue
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt (+12 lines)
Lines 119-124 Link Here
119
                                    Barcode [% ITEM_DAT.barcode | html %]  [% IF not_for_loan %][% not_for_loan_description | html %] [% END %]
119
                                    Barcode [% ITEM_DAT.barcode | html %]  [% IF not_for_loan %][% not_for_loan_description | html %] [% END %]
120
                                </h3>
120
                                </h3>
121
121
122
                                [% IF ITEM_DAT.itemlost and ITEM_DAT.waiting_holds > 0  %]
123
                                    <div class="dialog alert">
124
                                        This item has a waiting item-level hold on it, and has been marked as lost.<br>
125
                                        <form action="updateitem.pl" method="post" class="inline">
126
                                            <input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]">
127
                                            <input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]">
128
                                            <button type="submit" name="reverthold" value="1" class="btn btn-default"><i class="fa fa-undo"></i> Revert waiting status</button>
129
                                            <button type="submit" name="cancelhold" value="1" class="btn btn-default"><i class="fa fa-times"></i> Cancel hold</button>
130
                                        </form>
131
                                    </div>
132
                                [% END %]
133
122
                                <h4>
134
                                <h4>
123
                                    Item information
135
                                    Item information
124
                                    [% UNLESS ( ITEM_DAT.nomod ) %]
136
                                    [% UNLESS ( ITEM_DAT.nomod ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/additem.tt (+19 lines)
Lines 87-92 Link Here
87
[% IF last_item_for_hold %]<div class="dialog alert"><strong>Cannot delete</strong>: Last item for bibliographic record with biblio-level hold on it.</div>[% END %]
87
[% IF last_item_for_hold %]<div class="dialog alert"><strong>Cannot delete</strong>: Last item for bibliographic record with biblio-level hold on it.</div>[% END %]
88
[% IF item_not_found %]<div class="dialog alert"><strong>Cannot delete</strong>: Item not found.</div>[% END %]
88
[% IF item_not_found %]<div class="dialog alert"><strong>Cannot delete</strong>: Item not found.</div>[% END %]
89
89
90
[% IF waitinglostitems %]
91
    <div class="dialog alert">
92
        The following item(s) have a waiting item-level hold and have been marked as lost.
93
        <ul>
94
        [% FOREACH i IN waitinglostitems %]
95
            <br>
96
            <li>Item (<i>[% i.barcode | html %]</i>)
97
            <form action="../catalogue/updateitem.pl" method="post" class="inline">
98
                <input type="hidden" name="itemnumber" value="[% i.itemnumber | html %]">
99
                <input type="hidden" name="biblionumber" value="[% i.biblionumber | html %]">
100
                <input type="hidden" name="redirecturl" value="../cataloguing/additem.pl?biblionumber=">
101
                <button type="submit" name="reverthold" value="1" class="btn btn-default"><i class="fa fa-undo"></i> Revert waiting status</button>
102
                <button type="submit" name="cancelhold" value="1" class="btn btn-default"><i class="fa fa-times"></i> Cancel hold</button></li>
103
            </form>
104
        [% END %]
105
        </ul>
106
    </div>
107
[% END %]
108
90
<div id="cataloguing_additem_itemlist">
109
<div id="cataloguing_additem_itemlist">
91
    [% IF items %]
110
    [% IF items %]
92
        [% SET date_fields = [ 'dateaccessioned', 'onloan', 'datelastseen', 'datelastborrowed', 'replacementpricedate' ] %]
111
        [% SET date_fields = [ 'dateaccessioned', 'onloan', 'datelastseen', 'datelastborrowed', 'replacementpricedate' ] %]
(-)a/t/db_dependent/Reserves.t (-2 / +156 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 77;
20
use Test::More tests => 78;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 1419-1424 subtest 'ModReserveAffect logging' => sub { Link Here
1419
    like( $log->info, qr{$expected}, 'Timestamp logged is the current one' );
1419
    like( $log->info, qr{$expected}, 'Timestamp logged is the current one' );
1420
};
1420
};
1421
1421
1422
subtest 'Waiting item is marked as lost' => sub {
1423
1424
    plan tests => 17;
1425
1426
    # Set up data
1427
    my $biblio = $builder->build_sample_biblio();
1428
    my $item   = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
1429
    my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
1430
    t::lib::Mocks::mock_preference( 'SendLostHoldNotices', 0 );
1431
    my $original_notice_count = Koha::Notice::Messages->search( { letter_code => "LOST_WAITING_HOLD" } )->count;
1432
    ## TEST 1: BIBLIO-LEVEL HOLD
1433
1434
    # place biblio-level hold
1435
    my $reserve_id = AddReserve(
1436
        {
1437
            branchcode     => $item->homebranch,
1438
            borrowernumber => $patron->borrowernumber,
1439
            biblionumber   => $biblio->biblionumber,
1440
        }
1441
    );
1442
    my $hold = Koha::Holds->find($reserve_id);
1443
1444
    $dbh->do(
1445
        q{INSERT IGNORE INTO letter (module, code, branchcode, name, is_html, title, message_transport_type, content) VALUES ('reserves','LOST_WAITING_HOLD','','Waiting hold marked lost','0','Your waiting hold has been marked lost','email',"Dear [% borrower.firstname %] [% borrowers.surname %],<br><br>Your hold awaiting pickup is no longer available. The item is lost.<br><br>Please contact the library for more information.<br><br>Thank you,<br><br>[% branch.branchname %]") }
1446
    );
1447
1448
    is( $hold->item_level_hold, 0, 'Biblio-level hold placed' );
1449
1450
    # set hold as waiting and assign item
1451
    $hold->set( { itemnumber => $item->itemnumber } )->store;
1452
    $hold->set_waiting;
1453
1454
    # mark item in biblio as lost
1455
    $item->itemlost(1)->store;
1456
    is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' );
1457
1458
    # do test
1459
    t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 );
1460
    C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } );
1461
    is(
1462
        $hold->found, 'W',
1463
        'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled'
1464
    );
1465
1466
    # enable preference
1467
    t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 );
1468
1469
    # try again
1470
    is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' );
1471
    C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } );
1472
    $hold = Koha::Holds->find($reserve_id);
1473
    is( $hold->found, undef, 'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled' );
1474
1475
    # clean up
1476
    $hold->cancel;
1477
    $item->itemlost(0);
1478
1479
    ## TEST 2: ITEM-LEVEL HOLD, REVERT
1480
1481
    # place item-level hold
1482
    $reserve_id = AddReserve(
1483
        {
1484
            branchcode     => $item->homebranch,
1485
            borrowernumber => $patron->borrowernumber,
1486
            biblionumber   => $biblio->biblionumber,
1487
            itemnumber     => $item->itemnumber
1488
        }
1489
    );
1490
    $hold = Koha::Holds->find($reserve_id);
1491
1492
    is( $hold->item_level_hold, 1, 'Item-level hold placed' );
1493
1494
    # set hold as waiting and assign item
1495
    $hold->set_waiting;
1496
    $hold->set( { itemnumber => $item->itemnumber, priority => 0 } )->store;
1497
1498
    # mark item in biblio as lost
1499
    $item->itemlost(1);
1500
    is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' );
1501
1502
    # do test
1503
    t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 );
1504
    C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } );
1505
    is(
1506
        $hold->found, 'W',
1507
        'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled'
1508
    );
1509
1510
    # enable preference
1511
    t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 );
1512
1513
    # try again
1514
    is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' );
1515
    C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 0 } );
1516
    $hold = Koha::Holds->find($reserve_id);
1517
    is(
1518
        $hold->found, undef,
1519
        'Hold waiting status has been reverted because RevertLostBibLevelHolds is enabled, and we chose not to cancel'
1520
    );
1521
1522
    # clean up
1523
    $hold->cancel;
1524
    $item->itemlost(0);
1525
1526
    my $current_notice_count = Koha::Notice::Messages->search( { letter_code => "LOST_WAITING_HOLD" } )->count;
1527
    is( $current_notice_count, $original_notice_count, 'No notices enqueued because SendLostHoldNotices disabled' );
1528
1529
    # TEST 3: ITEM-LEVEL HOLD, CANCEL
1530
    t::lib::Mocks::mock_preference( 'SendLostHoldNotices', 1 );
1531
1532
    # place item-level hold
1533
    $reserve_id = AddReserve(
1534
        {
1535
            branchcode     => $item->homebranch,
1536
            borrowernumber => $patron->borrowernumber,
1537
            biblionumber   => $biblio->biblionumber,
1538
            itemnumber     => $item->itemnumber
1539
        }
1540
    );
1541
    $hold = Koha::Holds->find($reserve_id);
1542
1543
    is( $hold->item_level_hold, 1, 'Item-level hold placed' );
1544
1545
    # set hold as waiting and assign item
1546
    $hold->set_waiting;
1547
    $hold->set( { itemnumber => $item->itemnumber, priority => 0 } )->store;
1548
1549
    # mark item in biblio as lost
1550
    $item->itemlost(1);
1551
    is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' );
1552
1553
    # do test
1554
    t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 0 );
1555
    C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 } );
1556
    is(
1557
        $hold->found, 'W',
1558
        'Hold is still waiting even though the item is lost because RevertLostBibLevelHolds is disabled'
1559
    );
1560
1561
    # enable preference
1562
    t::lib::Mocks::mock_preference( 'RevertLostBibLevelHolds', 1 );
1563
1564
    # try again
1565
    is( $item->itemlost, 1, 'Item assigned to waiting hold has been marked lost' );
1566
    C4::Circulation::LostItem( $item->itemnumber, 'test', 0, { cancel_reserve => 1 } );
1567
    $hold = Koha::Holds->find($reserve_id);
1568
    is( Koha::Holds->find($reserve_id), undef, 'Hold has been cancelled with RevertLostBibLevelHolds enabled' );
1569
1570
    $current_notice_count = Koha::Notice::Messages->search( { letter_code => "LOST_WAITING_HOLD" } )->count;
1571
    is(
1572
        $current_notice_count, $original_notice_count + 2,
1573
        'LOST_WAITING_HOLD notice enqueued with each call to LostItem'
1574
    );
1575
};
1576
1422
sub count_hold_print_messages {
1577
sub count_hold_print_messages {
1423
    my $message_count = $dbh->selectall_arrayref(q{
1578
    my $message_count = $dbh->selectall_arrayref(q{
1424
        SELECT COUNT(*)
1579
        SELECT COUNT(*)
1425
- 

Return to bug 20844