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

(-)a/C4/Circulation.pm (+6 lines)
Lines 2931-2936 sub CanBookBeRenewed { Link Here
2931
2931
2932
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2932
    return ( 0, "auto_renew" ) if $auto_renew eq "ok" && !$override_limit; # 0 if auto-renewal should not succeed
2933
2933
2934
    # Check current article requests on item or biblio level
2935
    if( C4::Context->preference('CheckArticleRequestsOnRenewal') && $item->has_current_article_requests ) {
2936
        # TODO Can be improved. Currently we act like there is a reserve found. Same effect ;)
2937
        return ( 0, "on_reserve" );
2938
    }
2939
2934
    return ( 1, undef );
2940
    return ( 1, undef );
2935
}
2941
}
2936
2942
(-)a/Koha/Item.pm (+46 lines)
Lines 44-49 use Koha::Plugins; Link Here
44
use Koha::Libraries;
44
use Koha::Libraries;
45
use Koha::StockRotationItem;
45
use Koha::StockRotationItem;
46
use Koha::StockRotationRotas;
46
use Koha::StockRotationRotas;
47
use Koha::ArticleRequests;
47
48
48
use base qw(Koha::Object);
49
use base qw(Koha::Object);
49
50
Lines 1196-1201 sub _after_item_action_hooks { Link Here
1196
    );
1197
    );
1197
}
1198
}
1198
1199
1200
=head3 has_current_article_requests
1201
1202
    Checks if an item has current item or biblio level
1203
    requests. For biblio level requests the result depends
1204
    on another item being available.
1205
    Returns true or undef.
1206
1207
=cut
1208
1209
sub has_current_article_requests {
1210
    my ( $self, $params ) = @_;
1211
    return if !C4::Context->preference('ArticleRequests');
1212
1213
    # First check item level requests
1214
    my $rs_1 = Koha::ArticleRequests->search({
1215
        status => { -in => [ 'PENDING', 'PROCESSING' ] },
1216
        itemnumber => $self->id,
1217
    });
1218
    return 1 if $rs_1->count;
1219
1220
    # Now check biblio level requests
1221
    my $rs_2 = Koha::ArticleRequests->search({
1222
        status => { -in => [ 'PENDING', 'PROCESSING' ] },
1223
        itemnumber => undef,
1224
        biblionumber => $self->biblionumber,
1225
    });
1226
    return if !$rs_2->count;
1227
1228
    # Is another item available for biblio level requests?
1229
    # Only one item should be enough.
1230
    # Note: NOT looking at notforloan (yet?)
1231
    my $rs_3 = Koha::Items->search({
1232
        'me.biblionumber' => $self->biblionumber,
1233
        itemlost => 0,
1234
        withdrawn => 0,
1235
        damaged => 0,
1236
        onloan => undef,
1237
        'reserves.found' => undef,
1238
    }, {
1239
        join => 'reserves',
1240
    });
1241
    return 1 if !$rs_3->count;
1242
    return;
1243
}
1244
1199
=head3 _type
1245
=head3 _type
1200
1246
1201
=cut
1247
=cut
(-)a/t/db_dependent/Circulation.t (-1 / +23 lines)
Lines 51-56 use Koha::Subscriptions; Link Here
51
use Koha::Account::Lines;
51
use Koha::Account::Lines;
52
use Koha::Account::Offsets;
52
use Koha::Account::Offsets;
53
use Koha::ActionLogs;
53
use Koha::ActionLogs;
54
use Koha::ArticleRequests;
54
55
55
sub set_userenv {
56
sub set_userenv {
56
    my ( $library ) = @_;
57
    my ( $library ) = @_;
Lines 415-421 subtest "GetIssuingCharges tests" => sub { Link Here
415
416
416
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
417
my ( $reused_itemnumber_1, $reused_itemnumber_2 );
417
subtest "CanBookBeRenewed tests" => sub {
418
subtest "CanBookBeRenewed tests" => sub {
418
    plan tests => 95;
419
    plan tests => 99;
419
420
420
    C4::Context->set_preference('ItemsDeniedRenewal','');
421
    C4::Context->set_preference('ItemsDeniedRenewal','');
421
    # Generate test biblio
422
    # Generate test biblio
Lines 1444-1449 subtest "CanBookBeRenewed tests" => sub { Link Here
1444
            $item_3->itemcallnumber || '' ),
1445
            $item_3->itemcallnumber || '' ),
1445
        "Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber"
1446
        "Account line description must not contain 'Lost Items ', but be title, barcode, itemcallnumber"
1446
    );
1447
    );
1448
1449
    # Optional test on pending article requests
1450
    t::lib::Mocks::mock_preference( 'OverduesBlockRenewing', 'allow' ); # allow again
1451
    t::lib::Mocks::mock_preference( 'CheckArticleRequestsOnRenewal', 0 );
1452
    LostItem( $item_3->itemnumber, 'test', 1 ); # returned again
1453
    AddIssue( $renewing_borrower, $item_3->barcode );
1454
    Koha::CirculationRules->set_rules({
1455
        categorycode => undef, branchcode => undef, itemtype => undef, rules => { renewalsallowed => 10 },
1456
    });
1457
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_3->itemnumber );
1458
    is( $renewokay, 1, 'Renewal possible again' );
1459
    my $artreq1 = $builder->build_object({ class => 'Koha::ArticleRequests',
1460
        value => { borrowernumber => $renewing_borrowernumber, itemnumber => $item_3->itemnumber, biblionumber => $item_3->biblionumber, status => 'PENDING' },
1461
    });
1462
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_3->itemnumber );
1463
    is( $renewokay, 1, 'Renewal still possible, still need to enable pref' );
