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

(-)a/C4/Circulation.pm (-6 / +4 lines)
Lines 2580-2585 sub MarkIssueReturned { Link Here
2580
2580
2581
    # Retrieve the issue
2581
    # Retrieve the issue
2582
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2582
    my $issue = Koha::Checkouts->find( { itemnumber => $itemnumber } ) or return;
2583
    my $issue_branchcode = $issue->branchcode;
2583
2584
2584
    return unless $issue->borrowernumber == $borrowernumber; # If the item is checked out to another patron we do not return it
2585
    return unless $issue->borrowernumber == $borrowernumber; # If the item is checked out to another patron we do not return it
2585
2586
Lines 2626-2639 sub MarkIssueReturned { Link Here
2626
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2627
        # The reason this is here, and not in Koha::Patron->has_overdues() is
2627
        # to make sure it will not cause any side effects elsewhere, since this
2628
        # to make sure it will not cause any side effects elsewhere, since this
2628
        # is only relevant for removal of debarments.
2629
        # is only relevant for removal of debarments.
2629
        my $has_overdue_ignore_unrestricted = 0;
2630
        my $has_overdue_ignore_unrestricted = C4::Context->preference('AutoRemoveOverduesRestrictions') eq 'when_no_overdue_causing_debarment';
2630
        if(C4::Context->preference('ODueDebarmentRemovalAllowUnrestricted')) {
2631
            $has_overdue_ignore_unrestricted = 1;
2632
        }
2633
2631
2634
        # Remove any OVERDUES related debarment if the borrower has no overdues
2632
        # Possibly remove any OVERDUES related debarment
2635
        my $overdue_restrictions = $patron->restrictions->search({ type => 'OVERDUES' });
2633
        my $overdue_restrictions = $patron->restrictions->search({ type => 'OVERDUES' });
2636
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
2634
        if ( C4::Context->preference('AutoRemoveOverduesRestrictions' ne 'no')
2637
          && $patron->debarred
2635
          && $patron->debarred
2638
          && $overdue_restrictions->count
2636
          && $overdue_restrictions->count
2639
          && !$patron->has_overdues({
2637
          && !$patron->has_overdues({
(-)a/Koha/Patron.pm (-2 / +2 lines)
Lines 1031-1041 sub _get_overdue_restrict_delay { Link Here
1031
1031
1032
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1032
    my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
1033
1033
1034
    my $rqoverduerules =  $dbh->prepare($query);
1034
    my $rqoverduerules = $dbh->prepare($query);
1035
    $rqoverduerules->execute($branchcode, $categorycode);
1035
    $rqoverduerules->execute($branchcode, $categorycode);
1036
1036
1037
    # We get default rules if there is no rule for this branch
1037
    # We get default rules if there is no rule for this branch
1038
    if($rqoverduerules->rows == 0){
1038
    if($rqoverduerules->rows == 0) {
1039
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1039
        $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
1040
1040
1041
        $rqoverduerules = $dbh->prepare($query);
1041
        $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
            - In the staff interface, split the holds queue into separate tables by
663
            - In the staff interface, split the holds queue into separate tables by
Lines 990-1000 Circulation: Link Here
990
                  0: "Don't cumulate"
984
                  0: "Don't cumulate"
991
            - the restriction periods.
985
            - the restriction periods.
992
        -
986
        -
987
            - When returning items
993
            - pref: AutoRemoveOverduesRestrictions
988
            - pref: AutoRemoveOverduesRestrictions
989
              type: choice
994
              choices:
990
              choices:
995
                  1: "Do"
991
                  when_no_overdue: "if patron has no remaining overdue items"
996
                  0: "Don't"
992
                  when_no_overdue_causing_debarment: "if patron has no remaining items that is cause for debarment"
997
            - allow OVERDUES restrictions triggered by sent notices to be cleared automatically when all overdue items are returned by a patron.
993
                  no: "don't"
994
            - 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.
998
        -
995
        -
999
            - If a patron is restricted,
996
            - If a patron is restricted,
1000
            - pref: RestrictionBlockRenewing
997
            - 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, $item_1->barcode, $five_days_ago ); # overdue
205
    my $checkout_1 = AddIssue( $patron, $item_1->barcode, $five_days_ago ); # overdue, but would not trigger debarment
189
    my $checkout_2 = AddIssue( $patron, $item_2->barcode, $five_days_ago ); # overdue
206
    my $checkout_2 = AddIssue( $patron, $item_2->barcode, $five_days_ago ); # overdue, but would not trigger debarment
190
    my $checkout_3 = AddIssue( $patron, $item_3->barcode ); # not overdue
207
    my $checkout_3 = AddIssue( $patron, $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