View | Details | Raw Unified | Return to bug 22982
Collapse All | Expand All

(-)a/Koha/Account.pm (+1 lines)
Lines 108-113 sub pay { Link Here
108
        $fine->amountoutstanding($new_amountoutstanding)->store();
108
        $fine->amountoutstanding($new_amountoutstanding)->store();
109
        $balance_remaining = $balance_remaining - $amount_to_pay;
109
        $balance_remaining = $balance_remaining - $amount_to_pay;
110
110
111
        # Same logic exists in Koha::Account::Line::apply
111
        if ( $new_amountoutstanding == 0 && $fine->itemnumber && $fine->accounttype && ( $fine->accounttype eq 'L' ) )
112
        if ( $new_amountoutstanding == 0 && $fine->itemnumber && $fine->accounttype && ( $fine->accounttype eq 'L' ) )
112
        {
113
        {
113
            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
114
            C4::Circulation::ReturnLostItem( $self->{patron_id}, $fine->itemnumber );
(-)a/Koha/Account/Line.pm (+10 lines)
Lines 221-226 sub apply { Link Here
221
221
222
            $self->amountoutstanding( $available_credit * -1 )->store;
222
            $self->amountoutstanding( $available_credit * -1 )->store;
223
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
223
            $debit->amountoutstanding( $owed - $amount_to_cancel )->store;
224
225
            # Same logic exists in Koha::Account::pay
226
            if (   $debit->amountoutstanding == 0
227
                && $debit->itemnumber
228
                && $debit->accounttype
229
                && $debit->accounttype eq 'L' )
230
            {
231
                C4::Circulation::ReturnLostItem( $self->borrowernumber, $debit->itemnumber );
232
            }
233
224
        }
234
        }
225
    });
235
    });
226
236
(-)a/t/db_dependent/Koha/Account.t (-2 / +82 lines)
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
};

Return to bug 22982