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

(-)a/C4/Circulation.pm (-11 / +11 lines)
Lines 2484-2489 sub MarkIssueReturned { Link Here
2484
2484
2485
    # Retrieve the issue
2485
    # Retrieve the issue
2486
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2486
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2487
    my $issue_branchcode = $issue->branchcode;
2487
2488
2488
    return unless $issue->borrowernumber == $borrowernumber; # If the item is checked out to another patron we do not return it
2489
    return unless $issue->borrowernumber == $borrowernumber; # If the item is checked out to another patron we do not return it
2489
2490
Lines 2530-2547 sub MarkIssueReturned { Link Here
2530
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2531
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2531
        # to make sure it will not cause any side effects elsewhere, since this
2532
        # to make sure it will not cause any side effects elsewhere, since this
2532
        # is only relevant for removal of debarments.
2533
        # is only relevant for removal of debarments.
2533
        my $has_overdue_ignore_unrestricted = 0;
2534
        my $has_overdue_ignore_unrestricted = C4::Context->preference('AutoRemoveOverduesRestrictions') eq 'when_no_overdue_causing_debarment';
2534
        if(C4::Context->preference('ODueDebarmentRemovalAllowUnrestricted')) {
2535
            $has_overdue_ignore_unrestricted = 1;
2536
        }
2537
2535
2538
        # Remove any OVERDUES related debarment if the borrower has no overdues
2536
        # Possibly remove any OVERDUES related debarment
2539
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
2537
        if (
2540
          && $patron->debarred
2538
            C4::Context->preference('AutoRemoveOverduesRestrictions') ne 'no'
2541
          && !$patron->has_overdues({
2539
            && $patron->debarred
2542
              ignore_unrestricted => $has_overdue_ignore_unrestricted,
2540
            && !$patron->has_overdues({
2543
              issue_branch => $issue->{'branchcode'} })
2541
                    ignore_unrestricted => $has_overdue_ignore_unrestricted,
2544
          && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2542
                    issue_branchcode => $issue_branchcode
2543
                })
2544
            && @{ GetDebarments({ borrowernumber => $borrowernumber, type => 'OVERDUES' }) }
2545
        ) {
2545
        ) {
2546
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2546
            DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
2547
        }
2547
        }
(-)a/Koha/Patron.pm (-2 / +2 lines)
Lines 1002-1012 sub _get_overdue_restrict_delay { Link Here
1002
1002
1003
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1003
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1004
1004
1005
    my $rqoverduerules =  $dbh->prepare($query);
1005
    my $rqoverduerules = $dbh->prepare($query);
1006
    $rqoverduerules->execute($branchcode, $categorycode);
1006
    $rqoverduerules->execute($branchcode, $categorycode);
1007
1007
1008
    # We get default rules if there is no rule for this branch
1008
    # We get default rules if there is no rule for this branch
1009
    if($rqoverduerules->rows == 0){
1009
    if($rqoverduerules->rows == 0) {
1010
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1010
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1011
1011
1012
        $rqoverduerules = $dbh->prepare($query);
1012
        $rqoverduerules = $dbh->prepare($query);
(-)a/installer/data/mysql/atomicupdate/bug_29145-modify_AutoRemoveOverduesRestrictions-syspref.pl (+13 lines)
Line 0 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "",
5
    description => "Change type of AutoRemoveOverduesRestrictions system preference",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        # Do you stuffs here
10
        $dbh->do(q{UPDATE `systempreferences` SET `type` = 'Choice', `options` = 'no|when_no_overdue|when_no_overdue_causing_debarment', `explanation` = 'Defines if and on what conditions OVERDUES debarments should automatically be lifted when overdue items are returned by the patron.', `value` = CASE `value` WHEN '1' THEN 'when_no_overdue' WHEN '0' THEN 'no' ELSE `value` END WHERE variable = 'AutoRemoveOverduesRestrictions'});
11
        say $out "Type of AutoRemoveOverduesRestrictions system prefernce has ben changed";
12
    },
13
}
(-)a/installer/data/mysql/atomicupdate/odue-debarment-removal-allow-unrestricted.pl (-14 lines)
Lines 1-14 Link Here
1
use Modern::Perl;
2
3
return {
4
    bug_number => "",
5
    description => "Add system preference",
6
    up => sub {
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
9
        # Do you stuffs here
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('ODueDebarmentRemovalAllowUnrestricted', '0', null, 'Allow removal of OVERDUES debarment when overdues still exist, but has not reached restricting delay', 'YesNo')});
11
        # Print useful stuff here
12
        say $out "System preference added";
13
    },
14
}
(-)a/installer/data/mysql/mandatory/sysprefs.sql (-1 / +1 lines)
Lines 83-89 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
83
('AutomaticItemReturn','1',NULL,'If ON, Koha will automatically set up a transfer of this item to its homebranch','YesNo'),
83
('AutomaticItemReturn','1',NULL,'If ON, Koha will automatically set up a transfer of this item to its homebranch','YesNo'),
84
('AutoLinkBiblios','0',NULL,'If enabled, link biblio to authorities on creation and edit','YesNo'),
84
('AutoLinkBiblios','0',NULL,'If enabled, link biblio to authorities on creation and edit','YesNo'),
85
('autoMemberNum','0','','If ON, patron number is auto-calculated','YesNo'),
85
('autoMemberNum','0','','If ON, patron number is auto-calculated','YesNo'),
86
('AutoRemoveOverduesRestrictions','0',NULL,'Defines whether an OVERDUES debarment should be lifted automatically if all overdue items are returned by the patron.','YesNo'),
86
('AutoRemoveOverduesRestrictions','no','no|when_no_overdue|when_no_overdue_causing_debarment', 'Defines if and on what conditions OVERDUES debarments should automatically be lifted when overdue items are returned by the patron.','Choice'),
87
('AutoRenewalNotices','cron','cron|preferences|never','How should Koha determine whether to end autorenewal notices','Choice'),
87
('AutoRenewalNotices','cron','cron|preferences|never','How should Koha determine whether to end autorenewal notices','Choice'),
88
('AutoResumeSuspendedHolds','1',NULL,'Allow suspended holds to be automatically resumed by a set date.','YesNo'),
88
('AutoResumeSuspendedHolds','1',NULL,'Allow suspended holds to be automatically resumed by a set date.','YesNo'),
89
('AutoReturnCheckedOutItems', '0', '', 'If disabled, librarian must confirm return of checked out item when checking out to another.', 'YesNo'),
89
('AutoReturnCheckedOutItems', '0', '', 'If disabled, librarian must confirm return of checked out item when checking out to another.', 'YesNo'),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref (-9 / +6 lines)
Lines 662-673 Circulation: Link Here
662
                  1: Store
