Lines 21-32
use Modern::Perl;
Link Here
|
21 |
|
21 |
|
22 |
use Test::More tests => 9; |
22 |
use Test::More tests => 9; |
23 |
use Test::Exception; |
23 |
use Test::Exception; |
|
|
24 |
use Test::MockModule; |
25 |
|
26 |
use DateTime; |
24 |
|
27 |
|
25 |
use C4::Circulation qw/AddIssue AddReturn/; |
28 |
use C4::Circulation qw/AddIssue AddReturn/; |
26 |
use Koha::Account; |
29 |
use Koha::Account; |
27 |
use Koha::Account::Lines; |
30 |
use Koha::Account::Lines; |
28 |
use Koha::Account::Offsets; |
31 |
use Koha::Account::Offsets; |
29 |
use Koha::Items; |
32 |
use Koha::Items; |
|
|
33 |
use Koha::DateUtils qw( dt_from_string ); |
30 |
|
34 |
|
31 |
use t::lib::Mocks; |
35 |
use t::lib::Mocks; |
32 |
use t::lib::TestBuilder; |
36 |
use t::lib::TestBuilder; |
Lines 209-215
subtest 'is_credit() and is_debit() tests' => sub {
Link Here
|
209 |
|
213 |
|
210 |
subtest 'apply() tests' => sub { |
214 |
subtest 'apply() tests' => sub { |
211 |
|
215 |
|
212 |
plan tests => 24; |
216 |
plan tests => 25; |
213 |
|
217 |
|
214 |
$schema->storage->txn_begin; |
218 |
$schema->storage->txn_begin; |
215 |
|
219 |
|
Lines 320-325
subtest 'apply() tests' => sub {
Link Here
|
320 |
is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); |
324 |
is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' ); |
321 |
is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); |
325 |
is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' ); |
322 |
|
326 |
|
|
|
327 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
328 |
my $biblio = $builder->build_sample_biblio(); |
329 |
my $item = |
330 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
331 |
my $now = dt_from_string(); |
332 |
my $seven_weeks = DateTime::Duration->new(weeks => 7); |
333 |
my $five_weeks = DateTime::Duration->new(weeks => 5); |
334 |
my $seven_weeks_ago = $now - $seven_weeks; |
335 |
my $five_weeks_ago = $now - $five_weeks; |
336 |
|
337 |
my $checkout = Koha::Checkout->new( |
338 |
{ |
339 |
borrowernumber => $patron->id, |
340 |
itemnumber => $item->id, |
341 |
date_due => $five_weeks_ago, |
342 |
branchcode => $library->id, |
343 |
issuedate => $seven_weeks_ago |
344 |
} |
345 |
)->store(); |
346 |
|
347 |
my $accountline = Koha::Account::Line->new( |
348 |
{ |
349 |
issue_id => $checkout->id, |
350 |
borrowernumber => $patron->id, |
351 |
itemnumber => $item->id, |
352 |
branchcode => $library->id, |
353 |
date => \'NOW()', |
354 |
accounttype => 'OVERDUE', |
355 |
status => 'UNRETURNED', |
356 |
interface => 'cli', |
357 |
amount => '1', |
358 |
amountoutstanding => '1', |
359 |
} |
360 |
)->store(); |
361 |
|
362 |
# Enable renewing upon fine payment |
363 |
t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 ); |
364 |
my $called = 0; |
365 |
my $module = new Test::MockModule('C4::Circulation'); |
366 |
$module->mock('AddRenewal', sub { $called = 1; }); |
367 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
368 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id }); |
369 |
$credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); |
370 |
|
371 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
372 |
|
323 |
$schema->storage->txn_rollback; |
373 |
$schema->storage->txn_rollback; |
324 |
}; |
374 |
}; |
325 |
|
375 |
|
326 |
- |
|
|