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

(-)a/C4/Circulation.pm (+4 lines)
Lines 2445-2450 sub _FixAccountForLostAndReturned { Link Here
2445
2445
2446
    ModItem( { paidfor => '' }, undef, $itemnumber, { log_action => 0 } );
2446
    ModItem( { paidfor => '' }, undef, $itemnumber, { log_action => 0 } );
2447
2447
2448
    if ( defined $account and C4::Context->preference('AccountAutoReconcile') ) {
2449
        $account->reconcile_balance;
2450
    }
2451
2448
    return ($credit) ? $credit->id : undef;
2452
    return ($credit) ? $credit->id : undef;
2449
}
2453
}
2450
2454
(-)a/t/db_dependent/Circulation.t (-2 / +79 lines)
Lines 25-30 use POSIX qw( floor ); Link Here
25
use t::lib::Mocks;
25
use t::lib::Mocks;
26
use t::lib::TestBuilder;
26
use t::lib::TestBuilder;
27
27
28
use C4::Accounts;
28
use C4::Calendar;
29
use C4::Calendar;
29
use C4::Circulation;
30
use C4::Circulation;
30
use C4::Biblio;
31
use C4::Biblio;
Lines 1992-1998 subtest 'AddReturn | is_overdue' => sub { Link Here
1992
1993
1993
subtest '_FixAccountForLostAndReturned' => sub {
1994
subtest '_FixAccountForLostAndReturned' => sub {
1994
1995
1995
    plan tests => 4;
1996
    plan tests => 5;
1996
1997
1997
    t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
1998
    t::lib::Mocks::mock_preference( 'WhenLostChargeReplacementFee', 1 );
1998
    t::lib::Mocks::mock_preference( 'WhenLostForgiveFine',          0 );
1999
    t::lib::Mocks::mock_preference( 'WhenLostForgiveFine',          0 );
Lines 2296-2301 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2296
            'The patron balance is the difference between the PF and the credit'
2297
            'The patron balance is the difference between the PF and the credit'
2297
        );
2298
        );
2298
    };
2299
    };
2300
2301
    subtest 'Partial payement, existing debits and AccountAutoReconcile' => sub {
2302
2303
        plan tests => 8;
2304
2305
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2306
        my $barcode = 'KD123456793';
2307
        my $replacement_amount = 100;
2308
        my $processfee_amount  = 20;
2309
2310
        my $item_type          = $builder->build_object(
2311
            {   class => 'Koha::ItemTypes',
2312
                value => {
2313
                    notforloan         => undef,
2314
                    rentalcharge       => 0,
2315
                    defaultreplacecost => undef,
2316
                    processfee         => 0
2317
                }
2318
            }
2319
        );
2320
        my ( undef, undef, $item_id ) = AddItem(
2321
            {   homebranch       => $library->branchcode,
2322
                holdingbranch    => $library->branchcode,
2323
                barcode          => $barcode,
2324
                replacementprice => $replacement_amount,
2325
                itype            => $item_type->itemtype
2326
            },
2327
            $biblionumber
2328
        );
2329
2330
        AddIssue( $patron->unblessed, $barcode );
2331
2332
        # Simulate item marked as lost
2333
        ModItem( { itemlost => 1 }, $biblionumber, $item_id );
2334
        LostItem( $item_id, 1 );
2335
2336
        my $lost_fee_lines = Koha::Account::Lines->search(
2337
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'L' } );
2338
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2339
        my $lost_fee_line = $lost_fee_lines->next;
2340
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2341
        is( $lost_fee_line->amountoutstanding + 0,
2342
            $replacement_amount, 'The right L amountountstanding is generated' );
2343
2344
        my $account = $patron->account;
2345
        is( $account->balance, $replacement_amount, 'Balance is L' );
2346
2347
        # Partially pay fee
2348
        my $payment_amount = 27;
2349
        my $payment        = $account->add_credit(
2350
            {   amount => $payment_amount,
2351
                type   => 'payment'
2352
            }
2353
        );
2354
        $payment->apply({ debits => $lost_fee_lines->reset, offset_type => 'Payment' });
2355
2356
        is( $account->balance,
2357
            $replacement_amount - $payment_amount,
2358
            'Payment applied'
2359
        );
2360
2361
        # TODO use add_debit when time comes
2362
        my $manual_debit_amount = 80;
2363
        C4::Accounts::manualinvoice( $patron->id, undef, undef, 'FU', $manual_debit_amount );
2364
2365
        is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' );
2366
2367
        t::lib::Mocks::mock_preference( 'AccountAutoReconcile', 1 );
2368
2369
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item_id, $patron->id );
2370
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2371
2372
        is( $account->balance, $manual_debit_amount - $payment_amount, 'Balance is PF - payment (CR)' );
2373
2374
        my $manual_debit = Koha::Account::Lines->search({ borrowernumber => $patron->id, accounttype => 'FU' })->next;
2375
        is( $manual_debit->amountoutstanding + 0, $manual_debit_amount - $payment_amount, 'reconcile_balance was called' );
2376
    };
2299
};
2377
};
2300
2378
2301
subtest '_FixOverduesOnReturn' => sub {
2379
subtest '_FixOverduesOnReturn' => sub {
2302
- 

Return to bug 21915