662
                  1: Store
663
                  0: "Don't store"
663
                  0: "Don't store"
664
            - 'the last patron to return an item. This setting is independent of the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=opacreadinghistory">opacreadinghistory</a> and <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AnonymousPatron">AnonymousPatron</a> system preferences.'
664
            - 'the last patron to return an item. This setting is independent of the <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=opacreadinghistory">opacreadinghistory</a> and <a href="/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AnonymousPatron">AnonymousPatron</a> system preferences.'
665
        -
666
            - pref: ODueDebarmentRemovalAllowUnrestricted
667
              choices:
668
                  yes: Allow
669
                  no: Do not allow
670
            - removal of Overdue debarments when patron has overdue items but none are old enough to have reached restricting delay. Used in combination with AutoRemoveOverduesRestrictions.
671
    Holds policy:
665
    Holds policy:
672
        -
666
        -
673
            - pref: EnableItemGroups
667
            - pref: EnableItemGroups
Lines 987-997 Circulation: Link Here
987
                  0: "Don't cumulate"
981
                  0: "Don't cumulate"
988
            - the restriction periods.
982
            - the restriction periods.
989
        -
983
        -
984
            - When returning items
990
            - pref: AutoRemoveOverduesRestrictions
985
            - pref: AutoRemoveOverduesRestrictions
986
              type: choice
991
              choices:
987
              choices:
992
                  1: "Do"
988
                  when_no_overdue: "if patron has no remaining overdue items"
993
                  0: "Don't"
989
                  when_no_overdue_causing_debarment: "if patron has no remaining items that is cause for debarment"
994
            - allow OVERDUES restrictions triggered by sent notices to be cleared automatically when all overdue items are returned by a patron.
990
                  no: "don't"
991
            - remove OVERDUES restriction triggered by sent notices. The difference between removing restriction when no remaining overdue items exists and doing so only when any of the items would result in debarment is that the latter option will respect possible grace periods of overdue rules also on returns and not only when generating overdue notices.
995
        -
992
        -
996
            - If a patron is restricted,
993
            - If a patron is restricted,
997
            - pref: RestrictionBlockRenewing
994
            - pref: RestrictionBlockRenewing
