|
Lines 208-214
subtest 'apply() tests' => sub {
Link Here
|
| 208 |
$debit_1->discard_changes; |
208 |
$debit_1->discard_changes; |
| 209 |
|
209 |
|
| 210 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
210 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
| 211 |
$credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
211 |
$credit = $credit->apply( { debits => [ $debits->as_list ] } ); |
| 212 |
is( ref($credit), 'Koha::Account::Line', '->apply returns the updated Koha::Account::Line credit object'); |
212 |
is( ref($credit), 'Koha::Account::Line', '->apply returns the updated Koha::Account::Line credit object'); |
| 213 |
is( $credit->amountoutstanding * -1, 90, 'Remaining credit is correctly calculated' ); |
213 |
is( $credit->amountoutstanding * -1, 90, 'Remaining credit is correctly calculated' ); |
| 214 |
|
214 |
|
|
Lines 232-238
subtest 'apply() tests' => sub {
Link Here
|
| 232 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
232 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
| 233 |
$THE_offset = $offsets->next; |
233 |
$THE_offset = $offsets->next; |
| 234 |
is( $THE_offset->amount * 1, -90, 'Amount was calculated correctly (less than the available credit)' ); |
234 |
is( $THE_offset->amount * 1, -90, 'Amount was calculated correctly (less than the available credit)' ); |
| 235 |
is( $THE_offset->type, 'Credit Applied', 'Defaults to \'Credit Applied\' offset type' ); |
235 |
is( $THE_offset->type, 'APPLY', 'Defaults to \'APPLY\' offset type' ); |
| 236 |
|
236 |
|
| 237 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
237 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
| 238 |
throws_ok |
238 |
throws_ok |
|
Lines 266-272
subtest 'apply() tests' => sub {
Link Here
|
| 266 |
|
266 |
|
| 267 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } }); |
267 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } }); |
| 268 |
throws_ok { |
268 |
throws_ok { |
| 269 |
$credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); } |
269 |
$credit_2->apply( { debits => [ $debits->as_list ] } |
| 270 |
'Koha::Exceptions::Account::IsNotDebit', |
270 |
'Koha::Exceptions::Account::IsNotDebit', |
| 271 |
'->apply() rolls back if any of the passed lines is not a debit'; |
271 |
'->apply() rolls back if any of the passed lines is not a debit'; |
| 272 |
|
272 |
|
|
Lines 276-282
subtest 'apply() tests' => sub {
Link Here
|
| 276 |
is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); |
276 |
is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); |
| 277 |
|
277 |
|
| 278 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); |
278 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); |
| 279 |
$credit_2 = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
279 |
$credit_2 = $credit_2->apply( { debits => [ $debits->as_list ] } ); |
| 280 |
|
280 |
|
| 281 |
is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); |
281 |
is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); |
| 282 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
282 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
|
Lines 333-339
subtest 'apply() tests' => sub {
Link Here
|
| 333 |
} |
333 |
} |
| 334 |
); |
334 |
); |
| 335 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
335 |
my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
| 336 |
$credit_forgive = $credit_forgive->apply( { debits => $debits_renew, offset_type => 'Forgiven' } ); |
336 |
$credit_forgive = $credit_forgive->apply( { debits => $debits_renew } ); |
| 337 |
is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' ); |
337 |
is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' ); |
| 338 |
|
338 |
|
| 339 |
$accountline = Koha::Account::Line->new( |
339 |
$accountline = Koha::Account::Line->new( |
|
Lines 352-358
subtest 'apply() tests' => sub {
Link Here
|
| 352 |
)->store(); |
352 |
)->store(); |
| 353 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
353 |
my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' }); |
| 354 |
$debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
354 |
$debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list; |
| 355 |
$credit_renew = $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } ); |
355 |
$credit_renew = $credit_renew->apply( { debits => $debits_renew } ); |
| 356 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
356 |
is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' ); |
| 357 |
|
357 |
|
| 358 |
my @messages = @{$credit_renew->messages}; |
358 |
my @messages = @{$credit_renew->messages}; |
|
Lines 554-560
subtest 'adjust() tests' => sub {
Link Here
|
| 554 |
|
554 |
|
| 555 |
# Update fine to partially paid |
555 |
# Update fine to partially paid |
| 556 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
556 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
| 557 |
$credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
557 |
$credit->apply( { debits => [ $debits->as_list ] } ); |
| 558 |
|
558 |
|
| 559 |
$debit_2->discard_changes; |
559 |
$debit_2->discard_changes; |
| 560 |
is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' ); |
560 |
is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' ); |
|
Lines 978-984
subtest "payout() tests" => sub {
Link Here
|
| 978 |
|
978 |
|
| 979 |
subtest "reduce() tests" => sub { |
979 |
subtest "reduce() tests" => sub { |
| 980 |
|
980 |
|
| 981 |
plan tests => 29; |
981 |
plan tests => 34; |
| 982 |
|
982 |
|
| 983 |
$schema->storage->txn_begin; |
983 |
$schema->storage->txn_begin; |
| 984 |
|
984 |
|
|
Lines 1101-1112
subtest "reduce() tests" => sub {
Link Here
|
| 1101 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
1101 |
is( $reduction->status(), 'APPLIED', "Reduction status is 'APPLIED'" ); |
| 1102 |
|
1102 |
|
| 1103 |
my $offsets = Koha::Account::Offsets->search( |
1103 |
my $offsets = Koha::Account::Offsets->search( |
| 1104 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
1104 |
{ credit_id => $reduction->id } ); |
| 1105 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
1105 |
is( $offsets->count, 2, 'Two offsets generated' ); |
| 1106 |
my $THE_offset = $offsets->next; |
1106 |
my $THE_offset = $offsets->next; |
|
|
1107 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for discount line'); |
| 1107 |
is( $THE_offset->amount * 1, |
1108 |
is( $THE_offset->amount * 1, |
| 1108 |
-5, 'Correct amount was applied against debit' ); |
1109 |
-5, 'Correct offset amount recorded'); |
| 1109 |
is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" ); |
1110 |
$THE_offset = $offsets->next; |
|
|
1111 |
is( $THE_offset->type, 'APPLY', "APPLY offset added for 'DISCOUNT'" ); |
| 1112 |
is( $THE_offset->amount * 1, -5, 'Correct amount offset against debt'); |
| 1113 |
is( $THE_offset->debit_id, $debit1->accountlines_id, 'APPLY offset recorded the correct debit_id'); |
| 1110 |
|
1114 |
|
| 1111 |
# Zero offset created when zero outstanding |
1115 |
# Zero offset created when zero outstanding |
| 1112 |
# (Refund another 5 on paid debt of 20) |
1116 |
# (Refund another 5 on paid debt of 20) |
|
Lines 1121-1132
subtest "reduce() tests" => sub {
Link Here
|
| 1121 |
is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED"); |
1125 |
is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED"); |
| 1122 |
|
1126 |
|
| 1123 |
$offsets = Koha::Account::Offsets->search( |
1127 |
$offsets = Koha::Account::Offsets->search( |
| 1124 |
{ credit_id => $reduction->id, debit_id => $debit1->id } ); |
1128 |
{ credit_id => $reduction->id } ); |
| 1125 |
is( $offsets->count, 1, 'Only one new offset is generated' ); |
1129 |
is( $offsets->count, 2, 'Two offsets generated' ); |
| 1126 |
$THE_offset = $offsets->next; |
1130 |
$THE_offset = $offsets->next; |
|
|
1131 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for refund line'); |
| 1132 |
is( $THE_offset->amount * 1, |
| 1133 |
-5, 'Correct offset amount recorded'); |
| 1134 |
$THE_offset = $offsets->next; |
| 1135 |
is( $THE_offset->type, 'APPLY', "APPLY offset added for 'REFUND'" ); |
| 1127 |
is( $THE_offset->amount * 1, |
1136 |
is( $THE_offset->amount * 1, |
| 1128 |
0, 'Zero offset created for already paid off debit' ); |
1137 |
0, 'Zero offset created for already paid off debit' ); |
| 1129 |
is( $THE_offset->type, 'REFUND', "Offset type set to 'REFUND'" ); |
|
|
| 1130 |
|
1138 |
|
| 1131 |
# Compound reduction should not allow more than original amount |
1139 |
# Compound reduction should not allow more than original amount |
| 1132 |
# (Reduction of 5 + 5 + 20 > 20) |
1140 |
# (Reduction of 5 + 5 + 20 > 20) |
|
Lines 1157-1163
subtest "reduce() tests" => sub {
Link Here
|
| 1157 |
}; |
1165 |
}; |
| 1158 |
|
1166 |
|
| 1159 |
subtest "cancel() tests" => sub { |
1167 |
subtest "cancel() tests" => sub { |
| 1160 |
plan tests => 16; |
1168 |
plan tests => 18; |
| 1161 |
|
1169 |
|
| 1162 |
$schema->storage->txn_begin; |
1170 |
$schema->storage->txn_begin; |
| 1163 |
|
1171 |
|
|
Lines 1243-1255
subtest "cancel() tests" => sub {
Link Here
|
| 1243 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
1251 |
is( $account->balance() * 1, 15, "Account balance is 15" ); |
| 1244 |
|
1252 |
|
| 1245 |
my $offsets = Koha::Account::Offsets->search( |
1253 |
my $offsets = Koha::Account::Offsets->search( |
| 1246 |
{ credit_id => $cancellation->id, debit_id => $debit1->id } ); |
1254 |
{ credit_id => $cancellation->id } ); |
| 1247 |
is( $offsets->count, 1, 'Only one offset is generated' ); |
1255 |
is( $offsets->count, 2, 'Two offsets are generated' ); |
| 1248 |
my $THE_offset = $offsets->next; |
1256 |
my $THE_offset = $offsets->next; |
|
|
1257 |
is( $THE_offset->type, 'CREATE', 'CREATE offset added for cancel line'); |
| 1258 |
is( $THE_offset->amount * 1, -10, 'Correct offset amount recorded' ); |
| 1259 |
$THE_offset = $offsets->next; |
| 1260 |
is( $THE_offset->type, 'APPLY', "APPLY offset added" ); |
| 1249 |
is( $THE_offset->amount * 1, |
1261 |
is( $THE_offset->amount * 1, |
| 1250 |
-10, 'Correct amount was applied against debit' ); |
1262 |
-10, 'Correct amount was applied against debit' ); |
| 1251 |
is( $THE_offset->type, 'CANCELLATION', |
|
|
| 1252 |
"Offset type set to 'CANCELLATION'" ); |
| 1253 |
|
1263 |
|
| 1254 |
$schema->storage->txn_rollback; |
1264 |
$schema->storage->txn_rollback; |
| 1255 |
}; |
1265 |
}; |