Lines 88-94
sub add {
Link Here
|
88 |
my $non_priority = $body->{non_priority}; |
88 |
my $non_priority = $body->{non_priority}; |
89 |
|
89 |
|
90 |
my $overrides = $c->stash('koha.overrides'); |
90 |
my $overrides = $c->stash('koha.overrides'); |
91 |
my $can_override = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride'); |
91 |
my $can_override = C4::Context->preference('AllowHoldPolicyOverride') // 0; |
|
|
92 |
|
93 |
my $override_all = $overrides->{any} && C4::Context->preference('AllowHoldPolicyOverride') ? 1 : 0; |
92 |
|
94 |
|
93 |
if ( !C4::Context->preference('AllowHoldDateInFuture') && $hold_date ) { |
95 |
if ( !C4::Context->preference('AllowHoldDateInFuture') && $hold_date ) { |
94 |
return $c->render( |
96 |
return $c->render( |
Lines 142-148
sub add {
Link Here
|
142 |
} |
144 |
} |
143 |
|
145 |
|
144 |
# If the hold is being forced, no need to validate |
146 |
# If the hold is being forced, no need to validate |
145 |
unless ($can_override) { |
147 |
unless ($override_all) { |
146 |
|
148 |
|
147 |
# Validate pickup location |
149 |
# Validate pickup location |
148 |
my $valid_pickup_location; |
150 |
my $valid_pickup_location; |
Lines 161-181
sub add {
Link Here
|
161 |
openapi => { error => 'The supplied pickup location is not valid' } |
163 |
openapi => { error => 'The supplied pickup location is not valid' } |
162 |
) unless $valid_pickup_location; |
164 |
) unless $valid_pickup_location; |
163 |
|
165 |
|
164 |
my $can_place_hold = |
166 |
my $can_place_holds = $patron->can_place_holds(); |
|
|
167 |
|
168 |
if ( !$can_place_holds ) { |
169 |
my $error_code = $can_place_holds->messages->[0]->message; |
170 |
return $c->render( |
171 |
status => 409, |
172 |
openapi => { |
173 |
error => 'Hold cannot be placed. Reason: ' . $error_code, |
174 |
error_code => $error_code, |
175 |
} |
176 |
) unless $overrides->{$error_code}; |
177 |
} |
178 |
|
179 |
my $can_hold_be_placed = |
165 |
$item |
180 |
$item |
166 |
? C4::Reserves::CanItemBeReserved( $patron, $item ) |
181 |
? C4::Reserves::CanItemBeReserved( $patron, $item ) |
167 |
: C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id ); |
182 |
: C4::Reserves::CanBookBeReserved( $patron_id, $biblio_id ); |
168 |
|
183 |
|
169 |
if ( C4::Context->preference('maxreserves') |
184 |
unless ( $can_hold_be_placed->{status} eq 'OK' ) { |
170 |
&& $patron->holds->count + 1 > C4::Context->preference('maxreserves') ) |
|
|
171 |
{ |
172 |
$can_place_hold->{status} = 'tooManyReserves'; |
173 |
} |
174 |
|
175 |
unless ( $can_place_hold->{status} eq 'OK' ) { |
176 |
return $c->render( |
185 |
return $c->render( |
177 |
status => 403, |
186 |
status => 403, |
178 |
openapi => { error => "Hold cannot be placed. Reason: " . $can_place_hold->{status} } |
187 |
openapi => { error => "Hold cannot be placed. Reason: " . $can_hold_be_placed->{status} } |
179 |
); |
188 |
); |
180 |
} |
189 |
} |
181 |
} |
190 |
} |
182 |
- |
|
|