Lines 19-25
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 10; |
22 |
use Test::More tests => 11; |
23 |
use Test::MockModule; |
23 |
use Test::MockModule; |
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
|
25 |
|
Lines 730-732
subtest 'pay() handles lost items when paying by amount ( not specifying the los
Link Here
|
730 |
|
730 |
|
731 |
$schema->storage->txn_rollback; |
731 |
$schema->storage->txn_rollback; |
732 |
}; |
732 |
}; |
733 |
- |
733 |
|
|
|
734 |
subtest 'Koha::Account::Line::apply() handles lost items' => sub { |
735 |
|
736 |
plan tests => 4; |
737 |
|
738 |
$schema->storage->txn_begin; |
739 |
|
740 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
741 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
742 |
my $account = $patron->account; |
743 |
|
744 |
my $context = Test::MockModule->new('C4::Context'); |
745 |
$context->mock( 'userenv', { branch => $library->id } ); |
746 |
|
747 |
my $biblio = $builder->build_sample_biblio(); |
748 |
my $item = |
749 |
$builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
750 |
|
751 |
my $checkout = Koha::Checkout->new( |
752 |
{ |
753 |
borrowernumber => $patron->id, |
754 |
itemnumber => $item->id, |
755 |
date_due => \'NOW()', |
756 |
branchcode => $patron->branchcode, |
757 |
issuedate => \'NOW()', |
758 |
} |
759 |
)->store(); |
760 |
|
761 |
$item->itemlost('1')->store(); |
762 |
|
763 |
my $debit = Koha::Account::Line->new( |
764 |
{ |
765 |
issue_id => $checkout->id, |
766 |
borrowernumber => $patron->id, |
767 |
itemnumber => $item->id, |
768 |
date => \'NOW()', |
769 |
accounttype => 'L', |
770 |
interface => 'cli', |
771 |
amount => '1', |
772 |
amountoutstanding => '1', |
773 |
} |
774 |
)->store(); |
775 |
|
776 |
my $credit = Koha::Account::Line->new( |
777 |
{ |
778 |
borrowernumber => $patron->id, |
779 |
date => '1900-01-01', |
780 |
amount => "-0.500000", |
781 |
amountoutstanding => "-0.500000", |
782 |
interface => 'commandline' |
783 |
} |
784 |
)->store(); |
785 |
my $debits = $account->outstanding_debits; |
786 |
$credit->apply({ debits => $debits }); |
787 |
|
788 |
$debit = Koha::Account::Lines->find( $debit->id ); |
789 |
is( $debit->amountoutstanding, '0.500000', 'Account line was paid down by half' ); |
790 |
|
791 |
$checkout = Koha::Checkouts->find( $checkout->id ); |
792 |
ok( $checkout, 'Item still checked out to patron' ); |
793 |
|
794 |
$credit = Koha::Account::Line->new( |
795 |
{ |
796 |
borrowernumber => $patron->id, |
797 |
date => '1900-01-01', |
798 |
amount => "-0.500000", |
799 |
amountoutstanding => "-0.500000", |
800 |
interface => 'commandline' |
801 |
} |
802 |
)->store(); |
803 |
$debits = $account->outstanding_debits; |
804 |
$credit->apply({ debits => $debits }); |
805 |
|
806 |
$debit = Koha::Account::Lines->find( $debit->id ); |
807 |
is( $debit->amountoutstanding, '0.000000', 'Account line was paid down by half' ); |
808 |
|
809 |
$checkout = Koha::Checkouts->find( $checkout->id ); |
810 |
ok( !$checkout, 'Item was removed from patron account' ); |
811 |
|
812 |
$schema->storage->txn_rollback; |
813 |
}; |