Bug 29145: use overdues restrict delays when removing overdues restriction upon return

How to test:
1) Run tests in t/db_dependent/Circulation/MarkIssueReturned.t

Sponsored by: Gothenburg University Library

Signed-off-by: Michaela <michaela.sieber@kit.edu>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Stefan Berndtsson 2018-02-08 15:54:44 +01:00 committed by Tomas Cohen Arazi
parent f8233f44a5
commit f2d2a7839e
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
5 changed files with 73 additions and 5 deletions

View file

@ -2623,12 +2623,22 @@ sub MarkIssueReturned {
$item->last_returned_by( $patron->borrowernumber )->store;
}
# The reason this is here, and not in Koha::Patron->has_overdues() is
# to make sure it will not cause any side effects elsewhere, since this
# is only relevant for removal of debarments.
my $has_overdue_ignore_unrestricted = 0;
if(C4::Context->preference('ODueDebarmentRemovalAllowUnrestricted')) {
$has_overdue_ignore_unrestricted = 1;
}
# Remove any OVERDUES related debarment if the borrower has no overdues
my $overdue_restrictions = $patron->restrictions->search({ type => 'OVERDUES' });
if ( C4::Context->preference('AutoRemoveOverduesRestrictions')
&& $patron->debarred
&& !$patron->has_overdues
&& $overdue_restrictions->count
&& !$patron->has_overdues({
ignore_unrestricted => $has_overdue_ignore_unrestricted,
issue_branch => $issue->{'branchcode'} })
) {
DelUniqueDebarment({ borrowernumber => $borrowernumber, type => 'OVERDUES' });
}

View file

@ -1008,9 +1008,47 @@ Returns the number of patron's overdues
=cut
sub has_overdues {
my ($self) = @_;
my ($self, $params) = @_;
my $date = dt_from_string();
# If ignoring unrestricted overdues, calculate which delay value for
# overdue messages is set with restrictions. Then only include overdue
# issues older than that date when counting.
if($params->{ignore_unrestricted}) {
my $branchcode = $params->{issue_branchcode};
my $date_offset = _get_overdue_restrict_delay($params->{issue_branchcode}, $self->categorycode());
$date->subtract(days => $date_offset);
}
my $dtf = Koha::Database->new->schema->storage->datetime_parser;
return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( dt_from_string() ) } })->count;
return $self->_result->issues->search({ date_due => { '<' => $dtf->format_datetime( $date )} })->count;
}
# Fetch first delayX value from overduerules where debarredX is set, or 0 for no delay
sub _get_overdue_restrict_delay {
my ($branchcode, $categorycode) = @_;
my $dbh = C4::Context->dbh();
my $query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = ? AND categorycode = ?";
my $rqoverduerules = $dbh->prepare($query);
$rqoverduerules->execute($branchcode, $categorycode);
# We get default rules if there is no rule for this branch
if($rqoverduerules->rows == 0){
$query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' AND categorycode = ?";
$rqoverduerules = $dbh->prepare($query);
$rqoverduerules->execute($categorycode);
}
while ( my $overdue_rules = $rqoverduerules->fetchrow_hashref ) {
return $overdue_rules->{"delay1"} if($overdue_rules->{"debarred1"});
return $overdue_rules->{"delay2"} if($overdue_rules->{"debarred2"});
return $overdue_rules->{"delay3"} if($overdue_rules->{"debarred3"});
}
return 0;
}
=head3 track_login

View file

@ -0,0 +1,14 @@
use Modern::Perl;
return {
bug_number => "",
description => "Add system preference",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
# Do you stuffs here
$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')});
# Print useful stuff here
say $out "System preference added";
},
}

View file

@ -658,6 +658,12 @@ Circulation:
1: Store
0: "Don't store"
- '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.'
-
- pref: ODueDebarmentRemovalAllowUnrestricted
choices:
yes: Allow
no: Do not allow
- removal of Overdue debarments when patron has overdue items but none are old enough to have reached restricting delay. Used in combination with AutoRemoveOverduesRestrictions.
Holds policy:
-
- In the staff interface, split the holds queue into separate tables by

View file

@ -489,8 +489,8 @@ END_SQL
my $rqoverduerules = $dbh->prepare($query);
$rqoverduerules->execute($branchcode, @myborcat, @myborcatout);
# We get default rules is there is no rule for this branch
# We get default rules if there is no rule for this branch
if($rqoverduerules->rows == 0){
$query = "SELECT * FROM overduerules WHERE delay1 IS NOT NULL AND branchcode = '' ";
$query .= " AND categorycode IN (".join( ',' , ('?') x @myborcat ).") " if (@myborcat);