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

(-)a/t/db_dependent/Circulation.t (-19 / +23 lines)
Lines 2005-2011 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2005
2005
2006
    subtest 'Full write-off tests' => sub {
2006
    subtest 'Full write-off tests' => sub {
2007
2007
2008
        plan tests => 10;
2008
        plan tests => 11;
2009
2009
2010
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2010
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2011
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
2011
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
Lines 2039-2047 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2039
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2039
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2040
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2040
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2041
        my $lost_fee_line = $lost_fee_lines->next;
2041
        my $lost_fee_line = $lost_fee_lines->next;
2042
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2042
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2043
        is( $lost_fee_line->amountoutstanding + 0,
2043
        is( $lost_fee_line->amountoutstanding + 0,
2044
            $replacement_amount, 'The right L amountoutstanding is generated' );
2044
            $replacement_amount, 'The right LOST amountoutstanding is generated' );
2045
2045
2046
        my $account = $patron->account;
2046
        my $account = $patron->account;
2047
        my $debts   = $account->outstanding_debits;
2047
        my $debts   = $account->outstanding_debits;
Lines 2060-2073 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2060
        $lost_fee_line->discard_changes; # reload from DB
2060
        $lost_fee_line->discard_changes; # reload from DB
2061
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2061
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2062
        is( $lost_fee_line->accounttype,
2062
        is( $lost_fee_line->accounttype,
2063
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2063
            'LOST', 'Lost fee now still has account type of LOST' );
2064
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2064
2065
2065
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2066
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2066
    };
2067
    };
2067
2068
2068
    subtest 'Full payment tests' => sub {
2069
    subtest 'Full payment tests' => sub {
2069
2070
2070
        plan tests => 12;
2071
        plan tests => 13;
2071
2072
2072
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2073
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2073
2074
Lines 2099-2107 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2099
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2100
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2100
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2101
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2101
        my $lost_fee_line = $lost_fee_lines->next;
2102
        my $lost_fee_line = $lost_fee_lines->next;
2102
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2103
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2103
        is( $lost_fee_line->amountoutstanding + 0,
2104
        is( $lost_fee_line->amountoutstanding + 0,
2104
            $replacement_amount, 'The right L amountountstanding is generated' );
2105
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2105
2106
2106
        my $account = $patron->account;
2107
        my $account = $patron->account;
2107
        my $debts   = $account->outstanding_debits;
2108
        my $debts   = $account->outstanding_debits;
Lines 2126-2132 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2126
        $lost_fee_line->discard_changes;
2127
        $lost_fee_line->discard_changes;
2127
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2128
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2128
        is( $lost_fee_line->accounttype,
2129
        is( $lost_fee_line->accounttype,
2129
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2130
            'LOST', 'Lost fee now still has account type of LOST' );
2131
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2130
2132
2131
        is( $patron->account->balance,
2133
        is( $patron->account->balance,
2132
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
2134
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
Lines 2134-2140 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2134
2136
2135
    subtest 'Test without payment or write off' => sub {
2137
    subtest 'Test without payment or write off' => sub {
2136
2138
2137
        plan tests => 12;
2139
        plan tests => 13;
2138
2140
2139
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2141
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2140
2142
Lines 2167-2175 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2167
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2169
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2168
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2170
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2169
        my $lost_fee_line = $lost_fee_lines->next;
2171
        my $lost_fee_line = $lost_fee_lines->next;
2170
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2172
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2171
        is( $lost_fee_line->amountoutstanding + 0,
2173
        is( $lost_fee_line->amountoutstanding + 0,
2172
            $replacement_amount, 'The right L amountountstanding is generated' );
2174
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2173
2175
2174
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2176
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2175
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2177
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
Lines 2180-2193 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2180
2182
2181
        $lost_fee_line->discard_changes;
2183
        $lost_fee_line->discard_changes;
2182
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2184
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2183
        is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2185
        is( $lost_fee_line->accounttype,
2186
            'LOST', 'Lost fee now still has account type of LOST' );
2187
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2184
2188
2185
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2189
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2186
    };
2190
    };
2187
2191
2188
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2192
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2189
2193
2190
        plan tests => 15;
2194
        plan tests => 16;
2191
2195
2192
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2196
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2193
        my $item = $builder->build_sample_item(
2197
        my $item = $builder->build_sample_item(
Lines 2218-2226 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2218
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2222
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2219
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2223
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2220
        my $lost_fee_line = $lost_fee_lines->next;
2224
        my $lost_fee_line = $lost_fee_lines->next;
2221
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2225
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2222
        is( $lost_fee_line->amountoutstanding + 0,
2226
        is( $lost_fee_line->amountoutstanding + 0,
2223
            $replacement_amount, 'The right L amountountstanding is generated' );
2227
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2224
2228
2225
        my $account = $patron->account;
2229
        my $account = $patron->account;
2226
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
2230
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
Lines 2261-2267 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2261
        $lost_fee_line->discard_changes;
2265
        $lost_fee_line->discard_changes;
2262
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2266
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2263
        is( $lost_fee_line->accounttype,
2267
        is( $lost_fee_line->accounttype,
2264
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2268
            'LOST', 'Lost fee now still has account type of LOST' );
2269
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2265
2270
2266
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2271
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2267
        is( $credit_return->amount + 0,
2272
        is( $credit_return->amount + 0,
Lines 2319-2327 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2319
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2324
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2320
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2325
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2321
        my $lost_fee_line = $lost_fee_lines->next;
2326
        my $lost_fee_line = $lost_fee_lines->next;
2322
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2327
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2323
        is( $lost_fee_line->amountoutstanding + 0,
2328
        is( $lost_fee_line->amountoutstanding + 0,
2324
            $replacement_amount, 'The right L amountountstanding is generated' );
2329
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2325
2330
2326
        my $account = $patron->account;
2331
        my $account = $patron->account;
2327
        is( $account->balance, $replacement_amount, 'Balance is L' );
2332
        is( $account->balance, $replacement_amount, 'Balance is L' );
2328
- 

Return to bug 22563