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

(-)a/t/db_dependent/Accounts.t (-10 / +36 lines)
Lines 358-364 subtest "Koha::Account::pay writeoff tests" => sub { Link Here
358
358
359
subtest "More Koha::Account::pay tests" => sub {
359
subtest "More Koha::Account::pay tests" => sub {
360
360
361
    plan tests => 8;
361
    plan tests => 12;
362
362
363
    # Create a borrower
363
    # Create a borrower
364
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
364
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
Lines 392-402 subtest "More Koha::Account::pay tests" => sub { Link Here
392
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
392
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
393
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
393
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
394
    # make the full payment
394
    # make the full payment
395
    $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' });
395
    my $payment = $account->pay(
396
        {
397
            lines      => [$line],
398
            amount     => $amount,
399
            library_id => $branch,
400
            note       => 'A payment note'
401
        }
402
    );
396
403
397
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->{accountlines_id} })->next();
404
    my $offsets = Koha::Account::Offsets->search({ credit_id => $payment->{payment_id} });
398
    is( $offset->amount+0, -100, 'Offset amount is -100.00' );
405
    is( $offsets->count, 2, 'Two offsets recorded');
399
    is( $offset->type(), 'Payment', 'Offset type is Payment' );
406
    my $offset = $offsets->next;
407
    is( $offset->type(), 'CREATE', 'First offset type is CREATE' );
408
    is( $offset->amount+0, -100, 'First offset amount is -100.00' );
409
    $offset = $offsets->next;
410
    is( $offset->type(), 'APPLY', 'Second offset type is APPLY' );
411
    is( $offset->amount+0, -100, 'Second offset amount is -100.00' );
412
    is( $offset->debit_id, $accountline->{accountlines_id}, 'Second offset is against the right accountline');
400
413
401
    my $stat = $schema->resultset('Statistic')->search({
414
    my $stat = $schema->resultset('Statistic')->search({
402
        branch  => $branch,
415
        branch  => $branch,
Lines 417-423 subtest "More Koha::Account::pay tests" => sub { Link Here
417
430
418
subtest "Even more Koha::Account::pay tests" => sub {
431
subtest "Even more Koha::Account::pay tests" => sub {
419
432
420
    plan tests => 8;
433
    plan tests => 12;
421
434
422
    # Create a borrower
435
    # Create a borrower
423
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
436
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
Lines 452-462 subtest "Even more Koha::Account::pay tests" => sub { Link Here
452
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
465
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
453
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
466
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
454
    # make the full payment
467
    # make the full payment
455
    $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
468
    my $payment = $account->pay(
469
        {
470
            lines      => [$line],
471
            amount     => $partialamount,
472
            library_id => $branch,
473
            note       => 'A payment note'
474
        }
475
    );
456
476
457
    my $offset = Koha::Account::Offsets->search( { debit_id => $accountline->{ accountlines_id } } )->next();
477
    my $offsets = Koha::Account::Offsets->search({ credit_id => $payment->{payment_id} });
458
    is( $offset->amount+0, -60, 'Offset amount is -60.00' );
478
    is( $offsets->count, 2, 'Two offsets recorded');
459
    is( $offset->type, 'Payment', 'Offset type is payment' );
479
    my $offset = $offsets->next;
480
    is( $offset->type(), 'CREATE', 'First offset type is CREATE' );
481
    is( $offset->amount+0, -60, 'First offset amount is -60.00' );
482
    $offset = $offsets->next;
483
    is( $offset->type(), 'APPLY', 'Second offset type is APPLY' );
484
    is( $offset->amount+0, -60, 'Second offset amount is -60.00' );
485
    is( $offset->debit_id, $accountline->{accountlines_id}, 'Second offset is against the right accountline');
460
486
461
    my $stat = $schema->resultset('Statistic')->search({
487
    my $stat = $schema->resultset('Statistic')->search({
462
        branch  => $branch,
488
        branch  => $branch,
(-)a/t/db_dependent/Circulation.t (-2 / +2 lines)
Lines 1371-1377 subtest "CanBookBeRenewed tests" => sub { Link Here
1371
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
1371
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
1372
1372
1373
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
1373
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
1374
    is( $offset->type, 'OVERDUE', 'Account offset type is Fine' );
1374
    is( $offset->type, 'CREATE', 'Account offset type is CREATE' );
1375
    is( $offset->amount+0, 15, 'Account offset amount is 15.00' );
1375
    is( $offset->amount+0, 15, 'Account offset amount is 15.00' );
1376
1376
1377
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
1377
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
Lines 3383-3389 subtest '_FixOverduesOnReturn' => sub { Link Here
3383
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 1, 'RETURNED' );
3383
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 1, 'RETURNED' );
3384
3384
3385
    $accountline->_result()->discard_changes();
3385
    $accountline->_result()->discard_changes();
3386
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'Forgiven' })->next();
3386
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'APPLY' })->next();
3387
3387
3388
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3388
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3389
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
3389
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
(-)a/t/db_dependent/Circulation/NoIssuesChargeGuarantees.t (-1 / +1 lines)
Lines 81-87 is( $accountline->amountoutstanding+0, 10, "Found 10.00 amount outstanding" ); Link Here
81
is( $accountline->debit_type_code, "LOST", "Debit type is LOST" );
81
is( $accountline->debit_type_code, "LOST", "Debit type is LOST" );
82
82
83
my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
83
my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id })->next();
84
is( $offset->type, 'Lost Item', 'Got correct offset type' );
84
is( $offset->type, 'CREATE', 'Got CREATE offset type' );
85
is( $offset->amount+0, 10, 'Got amount of $10.00' );
85
is( $offset->amount+0, 10, 'Got amount of $10.00' );
86
86
87
$schema->storage->txn_rollback;
87
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Account/Line.t (-15 / +24 lines)
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 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' );
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');
1126
    $THE_offset = $offsets->next;
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
};
1256
- 

Return to bug 22435