1464
    t::lib::Mocks::mock_preference( 'CheckArticleRequestsOnRenewal', 1 );
1465
    ( $renewokay, $error ) = CanBookBeRenewed( $renewing_borrowernumber, $item_3->itemnumber );
1466
    is( $renewokay, 0, 'Renewal not possible, pref enabled' );
1467
    is( $error, 'on_reserve', 'Error message currently resembles presence of holds' );
1468
1447
};
1469
};
1448
1470
1449
subtest "GetUpcomingDueIssues" => sub {
1471
subtest "GetUpcomingDueIssues" => sub {
(-)a/t/db_dependent/Koha/Item/has_current_article_requests.t (-1 / +81 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2021 Rijksmuseum
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
use Data::Dumper qw/Dumper/;
22
23
use Test::More tests => 1;
24
25
use t::lib::TestBuilder;
26
use t::lib::Mocks;
27
28
use Koha::Database;
29
use Koha::ArticleRequests;
30
use Koha::DateUtils qw/dt_from_string/;
31
use Koha::Holds;
32
use Koha::Items;
33
use Koha::Patrons;
34
use C4::Circulation ();
35
use C4::Reserves ();
36
37
my $schema  = Koha::Database->new->schema;
38
my $builder = t::lib::TestBuilder->new;
39
40
subtest 'has_current_article_requests' => sub {
41
    plan tests => 8;
42
    $schema->storage->txn_begin;
43
44
    t::lib::Mocks::mock_preference( 'ArticleRequests', 1 );
45
46
    my $item1  = $builder->build_sample_item;
47
    my $patron1 = $builder->build_object({ class => 'Koha::Patrons' });
48
    t::lib::Mocks::mock_userenv({ branchcode => $patron1->branchcode });
49
50
    my $artreq1 = $builder->build_object({ class => 'Koha::ArticleRequests',
51
        value => { borrowernumber => $patron1->borrowernumber, itemnumber => $item1->itemnumber, biblionumber => $item1->biblionumber, status => 'PENDING' },
52
    });
53
    C4::Circulation::AddIssue( $patron1->unblessed, $item1->barcode, dt_from_string() );
54
    is( $item1->has_current_article_requests, 1, 'Expect true for item level request' );
55
56
    $artreq1->status('COMPLETED')->store;
57
    is( $item1->has_current_article_requests, undef, 'Expect false for completed item level request' );
58
59
    $artreq1->itemnumber(undef);
60
    $artreq1->status('PROCESSING')->store;
61
    is( $item1->has_current_article_requests, 1, 'Expect true for biblio level request with no other items' );
62
63
    my $item2 = $builder->build_sample_item;
64
    $item2->biblionumber( $item1->biblionumber )->store;
65
    is( $item1->has_current_article_requests, undef, 'Expect false for biblio level request with another available item' );
66
67
    $item2->damaged(1)->store;
68
    is( $item1->has_current_article_requests, 1, 'Expect true for biblio level request with only another damaged item' );
69
    $item2->damaged(0)->store;
70
    is( $item1->has_current_article_requests, undef, 'Expect false again when clearing damaged status' );
71
72
    C4::Reserves::AddReserve({
73
        branchcode => $patron1->branchcode, borrowernumber => $patron1->borrowernumber, biblionumber => $item2->biblionumber,
74
        priority => 1, itemnumber => $item2->itemnumber,
75
    });
76
    is( $item1->has_current_article_requests, undef, 'Expect false for biblio level request with only another item and a reserve' );
77
    Koha::Holds->search({ itemnumber => $item2->itemnumber })->next->set_waiting;
78
    is( $item1->has_current_article_requests, 1, 'Expect true for biblio level request with only another item on hold and waiting' );
79
80
    $schema->storage->txn_rollback;
81
};

Return to bug 28705