Lines 23-29
use Test::More tests => 7;
Link Here
|
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
25 |
use C4::Circulation qw( AddIssue ); |
25 |
use C4::Circulation qw( AddIssue ); |
26 |
use C4::Reserves qw( AddReserve ModReserve ModReserveCancelAll ); |
26 |
use C4::Reserves qw( AddReserve CheckReserves ModReserve ModReserveCancelAll ); |
27 |
use Koha::AuthorisedValueCategory; |
27 |
use Koha::AuthorisedValueCategory; |
28 |
use Koha::Database; |
28 |
use Koha::Database; |
29 |
use Koha::DateUtils qw( dt_from_string ); |
29 |
use Koha::DateUtils qw( dt_from_string ); |
Lines 132-169
subtest 'cancel' => sub {
Link Here
|
132 |
is( $third_hold->discard_changes->priority, 2, 'Third hold should now be second' ); |
132 |
is( $third_hold->discard_changes->priority, 2, 'Third hold should now be second' ); |
133 |
|
133 |
|
134 |
subtest 'charge_cancel_fee parameter' => sub { |
134 |
subtest 'charge_cancel_fee parameter' => sub { |
135 |
plan tests => 4; |
135 |
plan tests => 15; |
136 |
my $patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { reservefee => 0 } } ); |
136 |
my $library1 = $builder->build({ |
137 |
my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $patron_category->categorycode } }); |
137 |
source => 'Branch', |
138 |
is( $patron->account->balance, 0, 'A new patron does not have any charges' ); |
138 |
}); |
|
|
139 |
my $library2 = $builder->build({ |
140 |
source => 'Branch', |
141 |
}); |
142 |
|
143 |
my $bib_title = "Test Title"; |
144 |
|
145 |
my $borrower = $builder->build({ |
146 |
source => 'Borrower', |
147 |
value => { |
148 |
branchcode => $library1->{branchcode}, |
149 |
} |
150 |
}); |
151 |
|
152 |
my $itemtype1 = $builder->build({ |
153 |
source => 'Itemtype', |
154 |
value => {} |
155 |
}); |
156 |
my $itemtype2 = $builder->build({ |
157 |
source => 'Itemtype', |
158 |
value => {} |
159 |
}); |
160 |
my $itemtype3 = $builder->build({ |
161 |
source => 'Itemtype', |
162 |
value => {} |
163 |
}); |
164 |
my $itemtype4 = $builder->build({ |
165 |
source => 'Itemtype', |
166 |
value => {} |
167 |
}); |
168 |
|
169 |
my $borrowernumber = $borrower->{borrowernumber}; |
170 |
|
171 |
my $library_A_code = $library1->{branchcode}; |
172 |
|
173 |
my $biblio = $builder->build_sample_biblio({itemtype => $itemtype1->{itemtype}}); |
174 |
my $biblionumber = $biblio->biblionumber; |
175 |
my $item1 = $builder->build_sample_item({ |
176 |
biblionumber => $biblionumber, |
177 |
itype => $itemtype1->{itemtype}, |
178 |
homebranch => $library_A_code, |
179 |
holdingbranch => $library_A_code |
180 |
}); |
181 |
my $item2 = $builder->build_sample_item({ |
182 |
biblionumber => $biblionumber, |
183 |
itype => $itemtype2->{itemtype}, |
184 |
homebranch => $library_A_code, |
185 |
holdingbranch => $library_A_code |
186 |
}); |
187 |
my $item3 = $builder->build_sample_item({ |
188 |
biblionumber => $biblionumber, |
189 |
itype => $itemtype3->{itemtype}, |
190 |
homebranch => $library_A_code, |
191 |
holdingbranch => $library_A_code |
192 |
}); |
193 |
|
194 |
my $library_B_code = $library2->{branchcode}; |
195 |
|
196 |
my $biblio2 = $builder->build_sample_biblio({itemtype => $itemtype4->{itemtype}}); |
197 |
my $biblionumber2 = $biblio2->biblionumber; |
198 |
my $item4 = $builder->build_sample_item({ |
199 |
biblionumber => $biblionumber2, |
200 |
itype => $itemtype4->{itemtype}, |
201 |
homebranch => $library_B_code, |
202 |
holdingbranch => $library_B_code |
203 |
}); |
204 |
|
205 |
Koha::CirculationRules->set_rules( |
206 |
{ |
207 |
itemtype => undef, |
208 |
categorycode => undef, |
209 |
branchcode => undef, |
210 |
rules => { |
211 |
expire_reserves_charge => undef |
212 |
} |
213 |
} |
214 |
); |
215 |
Koha::CirculationRules->set_rules( |
216 |
{ |
217 |
itemtype => $itemtype1->{itemtype}, |
218 |
categorycode => undef, |
219 |
branchcode => undef, |
220 |
rules => { |
221 |
expire_reserves_charge => '111' |
222 |
} |
223 |
} |
224 |
); |
225 |
Koha::CirculationRules->set_rules( |
226 |
{ |
227 |
itemtype => $itemtype2->{itemtype}, |
228 |
categorycode => undef, |
229 |
branchcode => undef, |
230 |
rules => { |
231 |
expire_reserves_charge => undef |
232 |
} |
233 |
} |
234 |
); |
235 |
Koha::CirculationRules->set_rules( |
236 |
{ |
237 |
itemtype => undef, |
238 |
categorycode => undef, |
239 |
branchcode => $library_B_code, |
240 |
rules => { |
241 |
expire_reserves_charge => '444' |
242 |
} |
243 |
} |
244 |
); |
139 |
|
245 |
|
140 |
my $hold_info = { |
246 |
t::lib::Mocks::mock_preference('ReservesControlBranch', 'ItemHomeLibrary'); |
141 |
branchcode => $library->branchcode, |
247 |
|
142 |
borrowernumber => $patron->borrowernumber, |
248 |
my $reserve_id; |
143 |
biblionumber => $item->biblionumber, |
249 |
my $account; |
144 |
priority => 1, |
250 |
my $status; |
145 |
title => "title for fee", |
251 |
my $start_balance; |
146 |
itemnumber => $item->itemnumber, |
252 |
|
147 |
}; |
253 |
# TEST: Hold itemtype1 item |
|
|
254 |
$reserve_id = AddReserve( |
255 |
{ |
256 |
branchcode => $library_A_code, |
257 |
borrowernumber => $borrowernumber, |
258 |
biblionumber => $biblionumber, |
259 |
priority => 1, |
260 |
itemnumber => $item1->itemnumber, |
261 |
} |
262 |
); |
263 |
|
264 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
265 |
|
266 |
( $status ) = CheckReserves($item1->id); |
267 |
is( $status, 'Reserved', "Hold for the itemtype1 created" ); |
268 |
|
269 |
$start_balance = $account->balance(); |
270 |
|
271 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
272 |
|
273 |
( $status ) = CheckReserves($item1->id); |
274 |
is( $status, '', "Hold for the itemtype1 cancelled" ); |
275 |
|
276 |
is( $account->balance() - $start_balance, 111, "Used circulation rule for itemtype1" ); |
277 |
|
278 |
# TEST: circulation rule for itemtype2 has 'expire_reserves_charge' set undef, so it should use ExpireReservesMaxPickUpDelayCharge preference |
279 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 222); |
280 |
|
281 |
$reserve_id = AddReserve( |
282 |
{ |
283 |
branchcode => $library_A_code, |
284 |
borrowernumber => $borrowernumber, |
285 |
biblionumber => $biblionumber, |
286 |
priority => 1, |
287 |
itemnumber => $item2->itemnumber, |
288 |
} |
289 |
); |
290 |
|
291 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
292 |
|
293 |
( $status ) = CheckReserves($item2->id); |
294 |
is( $status, 'Reserved', "Hold for the itemtype2 created" ); |
295 |
|
296 |
$start_balance = $account->balance(); |
297 |
|
298 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
299 |
|
300 |
( $status ) = CheckReserves($item2->id); |
301 |
is( $status, '', "Hold for the itemtype2 cancelled" ); |
302 |
|
303 |
is( $account->balance() - $start_balance, 222, "Used ExpireReservesMaxPickUpDelayCharge preference as expire_reserves_charge set to undef" ); |
304 |
|
305 |
# TEST: no circulation rules for itemtype3, it should use ExpireReservesMaxPickUpDelayCharge preference |
306 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 333); |
307 |
|
308 |
$reserve_id = AddReserve( |
309 |
{ |
310 |
branchcode => $library_A_code, |
311 |
borrowernumber => $borrowernumber, |
312 |
biblionumber => $biblionumber, |
313 |
priority => 1, |
314 |
itemnumber => $item3->itemnumber, |
315 |
} |
316 |
); |
317 |
|
318 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
319 |
|
320 |
( $status ) = CheckReserves($item3->id); |
321 |
is( $status, 'Reserved', "Hold for the itemtype3 created" ); |
322 |
|
323 |
$start_balance = $account->balance(); |
324 |
|
325 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
326 |
|
327 |
( $status ) = CheckReserves($item3->id); |
328 |
is( $status, '', "Hold for the itemtype3 cancelled" ); |
329 |
|
330 |
is( $account->balance() - $start_balance, 333, "Used ExpireReservesMaxPickUpDelayCharge preference as there's no circulation rules for itemtype3" ); |
331 |
|
332 |
# TEST: circulation rule for itemtype4 with library_B_code |
333 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 555); |
334 |
|
335 |
$reserve_id = AddReserve( |
336 |
{ |
337 |
branchcode => $library_B_code, |
338 |
borrowernumber => $borrowernumber, |
339 |
biblionumber => $biblionumber2, |
340 |
priority => 1, |
341 |
itemnumber => $item4->itemnumber, |
342 |
} |
343 |
); |
344 |
|
345 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
346 |
|
347 |
( $status ) = CheckReserves($item4->id); |
348 |
is( $status, 'Reserved', "Hold for the itemtype4 created" ); |
349 |
|
350 |
$start_balance = $account->balance(); |
351 |
|
352 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 1 }); |
353 |
|
354 |
( $status ) = CheckReserves($item4->id); |
355 |
is( $status, '', "Hold for the itemtype4 cancelled" ); |
356 |
|
357 |
is( $account->balance() - $start_balance, 444, "Used circulation rule for itemtype4 with library_B_code" ); |
358 |
|
359 |
$reserve_id = AddReserve( |
360 |
{ |
361 |
branchcode => $library_B_code, |
362 |
borrowernumber => $borrowernumber, |
363 |
biblionumber => $biblionumber2, |
364 |
priority => 1, |
365 |
itemnumber => $item4->itemnumber, |
366 |
} |
367 |
); |
368 |
|
369 |
$account = Koha::Account->new({ patron_id => $borrowernumber }); |
370 |
|
371 |
( $status ) = CheckReserves($item4->id); |
372 |
is( $status, 'Reserved', "Hold for the itemtype4 created" ); |
148 |
|
373 |
|
149 |
# First, test cancelling a reserve when there's no charge configured. |
374 |
$start_balance = $account->balance(); |
150 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0); |
|
|
151 |
my $reserve_id = C4::Reserves::AddReserve( $hold_info ); |
152 |
Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } ); |
153 |
is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=0 - The patron should not have been charged' ); |
154 |
|
375 |
|
155 |
# Then, test cancelling a reserve when there's no charge desired. |
376 |
Koha::Holds->find( $reserve_id )->cancel({ charge_cancel_fee => 0 }); |
156 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42); |
|
|
157 |
$reserve_id = C4::Reserves::AddReserve( $hold_info ); |
158 |
Koha::Holds->find( $reserve_id )->cancel(); # charge_cancel_fee => 0 |
159 |
is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=42, but charge_cancel_fee => 0, The patron should not have been charged' ); |
160 |
|
377 |
|
|
|
378 |
( $status ) = CheckReserves($item4->id); |
379 |
is( $status, '', "Hold for the itemtype4 cancelled" ); |
161 |
|
380 |
|
162 |
# Finally, test cancelling a reserve when there's a charge desired and configured. |
381 |
is( $account->balance() - $start_balance, 0, "Patron not charged when charge_cancel_fee is 0" ); |
163 |
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42); |
|
|
164 |
$reserve_id = C4::Reserves::AddReserve( $hold_info ); |
165 |
Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } ); |
166 |
is( int($patron->account->balance), 42, 'ExpireReservesMaxPickUpDelayCharge=42 and charge_cancel_fee => 1, The patron should have been charged!' ); |
167 |
}; |
382 |
}; |
168 |
|
383 |
|
169 |
subtest 'waiting hold' => sub { |
384 |
subtest 'waiting hold' => sub { |
170 |
- |
|
|