is( $new_log_size, $old_log_size + 1, 'renew log successfully added' );
is( $new_stats_size, $old_stats_size + 1, 'renew statistic successfully added with passed branch' );
+ AddReturn( $item->id, $library->id, undef, $date );
+ AddIssue( $patron->unblessed, $item->barcode, dt_from_string() );
+ AddRenewal( $patron->id, $item->id, $library->id, undef, undef, 1 );
+ my $lines_skipped = Koha::Account::Lines->search({
+ borrowernumber => $patron->id,
+ itemnumber => $item->id
+ });
+ is( $lines_skipped->count, 5, 'Passing skipfinecalc causes fine calculation on renewal to be skipped' );
+
};
subtest 'ProcessOfflinePayment() tests' => sub {
use Test::MockModule;
use Test::Exception;
+use DateTime;
+
use Koha::Account;
use Koha::Account::Lines;
use Koha::Account::Offsets;
-
+use Koha::DateUtils qw( dt_from_string );
use t::lib::Mocks;
use t::lib::TestBuilder;
$schema->storage->txn_begin;
+ # Disable renewing upon fine payment
+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 0 );
+
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
my $library = $builder->build_object({ class => 'Koha::Libraries' });
my $account = $patron->account;
$schema->storage->txn_rollback;
};
+subtest 'pay() renews items when appropriate' => sub {
+
+ plan tests => 1;
+
+ $schema->storage->txn_begin;
+
+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
+ my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $account = $patron->account;
+
+ my $context = Test::MockModule->new('C4::Context');
+ $context->mock( 'userenv', { branch => $library->id } );
+
+ my $biblio = $builder->build_sample_biblio();
+ my $item =
+ $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
+
+ my $now = dt_from_string();
+ my $seven_weeks = DateTime::Duration->new(weeks => 7);
+ my $five_weeks = DateTime::Duration->new(weeks => 5);
+ my $seven_weeks_ago = $now - $seven_weeks;
+ my $five_weeks_ago = $now - $five_weeks;
+
+ my $checkout = Koha::Checkout->new(
+ {
+ borrowernumber => $patron->id,
+ itemnumber => $item->id,
+ date_due => $five_weeks_ago,
+ branchcode => $patron->branchcode,
+ issuedate => $seven_weeks_ago
+ }
+ )->store();
+
+ my $accountline = Koha::Account::Line->new(
+ {
+ issue_id => $checkout->id,
+ borrowernumber => $patron->id,
+ itemnumber => $item->id,
+ date => \'NOW()',
+ accounttype => 'OVERDUE',
+ status => 'UNRETURNED',
+ interface => 'cli',
+ amount => '1',
+ amountoutstanding => '1',
+ }
+ )->store();
+
+ # Enable renewing upon fine payment
+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
+ my $called = 0;
+ my $module = new Test::MockModule('C4::Circulation');
+ $module->mock('AddRenewal', sub { $called = 1; });
+ $account->pay(
+ {
+ amount => '1',
+ library_id => $library->id,
+ }
+ );
+
+ is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
+
+ $schema->storage->txn_rollback;
+};
+
subtest 'Koha::Account::Line::apply() handles lost items' => sub {
plan tests => 4;
use Test::More tests => 11;
use Test::Exception;
+use Test::MockModule;
+
+use DateTime;
use C4::Circulation qw/AddIssue AddReturn/;
use Koha::Account;
use Koha::Account::Lines;
use Koha::Account::Offsets;
use Koha::Items;
+use Koha::DateUtils qw( dt_from_string );
use t::lib::Mocks;
use t::lib::TestBuilder;
subtest 'apply() tests' => sub {
- plan tests => 24;
+ plan tests => 25;
$schema->storage->txn_begin;
is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
+ my $library = $builder->build_object( { class => 'Koha::Libraries' } );
+ my $biblio = $builder->build_sample_biblio();
+ my $item =
+ $builder->build_sample_item( { biblionumber => $biblio->biblionumber } );
+ my $now = dt_from_string();
+ my $seven_weeks = DateTime::Duration->new(weeks => 7);
+ my $five_weeks = DateTime::Duration->new(weeks => 5);
+ my $seven_weeks_ago = $now - $seven_weeks;
+ my $five_weeks_ago = $now - $five_weeks;
+
+ my $checkout = Koha::Checkout->new(
+ {
+ borrowernumber => $patron->id,
+ itemnumber => $item->id,
+ date_due => $five_weeks_ago,
+ branchcode => $library->id,
+ issuedate => $seven_weeks_ago
+ }
+ )->store();
+
+ my $accountline = Koha::Account::Line->new(
+ {
+ issue_id => $checkout->id,
+ borrowernumber => $patron->id,
+ itemnumber => $item->id,
+ branchcode => $library->id,
+ date => \'NOW()',
+ accounttype => 'OVERDUE',
+ status => 'UNRETURNED',
+ interface => 'cli',
+ amount => '1',
+ amountoutstanding => '1',
+ }
+ )->store();
+
+ # Enable renewing upon fine payment
+ t::lib::Mocks::mock_preference( 'RenewAccruingItemWhenPaid', 1 );
+ my $called = 0;
+ my $module = new Test::MockModule('C4::Circulation');
+ $module->mock('AddRenewal', sub { $called = 1; });
+ my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
+ my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id });
+ $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
+
+ is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
+
$schema->storage->txn_rollback;
};
$patron->delete;
$line = $line->get_from_storage;
- is( $line->borrowernumber, undef, "The account line should not be deleted when the related patron is delete");
+ is( $line->borro1wernumber, undef, "The account line should not be deleted when the related patron is delete");
$register->delete;
$line = $line->get_from_storage;
use Test::More tests => 4;
use Test::Exception;
+use Test::MockModule;
+
+use DateTime;
use Koha::Account;
use Koha::Account::Lines;