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