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

(-)a/C4/Circulation.pm (-6 / +4 lines)
Lines 2587-2592 sub MarkIssueReturned { Link Here
2587
2587
2588
    # Retrieve the issue
2588
    # Retrieve the issue
2589
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2589
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2590
    my $issue_branchcode = $issue->branchcode;
2590
2591
2591
    return unless $issue->borrowernumber == $borrowernumber; # If the item is checked out to another patron we do not return it
2592
    return unless $issue->borrowernumber == $borrowernumber; # If the item is checked out to another patron we do not return it
2592
2593
Lines 2633-2646 sub MarkIssueReturned { Link Here
2633
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2634
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2634
        # to make sure it will not cause any side effects elsewhere, since this
2635
        # to make sure it will not cause any side effects elsewhere, since this
2635
        # is only relevant for removal of debarments.
2636
        # is only relevant for removal of debarments.
2636
        my $has_overdue_ignore_unrestricted = 0;
2637
        my $has_overdue_ignore_unrestricted = C4::Context->preference('AutoRemoveOverduesRestrictions') eq 'when_no_overdue_causing_debarment';
2637
        if(C4::Context->preference('ODueDebarmentRemovalAllowUnrestricted')) {
2638
            $has_overdue_ignore_unrestricted = 1;
2639
        }
2640
2638
2641
        # Remove any OVERDUES related debarment if the borrower has no overdues
2639
        # Possibly remove any OVERDUES related debarment
2642
        my $overdue_restrictions = $patron->restrictions->search({ type => 'OVERDUES' });
2640
        my $overdue_restrictions = $patron->restrictions->search({ type => 'OVERDUES' });
2643
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
2641
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions' ne 'no')
2644
          && $patron->debarred
2642
          && $patron->debarred
2645
          && $overdue_restrictions->count
2643
          && $overdue_restrictions->count
2646
          && !$patron->has_overdues({
2644
          && !$patron->has_overdues({
(-)a/Koha/Patron.pm (-2 / +2 lines)
Lines 1016-1026 sub _get_overdue_restrict_delay { Link Here
1016
1016
1017
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1017
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1018
1018
1019
    my $rqoverduerules =  $dbh->prepare($query);
1019
    my $rqoverduerules = $dbh->prepare($query);
1020
    $rqoverduerules->execute($branchcode, $categorycode);
1020
    $rqoverduerules->execute($branchcode, $categorycode);
1021
1021
1022
    # We get default rules if there is no rule for this branch
1022
    # We get default rules if there is no rule for this branch
1023
    if($rqoverduerules->rows == 0){
1023
    if($rqoverduerules->rows == 0) {
1024
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1024
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1025
1025
1026
        $rqoverduerules = $dbh->prepare($query);
1026
        $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 86-92 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
86
('AutoLinkBiblios','0',NULL,'If enabled, link biblio to authorities on creation and edit','YesNo'),
86
('AutoLinkBiblios','0',NULL,'If enabled, link biblio to authorities on creation and edit','YesNo'),
87
('AutomaticConfirmTransfer','0',NULL,'Defines whether transfers should be automatically confirmed at checkin if modal dismissed','YesNo'),
87
('AutomaticConfirmTransfer','0',NULL,'Defines whether transfers should be automatically confirmed at checkin if modal dismissed','YesNo'),
88
('autoMemberNum','0','','If ON, patron number is auto-calculated','YesNo'),
88
('autoMemberNum','0','','If ON, patron number is auto-calculated','YesNo'),
89
('AutoRemoveOverduesRestrictions','0',NULL,'Defines whether an OVERDUES debarment should be lifted automatically if all overdue items are returned by the patron.','YesNo'),
89
('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'),
90
('AutoRenewalNotices','cron','cron|preferences|never','How should Koha determine whether to end autorenewal notices','Choice'),
90
('AutoRenewalNotices','cron','cron|preferences|never','How should Koha determine whether to end autorenewal notices','Choice'),
91
('AutoResumeSuspendedHolds','1',NULL,'Allow suspended holds to be automatically resumed by a set date.','YesNo'),
91
('AutoResumeSuspendedHolds','1',NULL,'Allow suspended holds to be automatically resumed by a set date.','YesNo'),
92
('AutoReturnCheckedOutItems', '0', '', 'If disabled, librarian must confirm return of checked out item when checking out to another.', 'YesNo'),
92
('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 658-669 Circulation: Link Here
658
                  1: Store
658
                  1: Store
659
                  0: "Don't store"
659
                  0: "Don't store"
660
            - '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.'
660
            - '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.'
661
        -
662
            - pref: ODueDebarmentRemovalAllowUnrestricted
663
              choices:
664
                  yes: Allow
665
                  no: Do not allow
666
            - removal of Overdue debarments when patron has overdue items but none are old enough to have reached restricting delay. Used in combination with AutoRemoveOverduesRestrictions.
667
    Holds policy:
661
    Holds policy:
668
        -
662
        -
669
            - pref: EnableItemGroups
663
            - pref: EnableItemGroups
Lines 996-1006 Circulation: Link Here
996
                  0: "Don't cumulate"
990
                  0: "Don't cumulate"
997
            - the restriction periods.
991
            - the restriction periods.
998
        -
992
        -
993
            - When returning items
999
            - pref: AutoRemoveOverduesRestrictions
994
            - pref: AutoRemoveOverduesRestrictions
995
              type: choice
1000
              choices:
996
              choices:
1001
                  1: "Do"
997
                  when_no_overdue: "if patron has no remaining overdue items"
1002
                  0: "Don't"
998
                  when_no_overdue_causing_debarment: "if patron has no remaining items that is cause for debarment"
1003
            - allow OVERDUES restrictions triggered by sent notices to be cleared automatically when all overdue items are returned by a patron.
999
                  no: "don't"
1000
            - 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.
1004
        -
1001
        -
1005
            - If a patron is restricted,
1002
            - If a patron is restricted,
1006
            - pref: RestrictionBlockRenewing
1003
            - 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 208-212 subtest 'AutoRemoveOverduesRestrictions' => sub { Link Here
208
    $restrictions = $patron->restrictions;
225
    $restrictions = $patron->restrictions;
209
    is( $restrictions->count, 0, 'OVERDUES debarment is removed if patron does not have overdues' );
226
    is( $restrictions->count, 0, 'OVERDUES debarment is removed if patron does not have overdues' );
210
227
228
    t::lib::Mocks::mock_preference('AutoRemoveOverduesRestrictions', 'when_no_overdue_causing_debarment');
229
230
    my $eleven_days_ago = dt_from_string->subtract( days => 11 );
231
232
    $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $eleven_days_ago ); # overdue and would trigger debarment
233
    $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $five_days_ago ); # overdue, but would not trigger debarment
234
235
    Koha::Patron::Debarments::AddUniqueDebarment(
236
        {
237
            borrowernumber => $patron->borrowernumber,
238
            type           => 'OVERDUES',
239
            comment => "OVERDUES_PROCESS simulation",
240
        }
241
    );
242
243
    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_1->itemnumber );
244
245
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
246
    is( scalar @$debarments, 0, 'OVERDUES debarment is removed if remaning items would not result in patron debarment' );
247
248
    $checkout_1 = AddIssue( $patron->unblessed, $item_1->barcode, $eleven_days_ago ); # overdue and would trigger debarment
249
250
    Koha::Patron::Debarments::AddUniqueDebarment(
251
        {
252
            borrowernumber => $patron->borrowernumber,
253
            type           => 'OVERDUES',
254
            comment => "OVERDUES_PROCESS simulation",
255
        }
256
    );
257
258
    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber );
259
260
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
261
    is( $debarments->[0]->{type}, 'OVERDUES', 'OVERDUES debarment is not removed if patron still has overdues that would trigger debarment' );
262
263
    my $thirteen_days_ago = dt_from_string->subtract( days => 13 );
264
265
    # overdue and would trigger debarment
266
    $checkout_2 = AddIssue( $patron->unblessed, $item_2->barcode, $thirteen_days_ago );
267
268
    # $chechout_1 should now not trigger debarment with this new rule for specific branchcode
269
    $dbh->do(qq{
270
        INSERT INTO `overduerules` (
271
            `branchcode`,
272
            `categorycode`,
273
            `delay1`,
274
            `letter1`,
275
            `debarred1`,
276
            `delay2`,
277
            `letter2`,
278
            `debarred2`
279
        )
280
        VALUES ('$branchcode', '$categorycode', 6, 'ODUE', 0, 12, 'ODUE2', 1)
281
    });
282
283
    C4::Circulation::MarkIssueReturned( $patron->borrowernumber, $item_2->itemnumber );
284
285
    $debarments = Koha::Patron::Debarments::GetDebarments({ borrowernumber => $patron->borrowernumber });
286
    is( scalar @$debarments, 0, 'OVERDUES debarment is removed if remaning items would not result in patron debarment' );
287
211
    $schema->storage->txn_rollback;
288
    $schema->storage->txn_rollback;
212
};
289
};
213
- 

Return to bug 29145