(-)a/t/db_dependent/Circulation/MarkIssueReturned.t (-7 / +83 lines)
Lines 173-192 subtest 'Manually pass a return date' => sub { Link Here
173
};
173
};
174
174
175
subtest 'AutoRemoveOverduesRestrictions' => sub {
175
subtest 'AutoRemoveOverduesRestrictions' => sub {
176
    plan tests => 2;
176
    plan tests => 5;
177
177
178
    $schema->storage->txn_begin;
178
    $schema->storage->txn_begin;
179
179
180
    t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 1);
180
    my $dbh = C4::Context->dbh;
181
182
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
181
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
183
    t::lib::Mocks::mock_userenv( { branchcode => $patron->branchcode } );
182
    my $categorycode = $patron->categorycode;
183
    my $branchcode = $patron->branchcode;
184
185
    $dbh->do(qq{
186
        INSERT INTO `overduerules` (
187
            `categorycode`,
188
            `delay1`,
189
            `letter1`,
190
            `debarred1`,
191
            `delay2`,
192
            `letter2`,
193
            `debarred2`
194
        )
195
        VALUES ('$categorycode', 6, 'ODUE', 0, 10, 'ODUE2', 1)
196
    });
197
198
    t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 'when_no_overdue');
199
200
    t::lib::Mocks::mock_userenv( { branchcode => $branchcode } );
184
    my $item_1 = $builder->build_sample_item;
201
    my $item_1 = $builder->build_sample_item;
185
    my $item_2 = $builder->build_sample_item;
202
    my $item_2 = $builder->build_sample_item;
186
    my $item_3 = $builder->build_sample_item;
203
    my $item_3 = $builder->build_sample_item;
187
    my $five_days_ago = dt_from_string->subtract( days => 5 );
204
    my $five_days_ago = dt_from_string->subtract( days => 5 );
188
    my $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # overdue
205
    my $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $five_days_ago ); # overdue, but would not trigger debarment
189
    my $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue
206
    my $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue, but would not trigger debarment
190
    my $checkout_3 = AddIssue( $patron->unblessed, $item_3->barcode ); # not overdue
207
    my $checkout_3 = AddIssue( $patron->unblessed, $item_3->barcode ); # not overdue
191
208
192
    Koha::Patron::Debarments::AddUniqueDebarment(
209
    Koha::Patron::Debarments::AddUniqueDebarment(
Lines 207-211 subtest 'AutoRemoveOverduesRestrictions' => sub { Link Here
207
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
224
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
208
    is( scalar @$debarments, 0, 'OVERDUES debarment is removed if patron does not have overdues' );
225
    is( scalar @$debarments, 0, 'OVERDUES debarment is removed if patron does not have overdues' );
209
226
227
    t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 'when_no_overdue_causing_debarment');
228
229
    my $eleven_days_ago = dt_from_string->subtract( days => 11 );
230
231
    $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $eleven_days_ago ); # overdue and would trigger debarment
232
    $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue, but would not trigger debarment
233
234
    Koha::Patron::Debarments::AddUniqueDebarment(
235
        {
236
            borrowernumber => $patron->borrowernumber,
237
            type           => 'OVERDUES',
238
            comment => "OVERDUES_PROCESS simulation",
239
        }
240
    );
241
242
    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber );
243
244
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
245
    is( scalar @$debarments, 0, 'OVERDUES debarment is removed if remaning items would not result in patron debarment' );
246
247
    $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $eleven_days_ago ); # overdue and would trigger debarment
248
249
    Koha::Patron::Debarments::AddUniqueDebarment(
250
        {
251
            borrowernumber => $patron->borrowernumber,
252
            type           => 'OVERDUES',
253
            comment => "OVERDUES_PROCESS simulation",
254
        }
255
    );
256
257
    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber );
258
259
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
260
    is( $debarments->[0]->{type}, 'OVERDUES', 'OVERDUES debarment is not removed if patron still has overdues that would trigger debarment' );
261
262
    my $thirteen_days_ago = dt_from_string->subtract( days => 13 );
263
264
    # overdue and would trigger debarment
265
    $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $thirteen_days_ago );
266
267
    # $chechout_1 should now not trigger debarment with this new rule for specific branchcode
268
    $dbh->do(qq{
269
        INSERT INTO `overduerules` (
270
            `branchcode`,
271
            `categorycode`,
272
            `delay1`,
273
            `letter1`,
274
            `debarred1`,
275
            `delay2`,
276
            `letter2`,
277
            `debarred2`
278
        )
279
        VALUES ('$branchcode', '$categorycode', 6, 'ODUE', 0, 12, 'ODUE2', 1)
280
    });
281
282
    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber );
283
284
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
285
    is( scalar @$debarments, 0, 'OVERDUES debarment is removed if remaning items would not result in patron debarment' );
286
210
    $schema->storage->txn_rollback;
287
    $schema->storage->txn_rollback;
211
};
288
};
212
- 

Return to bug 29145