Lines 213-219
subtest 'apply() tests' => sub {
Link Here
|
213 |
$debit_1->discard_changes; |
213 |
$debit_1->discard_changes; |
214 |
|
214 |
|
215 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
215 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
216 |
my $remaining_credit = $credit->apply( { debits => $debits, offset_type => 'Manual Credit' } ); |
216 |
my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
217 |
is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' ); |
217 |
is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' ); |
218 |
$credit->discard_changes; |
218 |
$credit->discard_changes; |
219 |
is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' ); |
219 |
is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' ); |
Lines 229-235
subtest 'apply() tests' => sub {
Link Here
|
229 |
is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' ); |
229 |
is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' ); |
230 |
|
230 |
|
231 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
231 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
232 |
$remaining_credit = $credit->apply( { debits => $debits } ); |
232 |
$remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } ); |
233 |
is( $remaining_credit, 0, 'No remaining credit left' ); |
233 |
is( $remaining_credit, 0, 'No remaining credit left' ); |
234 |
$credit->discard_changes; |
234 |
$credit->discard_changes; |
235 |
is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' ); |
235 |
is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' ); |
Lines 244-263
subtest 'apply() tests' => sub {
Link Here
|
244 |
|
244 |
|
245 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
245 |
$debits = Koha::Account::Lines->search({ accountlines_id => $debit_1->id }); |
246 |
throws_ok |
246 |
throws_ok |
247 |
{ $credit->apply({ debits => $debits }); } |
247 |
{ $credit->apply({ debits => [ $debits->as_list ] }); } |
248 |
'Koha::Exceptions::Account::NoAvailableCredit', |
248 |
'Koha::Exceptions::Account::NoAvailableCredit', |
249 |
'->apply() can only be used with outstanding credits'; |
249 |
'->apply() can only be used with outstanding credits'; |
250 |
|
250 |
|
251 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
251 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
252 |
throws_ok |
252 |
throws_ok |
253 |
{ $debit_1->apply({ debits => $debits }); } |
253 |
{ $debit_1->apply({ debits => [ $debits->as_list ] }); } |
254 |
'Koha::Exceptions::Account::IsNotCredit', |
254 |
'Koha::Exceptions::Account::IsNotCredit', |
255 |
'->apply() can only be used with credits'; |
255 |
'->apply() can only be used with credits'; |
256 |
|
256 |
|
257 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
257 |
$debits = Koha::Account::Lines->search({ accountlines_id => $credit->id }); |
258 |
my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' }); |
258 |
my $credit_3 = $account->add_credit({ amount => 1, interface => 'commandline' }); |
259 |
throws_ok |
259 |
throws_ok |
260 |
{ $credit_3->apply({ debits => $debits }); } |
260 |
{ $credit_3->apply({ debits => [ $debits->as_list ] }); } |
261 |
'Koha::Exceptions::Account::IsNotDebit', |
261 |
'Koha::Exceptions::Account::IsNotDebit', |
262 |
'->apply() can only be applied to credits'; |
262 |
'->apply() can only be applied to credits'; |
263 |
|
263 |
|
Lines 274-280
subtest 'apply() tests' => sub {
Link Here
|
274 |
|
274 |
|
275 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } }); |
275 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } }); |
276 |
throws_ok { |
276 |
throws_ok { |
277 |
$credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); } |
277 |
$credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); } |
278 |
'Koha::Exceptions::Account::IsNotDebit', |
278 |
'Koha::Exceptions::Account::IsNotDebit', |
279 |
'->apply() rolls back if any of the passed lines is not a debit'; |
279 |
'->apply() rolls back if any of the passed lines is not a debit'; |
280 |
|
280 |
|
Lines 284-290
subtest 'apply() tests' => sub {
Link Here
|
284 |
is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); |
284 |
is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' ); |
285 |
|
285 |
|
286 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); |
286 |
$debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id ] } }); |
287 |
$remaining_credit = $credit_2->apply( { debits => $debits, offset_type => 'Manual Credit' } ); |
287 |
$remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
288 |
|
288 |
|
289 |
is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); |
289 |
is( $debit_1->discard_changes->amountoutstanding * 1, 0, 'No changes to already cancelled debit' ); |
290 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
290 |
is( $debit_2->discard_changes->amountoutstanding * 1, 0, 'Debit cancelled' ); |
Lines 397-403
subtest 'adjust() tests' => sub {
Link Here
|
397 |
|
397 |
|
398 |
# Update fine to partially paid |
398 |
# Update fine to partially paid |
399 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
399 |
my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id }); |
400 |
$credit->apply( { debits => $debits, offset_type => 'Manual Credit' } ); |
400 |
$credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); |
401 |
|
401 |
|
402 |
$debit_2->discard_changes; |
402 |
$debit_2->discard_changes; |
403 |
is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' ); |
403 |
is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' ); |
404 |
- |
|
|