|
Lines 2020-2026
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2020 |
|
2020 |
|
| 2021 |
subtest 'Full write-off tests' => sub { |
2021 |
subtest 'Full write-off tests' => sub { |
| 2022 |
|
2022 |
|
| 2023 |
plan tests => 10; |
2023 |
plan tests => 11; |
| 2024 |
|
2024 |
|
| 2025 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2025 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2026 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
2026 |
my $manager = $builder->build_object({ class => "Koha::Patrons" }); |
|
Lines 2054-2062
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2054 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2054 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
| 2055 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2055 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 2056 |
my $lost_fee_line = $lost_fee_lines->next; |
2056 |
my $lost_fee_line = $lost_fee_lines->next; |
| 2057 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2057 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
| 2058 |
is( $lost_fee_line->amountoutstanding + 0, |
2058 |
is( $lost_fee_line->amountoutstanding + 0, |
| 2059 |
$replacement_amount, 'The right L amountoutstanding is generated' ); |
2059 |
$replacement_amount, 'The right LOST amountoutstanding is generated' ); |
| 2060 |
|
2060 |
|
| 2061 |
my $account = $patron->account; |
2061 |
my $account = $patron->account; |
| 2062 |
my $debts = $account->outstanding_debits; |
2062 |
my $debts = $account->outstanding_debits; |
|
Lines 2076-2089
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2076 |
$lost_fee_line->discard_changes; # reload from DB |
2076 |
$lost_fee_line->discard_changes; # reload from DB |
| 2077 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2077 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2078 |
is( $lost_fee_line->accounttype, |
2078 |
is( $lost_fee_line->accounttype, |
| 2079 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2079 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2080 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
| 2080 |
|
2081 |
|
| 2081 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
2082 |
is( $patron->account->balance, -0, 'The patron balance is 0, everything was written off' ); |
| 2082 |
}; |
2083 |
}; |
| 2083 |
|
2084 |
|
| 2084 |
subtest 'Full payment tests' => sub { |
2085 |
subtest 'Full payment tests' => sub { |
| 2085 |
|
2086 |
|
| 2086 |
plan tests => 12; |
2087 |
plan tests => 13; |
| 2087 |
|
2088 |
|
| 2088 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2089 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2089 |
|
2090 |
|
|
Lines 2115-2123
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2115 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2116 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
| 2116 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2117 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 2117 |
my $lost_fee_line = $lost_fee_lines->next; |
2118 |
my $lost_fee_line = $lost_fee_lines->next; |
| 2118 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2119 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
| 2119 |
is( $lost_fee_line->amountoutstanding + 0, |
2120 |
is( $lost_fee_line->amountoutstanding + 0, |
| 2120 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2121 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
| 2121 |
|
2122 |
|
| 2122 |
my $account = $patron->account; |
2123 |
my $account = $patron->account; |
| 2123 |
my $debts = $account->outstanding_debits; |
2124 |
my $debts = $account->outstanding_debits; |
|
Lines 2143-2149
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2143 |
$lost_fee_line->discard_changes; |
2144 |
$lost_fee_line->discard_changes; |
| 2144 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2145 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2145 |
is( $lost_fee_line->accounttype, |
2146 |
is( $lost_fee_line->accounttype, |
| 2146 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2147 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2148 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
| 2147 |
|
2149 |
|
| 2148 |
is( $patron->account->balance, |
2150 |
is( $patron->account->balance, |
| 2149 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
2151 |
-99, 'The patron balance is -99, a credit that equals the lost fee payment' ); |
|
Lines 2151-2157
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2151 |
|
2153 |
|
| 2152 |
subtest 'Test without payment or write off' => sub { |
2154 |
subtest 'Test without payment or write off' => sub { |
| 2153 |
|
2155 |
|
| 2154 |
plan tests => 12; |
2156 |
plan tests => 13; |
| 2155 |
|
2157 |
|
| 2156 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2158 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2157 |
|
2159 |
|
|
Lines 2184-2192
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2184 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2186 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
| 2185 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2187 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 2186 |
my $lost_fee_line = $lost_fee_lines->next; |
2188 |
my $lost_fee_line = $lost_fee_lines->next; |
| 2187 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2189 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
| 2188 |
is( $lost_fee_line->amountoutstanding + 0, |
2190 |
is( $lost_fee_line->amountoutstanding + 0, |
| 2189 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2191 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
| 2190 |
|
2192 |
|
| 2191 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
2193 |
my $credit_return_id = C4::Circulation::_FixAccountForLostAndReturned( $item->itemnumber, $patron->id ); |
| 2192 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
2194 |
my $credit_return = Koha::Account::Lines->find($credit_return_id); |
|
Lines 2197-2210
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2197 |
|
2199 |
|
| 2198 |
$lost_fee_line->discard_changes; |
2200 |
$lost_fee_line->discard_changes; |
| 2199 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2201 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2200 |
is( $lost_fee_line->accounttype, 'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2202 |
is( $lost_fee_line->accounttype, |
|
|
2203 |
'LOST', 'Lost fee now still has account type of LOST' ); |
| 2204 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
| 2201 |
|
2205 |
|
| 2202 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
2206 |
is( $patron->account->balance, 20, 'The patron balance is 20, still owes the processing fee' ); |
| 2203 |
}; |
2207 |
}; |
| 2204 |
|
2208 |
|
| 2205 |
subtest 'Test with partial payement and write off, and remaining debt' => sub { |
2209 |
subtest 'Test with partial payement and write off, and remaining debt' => sub { |
| 2206 |
|
2210 |
|
| 2207 |
plan tests => 15; |
2211 |
plan tests => 16; |
| 2208 |
|
2212 |
|
| 2209 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
2213 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 2210 |
my $item = $builder->build_sample_item( |
2214 |
my $item = $builder->build_sample_item( |
|
Lines 2235-2243
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2235 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
2239 |
{ borrowernumber => $patron->id, itemnumber => $item->itemnumber, accounttype => 'LOST' } ); |
| 2236 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2240 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 2237 |
my $lost_fee_line = $lost_fee_lines->next; |
2241 |
my $lost_fee_line = $lost_fee_lines->next; |
| 2238 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2242 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
| 2239 |
is( $lost_fee_line->amountoutstanding + 0, |
2243 |
is( $lost_fee_line->amountoutstanding + 0, |
| 2240 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2244 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
| 2241 |
|
2245 |
|
| 2242 |
my $account = $patron->account; |
2246 |
my $account = $patron->account; |
| 2243 |
is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' ); |
2247 |
is( $account->balance, $processfee_amount + $replacement_amount, 'Balance is PF + L' ); |
|
Lines 2280-2286
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2280 |
$lost_fee_line->discard_changes; |
2284 |
$lost_fee_line->discard_changes; |
| 2281 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
2285 |
is( $lost_fee_line->amountoutstanding + 0, 0, 'Lost fee has no outstanding amount' ); |
| 2282 |
is( $lost_fee_line->accounttype, |
2286 |
is( $lost_fee_line->accounttype, |
| 2283 |
'LR', 'Lost fee now has account type of LR ( Lost Returned )' ); |
2287 |
'LOST', 'Lost fee now still has account type of LOST' ); |
|
|
2288 |
is( $lost_fee_line->status, 'RETURNED', "Lost fee now has account status of RETURNED"); |
| 2284 |
|
2289 |
|
| 2285 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
2290 |
is( $credit_return->accounttype, 'CR', 'An account line of type CR is added' ); |
| 2286 |
is( $credit_return->amount + 0, |
2291 |
is( $credit_return->amount + 0, |
|
Lines 2338-2346
subtest '_FixAccountForLostAndReturned' => sub {
Link Here
|
| 2338 |
{ borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } ); |
2343 |
{ borrowernumber => $patron->id, itemnumber => $item_id, accounttype => 'LOST' } ); |
| 2339 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
2344 |
is( $lost_fee_lines->count, 1, 'Only one lost item fee produced' ); |
| 2340 |
my $lost_fee_line = $lost_fee_lines->next; |
2345 |
my $lost_fee_line = $lost_fee_lines->next; |
| 2341 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right L amount is generated' ); |
2346 |
is( $lost_fee_line->amount + 0, $replacement_amount, 'The right LOST amount is generated' ); |
| 2342 |
is( $lost_fee_line->amountoutstanding + 0, |
2347 |
is( $lost_fee_line->amountoutstanding + 0, |
| 2343 |
$replacement_amount, 'The right L amountountstanding is generated' ); |
2348 |
$replacement_amount, 'The right LOST amountountstanding is generated' ); |
| 2344 |
|
2349 |
|
| 2345 |
my $account = $patron->account; |
2350 |
my $account = $patron->account; |
| 2346 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
2351 |
is( $account->balance, $replacement_amount, 'Balance is L' ); |
| 2347 |
- |
|
|