use Modern::Perl;
-use Test::More tests => 2;
+use Test::More tests => 6;
use t::lib::TestBuilder;
use t::lib::Mocks;
-use C4::Accounts qw( manualinvoice );
use C4::Circulation qw( CanBookBeIssued );
+use Koha::Account;
+use Koha::Account::Lines;
+use Koha::Account::Offsets;
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
{
source => 'Item',
value => {
+ biblionumber => $builder->build( { source => 'Biblioitem' } )->{biblionumber},
notforloan => 0,
withdrawn => 0
}
}
);
-my $patron = $builder->build(
+my $patron_category = $builder->build({ source => 'Category', value => { categorycode => 'NOT_X', category_type => 'P', enrolmentfee => 0 } });
+my $patron = $builder->build_object(
{
- source => 'Borrower',
+ class => 'Koha::Patrons',
+ value => {
+ categorycode => $patron_category->{categorycode},
+ }
}
);
my $guarantee = $builder->build(
{
source => 'Borrower',
value => {
- guarantorid => $patron->{borrowernumber},
+ guarantorid => $patron->borrowernumber,
+ categorycode => $patron_category->{categorycode},
}
}
);
t::lib::Mocks::mock_preference( 'NoIssuesChargeGuarantees', '5.00' );
+t::lib::Mocks::mock_preference( 'AllowFineOverride', '' );
my ( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
is( $issuingimpossible->{DEBT_GUARANTEES}, undef, "Patron can check out item" );
-manualinvoice( $guarantee->{borrowernumber}, undef, undef, 'L', 10.00 );
+my $account = Koha::Account->new( { patron_id => $guarantee->{borrowernumber} } );
+$account->add_debit({ amount => 10.00, type => 'lost_item', interface => 'test' });
( $issuingimpossible, $needsconfirmation ) = CanBookBeIssued( $patron, $item->{barcode} );
is( $issuingimpossible->{DEBT_GUARANTEES} + 0, '10.00' + 0, "Patron cannot check out item due to debt for guarantee" );
+my $accountline = Koha::Account::Lines->search({ borrowernumber => $guarantee->{borrowernumber} })->next();
+is( $accountline->amountoutstanding, "10.000000", "Found 10.00 amount outstanding" );
+is( $accountline->accounttype, "LOST", "Account type is LOST" );
+
+my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
+is( $offset->type, 'Lost Item', 'Got correct offset type' );
+is( $offset->amount, '10.000000', 'Got amount of $10.00' );
+
$schema->storage->txn_rollback;