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

(-)a/t/db_dependent/Circulation.t (-19 / +23 lines)
Lines 2007-2013 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2007
2007
2008
    subtest 'Full write-off tests' => sub {
2008
    subtest 'Full write-off tests' => sub {
2009
2009
2010
        plan tests => 10;
2010
        plan tests => 11;
2011
2011
2012
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2012
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2013
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
2013
        my $manager = $builder->build_object({ class => "Koha::Patrons" });
Lines 2041-2049 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2041
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2041
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2042
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2042
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2043
        my $lost_fee_line = $lost_fee_lines->next;
2043
        my $lost_fee_line = $lost_fee_lines->next;
2044
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2044
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2045
        is( $lost_fee_line->amountoutstanding + 0,
2045
        is( $lost_fee_line->amountoutstanding + 0,
2046
            $replacement_amount, 'The right L amountoutstanding is generated' );
2046
            $replacement_amount, 'The right LOST amountoutstanding is generated' );
2047
2047
2048
        my $account = $patron->account;
2048
        my $account = $patron->account;
2049
        my $debts   = $account->outstanding_debits;
2049
        my $debts   = $account->outstanding_debits;
Lines 2063-2076 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2063
        $lost_fee_line->discard_changes; # reload from DB
2063
        $lost_fee_line->discard_changes; # reload from DB
2064
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2064
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2065
        is( $lost_fee_line->accounttype,
2065
        is( $lost_fee_line->accounttype,
2066
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2066
            'LOST', 'Lost fee now still has account type of LOST' );
2067
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2067
2068
2068
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2069
        is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' );
2069
    };
2070
    };
2070
2071
2071
    subtest 'Full payment tests' => sub {
2072
    subtest 'Full payment tests' => sub {
2072
2073
2073
        plan tests => 12;
2074
        plan tests => 13;
2074
2075
2075
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2076
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2076
2077
Lines 2102-2110 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2102
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2103
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2103
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2104
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2104
        my $lost_fee_line = $lost_fee_lines->next;
2105
        my $lost_fee_line = $lost_fee_lines->next;
2105
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2106
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2106
        is( $lost_fee_line->amountoutstanding + 0,
2107
        is( $lost_fee_line->amountoutstanding + 0,
2107
            $replacement_amount, 'The right L amountountstanding is generated' );
2108
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2108
2109
2109
        my $account = $patron->account;
2110
        my $account = $patron->account;
2110
        my $debts   = $account->outstanding_debits;
2111
        my $debts   = $account->outstanding_debits;
Lines 2130-2136 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2130
        $lost_fee_line->discard_changes;
2131
        $lost_fee_line->discard_changes;
2131
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2132
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2132
        is( $lost_fee_line->accounttype,
2133
        is( $lost_fee_line->accounttype,
2133
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2134
            'LOST', 'Lost fee now still has account type of LOST' );
2135
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2134
2136
2135
        is( $patron->account->balance,
2137
        is( $patron->account->balance,
2136
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
2138
            -99, 'The patron balance is -99, a credit that equals the lost fee payment' );
Lines 2138-2144 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2138
2140
2139
    subtest 'Test without payment or write off' => sub {
2141
    subtest 'Test without payment or write off' => sub {
2140
2142
2141
        plan tests => 12;
2143
        plan tests => 13;
2142
2144
2143
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2145
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2144
2146
Lines 2171-2179 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2171
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2173
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2172
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2174
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2173
        my $lost_fee_line = $lost_fee_lines->next;
2175
        my $lost_fee_line = $lost_fee_lines->next;
2174
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2176
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2175
        is( $lost_fee_line->amountoutstanding + 0,
2177
        is( $lost_fee_line->amountoutstanding + 0,
2176
            $replacement_amount, 'The right L amountountstanding is generated' );
2178
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2177
2179
2178
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2180
        my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id );
2179
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
2181
        my $credit_return = Koha::Account::Lines->find($credit_return_id);
Lines 2184-2197 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2184
2186
2185
        $lost_fee_line->discard_changes;
2187
        $lost_fee_line->discard_changes;
2186
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2188
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2187
        is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2189
        is( $lost_fee_line->accounttype,
2190
            'LOST', 'Lost fee now still has account type of LOST' );
2191
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2188
2192
2189
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2193
        is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' );
2190
    };
2194
    };
2191
2195
2192
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2196
    subtest 'Test with partial payement and write off, and remaining debt' => sub {
2193
2197
2194
        plan tests => 15;
2198
        plan tests => 16;
2195
2199
2196
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2200
        my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
2197
        my $item = $builder->build_sample_item(
2201
        my $item = $builder->build_sample_item(
Lines 2222-2230 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2222
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2226
            { borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } );
2223
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2227
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2224
        my $lost_fee_line = $lost_fee_lines->next;
2228
        my $lost_fee_line = $lost_fee_lines->next;
2225
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2229
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2226
        is( $lost_fee_line->amountoutstanding + 0,
2230
        is( $lost_fee_line->amountoutstanding + 0,
2227
            $replacement_amount, 'The right L amountountstanding is generated' );
2231
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2228
2232
2229
        my $account = $patron->account;
2233
        my $account = $patron->account;
2230
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
2234
        is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' );
Lines 2267-2273 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2267
        $lost_fee_line->discard_changes;
2271
        $lost_fee_line->discard_changes;
2268
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2272
        is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' );
2269
        is( $lost_fee_line->accounttype,
2273
        is( $lost_fee_line->accounttype,
2270
            'LR', 'Lost fee now has account type of LR ( Lost Returned )' );
2274
            'LOST', 'Lost fee now still has account type of LOST' );
2275
        is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED");
2271
2276
2272
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2277
        is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' );
2273
        is( $credit_return->amount + 0,
2278
        is( $credit_return->amount + 0,
Lines 2325-2333 subtest '_FixAccountForLostAndReturned' => sub { Link Here
2325
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2330
            { borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } );
2326
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2331
        is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' );
2327
        my $lost_fee_line = $lost_fee_lines->next;
2332
        my $lost_fee_line = $lost_fee_lines->next;
2328
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' );
2333
        is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' );
2329
        is( $lost_fee_line->amountoutstanding + 0,
2334
        is( $lost_fee_line->amountoutstanding + 0,
2330
            $replacement_amount, 'The right L amountountstanding is generated' );
2335
            $replacement_amount, 'The right LOST amountountstanding is generated' );
2331
2336
2332
        my $account = $patron->account;
2337
        my $account = $patron->account;
2333
        is( $account->balance, $replacement_amount, 'Balance is L' );
2338
        is( $account->balance, $replacement_amount, 'Balance is L' );
2334
- 

Return to bug 22563