5 use Test::More tests => 6;
8 use t::lib::TestBuilder;
17 use_ok('C4::Accounts');
20 my $schema = Koha::Database->schema;
21 $schema->storage->txn_begin;
22 my $builder = t::lib::TestBuilder->new;
23 my $dbh = C4::Context->dbh;
25 $dbh->do(q|DELETE FROM accountlines|);
27 t::lib::Mocks::mock_preference('ProcessingFeeNote', 'Test Note');
29 my $library = $builder->build({
32 my $branchcode = $library->{branchcode};
34 my $itemtype = $builder->build({
38 my %item_branch_infos = (
39 homebranch => $branchcode,
40 holdingbranch => $branchcode,
41 itype => $itemtype->{itemtype},
44 my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
45 my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1);
46 my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1);
48 my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
49 my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
51 my $categorycode = $builder->build({
55 my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode);
56 my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed();
58 # Need to mock userenv for AddIssue
59 my $module = new Test::MockModule('C4::Context');
60 $module->mock('userenv', sub { { branch => $branchcode } });
61 AddIssue($borrower, '0101');
62 AddIssue($borrower, '0203');
65 Koha::Account::Offsets->delete();
66 my $issue = Koha::Checkouts->search( { borrowernumber => $borrowernumber } )->next()->unblessed();
67 C4::Accounts::chargelostitem( $borrowernumber, $issue->{itemnumber}, '1.00');
69 my $accountline = Koha::Account::Lines->search( { borrowernumber => $borrowernumber, accounttype => 'PF' } )->next();
71 is( int($accountline->amount), int($itemtype->{processfee}), "The accountline amount should be precessfee value " );
72 is( $accountline->itemnumber, $itemnumber1, "The accountline itemnumber should the linked with barcode '0101'" );
73 is( $accountline->note, C4::Context->preference("ProcessingFeeNote"), "The accountline description should be 'test'" );
75 my $lost_ao = Koha::Account::Offsets->single( { type => 'Lost Item' } );
76 ok( $lost_ao, 'Account offset of type "Lost Item" created' );
78 my $processing_fee_ao = Koha::Account::Offsets->single( { type => 'Processing Fee' } );
79 ok( $processing_fee_ao, 'Account offset of type "Processing Fee" created' );