Lines 242-248
subtest 'apply() tests' => sub {
Link Here
|
242 |
$debit_1->discard_changes; |
242 |
$debit_1->discard_changes; |
243 |
|
243 |
|
244 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
244 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
245 |
my $remaining_credit = $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } ); |
245 |
my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
246 |
is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' ); |
246 |
is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' ); |
247 |
$credit->discard_changes; |
247 |
$credit->discard_changes; |
248 |
is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' ); |
248 |
is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' ); |
Lines 258-264
subtest 'apply() tests' => sub {
Link Here
|
258 |
is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' ); |
258 |
is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' ); |
259 |
|
259 |
|
260 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
260 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
261 |
$remaining_credit = $credit->apply( { debits => $debits } ); |
261 |
$remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } ); |
262 |
is( $remaining_credit, 0, 'No remaining credit left' ); |
262 |
is( $remaining_credit, 0, 'No remaining credit left' ); |
263 |
$credit->discard_changes; |
263 |
$credit->discard_changes; |
264 |
is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' ); |
264 |
is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' ); |
Lines 273-292
subtest 'apply() tests' => sub {
Link Here
|
273 |
|
273 |
|
274 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
274 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
275 |
throws_ok |
275 |
throws_ok |
276 |
{ $credit->apply({ debits => $debits }); } |
276 |
{ $credit->apply({ debits => [ $debits->as_list ] }); } |
277 |
'Koha::Exceptions::Account::NoAvailableCredit', |
277 |
'Koha::Exceptions::Account::NoAvailableCredit', |
278 |
'->apply() can only be used with outstanding credits'; |
278 |
'->apply() can only be used with outstanding credits'; |
279 |
|
279 |
|
280 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
280 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
281 |
throws_ok |
281 |
throws_ok |
282 |
{ $debit_1->apply({ debits => $debits }); } |
282 |
{ $debit_1->apply({ debits => [ $debits->as_list ] }); } |
283 |
'Koha::Exceptions::Account::IsNotCredit', |
283 |
'Koha::Exceptions::Account::IsNotCredit', |
284 |
'->apply() can only be used with credits'; |
284 |
'->apply() can only be used with credits'; |
285 |
|
285 |
|
286 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
286 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
287 |
my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' }); |
287 |
my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' }); |
288 |
throws_ok |
288 |
throws_ok |
289 |
{ $credit_3->apply({ debits => $debits }); } |
289 |
{ $credit_3->apply({ debits => [ $debits->as_list ] }); } |
290 |
'Koha::Exceptions::Account::IsNotDebit', |
290 |
'Koha::Exceptions::Account::IsNotDebit', |
291 |
'->apply() can only be applied to credits'; |
291 |
'->apply() can only be applied to credits'; |
292 |
|
292 |
|
Lines 303-309
subtest 'apply() tests' => sub {
Link Here
|
303 |
|
303 |
|
304 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } }); |
304 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } }); |
305 |
throws_ok { |
305 |
throws_ok { |
306 |
$credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); } |
306 |
$credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); } |
307 |
'Koha::Exceptions::Account::IsNotDebit', |
307 |
'Koha::Exceptions::Account::IsNotDebit', |
308 |
'->apply() rolls back if any of the passed lines is not a debit'; |
308 |
'->apply() rolls back if any of the passed lines is not a debit'; |
309 |
|
309 |
|
Lines 313-319
subtest 'apply() tests' => sub {
Link Here
|
313 |
is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); |
313 |
is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); |
314 |
|
314 |
|
315 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); |
315 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); |
316 |
$remaining_credit = $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); |
316 |
$remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
317 |
|
317 |
|
318 |
is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); |
318 |
is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); |
319 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
319 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
Lines 426-432
subtest 'adjust() tests' => sub {
Link Here
|
426 |
|
426 |
|
427 |
# Update fine to partially paid |
427 |
# Update fine to partially paid |
428 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
428 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
429 |
$credit->apply( { debits => $debits, offset_type => 'Manual Credit' } ); |
429 |
$credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
430 |
|
430 |
|
431 |
$debit_2->discard_changes; |
431 |
$debit_2->discard_changes; |
432 |
is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' ); |
432 |
is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' ); |
433 |
- |
|
|