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

(-)a/t/db_dependent/Koha/Account/Line.t (-14 / +16 lines)
Lines 175-181 subtest 'is_credit() and is_debit() tests' => sub { Link Here
175
175
176
subtest 'apply() tests' => sub {
176
subtest 'apply() tests' => sub {
177
177
178
    plan tests => 25;
178
    plan tests => 29;
179
179
180
    $schema->storage->txn_begin;
180
    $schema->storage->txn_begin;
181
181
Lines 208-217 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
    my $remaining_credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
211
    $credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
212
    is( $remaining_credit * 1, 90, 'Remaining credit is correctly calculated' );
212
    is( ref($credit), 'Koha::Account::Line', '->apply returns the updated Koha::Account::Line credit object');
213
    $credit->discard_changes;
213
    is( $credit->amountoutstanding * -1, 90, 'Remaining credit is correctly calculated' );
214
    is( $credit->amountoutstanding * -1, $remaining_credit, 'Remaining credit correctly stored' );
215
214
216
    # re-read debit info
215
    # re-read debit info
217
    $debit_1->discard_changes;
216
    $debit_1->discard_changes;
Lines 224-233 subtest 'apply() tests' => sub { Link Here
224
    is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );
223
    is( $THE_offset->type, 'Manual Credit', 'Passed type stored correctly' );
225
224
226
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
225
    $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
227
    $remaining_credit = $credit->apply( { debits => [ $debits->as_list ] } );
226
    $credit = $credit->apply( { debits => [ $debits->as_list ] } );
228
    is( $remaining_credit, 0, 'No remaining credit left' );
227
    is( $credit->amountoutstanding * 1, 0, 'No remaining credit' );
229
    $credit->discard_changes;
230
    is( $credit->amountoutstanding * 1, 0, 'No outstanding credit' );
231
    $debit_2->discard_changes;
228
    $debit_2->discard_changes;
232
    is( $debit_2->amountoutstanding * 1, 10, 'Outstanding amount decremented correctly' );
229
    is( $debit_2->amountoutstanding * 1, 10, 'Outstanding amount decremented correctly' );
233
230
Lines 279-290 subtest 'apply() tests' => sub { Link Here
279
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
276
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
280
277
281
    $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 ] } });
282
    $remaining_credit = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
279
    $credit_2 = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
283
280
284
    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' );
285
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
282
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
286
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
283
    is( $debit_3->discard_changes->amountoutstanding * 1, 90, 'Outstanding amount correctly calculated' );
287
    is( $credit_2->discard_changes->amountoutstanding * 1, 0, 'No remaining credit' );
284
    is( $credit_2->amountoutstanding * 1, 0, 'No remaining credit' );
288
285
289
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
286
    my $library  = $builder->build_object( { class => 'Koha::Libraries' } );
290
    my $biblio = $builder->build_sample_biblio();
287
    my $biblio = $builder->build_sample_biblio();
Lines 329-338 subtest 'apply() tests' => sub { Link Here
329
    $module->mock('CanBookBeRenewed', sub { return 1; });
326
    $module->mock('CanBookBeRenewed', sub { return 1; });
330
    my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
327
    my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
331
    my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list;
328
    my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list;
332
    $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
329
    $credit_renew = $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
333
334
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
330
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
335
331
332
    my @messages = @{$credit_renew->messages};
333
    is( $messages[0]->type, 'info', 'Info message added for renewal' );
334
    is( $messages[0]->message, 'renewal', 'Message is "renewal"' );
335
    is( $messages[0]->payload->{itemnumber}, $item->id, 'itemnumber found in payload' );
336
    is( $messages[0]->payload->{due_date}, 1, 'due_date key in payload' );
337
    is( $messages[0]->payload->{success}, 1, "'success' key in payload" );
338
336
    $schema->storage->txn_rollback;
339
    $schema->storage->txn_rollback;
337
};
340
};
338
341
339
- 

Return to bug 27995