Bug 15486: Extend CanItemBeReserved so it handles daily holds limits
This patch implements the required changes in C4::Reserves::CanItemBeReserved so it implements a daily limit on holds. It returns the 'tooManyReservesToday' string if the policy doesn't allow placing the hold. It returns 'OK' (current behaviour) otherwise. To test: - Run: $ sudo koha-shell kohadev k$ cd kohaclone k$ prove t/db_dependent/Holds.t => FAIL: Tests fail because the error condition is not making CanItemBeReserved return the desired error code. - Apply this patch - Run: k$ prove t/db_dependent/Holds.t => SUCCESS: Tests pass! - Sign off :-D Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr> Signed-off-by: Josef Moravec <josef.moravec@gmail.com> Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
This commit is contained in:
parent
dad1324b1b
commit
fb0ab55fd0
|
|
@ -314,10 +314,11 @@ sub CanItemBeReserved {
|
|||
my $ruleitemtype; # itemtype of the matching issuing rule
|
||||
my $allowedreserves = 0; # Total number of holds allowed across all records
|
||||
my $holds_per_record = 1; # Total number of holds allowed for this one given record
|
||||
my $holds_per_day = 0; # Total number of holds allowed per day for the given patron
|
||||
|
||||
# we retrieve borrowers and items informations #
|
||||
# item->{itype} will come for biblioitems if necessery
|
||||
my $item = GetItem($itemnumber);
|
||||
my $item = C4::Items::GetItem($itemnumber);
|
||||
my $biblio = Koha::Biblios->find( $item->{biblionumber} );
|
||||
my $patron = Koha::Patrons->find( $borrowernumber );
|
||||
my $borrower = $patron->unblessed;
|
||||
|
|
@ -364,6 +365,7 @@ sub CanItemBeReserved {
|
|||
$ruleitemtype = $rights->{itemtype};
|
||||
$allowedreserves = $rights->{reservesallowed};
|
||||
$holds_per_record = $rights->{holds_per_record};
|
||||
$holds_per_day = $rights->{holds_per_day};
|
||||
}
|
||||
else {
|
||||
$ruleitemtype = '*';
|
||||
|
|
@ -381,6 +383,18 @@ sub CanItemBeReserved {
|
|||
return { status => "tooManyHoldsForThisRecord", limit => $holds_per_record };
|
||||
}
|
||||
|
||||
my $today_holds = Koha::Holds->search({
|
||||
borrowernumber => $borrowernumber,
|
||||
reservedate => dt_from_string->date
|
||||
});
|
||||
|
||||
if ( defined $holds_per_day &&
|
||||
( ( $holds_per_day > 0 && $today_holds->count() >= $holds_per_day )
|
||||
or ( $holds_per_day == 0 ) )
|
||||
) {
|
||||
return { status => 'tooManyReservesToday', limit => $holds_per_day };
|
||||
}
|
||||
|
||||
# we retrieve count
|
||||
|
||||
$querycount .= "AND $branchfield = ?";
|
||||
|
|
@ -2122,7 +2136,7 @@ sub GetHoldRule {
|
|||
|
||||
my $sth = $dbh->prepare(
|
||||
q{
|
||||
SELECT categorycode, itemtype, branchcode, reservesallowed, holds_per_record
|
||||
SELECT categorycode, itemtype, branchcode, reservesallowed, holds_per_record, holds_per_day
|
||||
FROM issuingrules
|
||||
WHERE (categorycode in (?,'*') )
|
||||
AND (itemtype IN (?,'*'))
|
||||
|
|
|
|||
Loading…
Reference in New Issue