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 1285-1291 subtest "CanBookBeRenewed tests" => sub { Link Here
1285
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
1285
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
1286
1286
1287
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
1287
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
1288
    is( $offset->type, 'OVERDUE', 'Account offset type is Fine' );
1288
    is( $offset->type, 'CREATE', 'Account offset type is CREATE' );
1289
    is( $offset->amount+0, 15, 'Account offset amount is 15.00' );
1289
    is( $offset->amount+0, 15, 'Account offset amount is 15.00' );
1290
1290
1291
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
1291
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
Lines 3297-3303 subtest '_FixOverduesOnReturn' => sub { Link Here
3297
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 1, 'RETURNED' );
3297
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 1, 'RETURNED' );
3298
3298
3299
    $accountline->_result()->discard_changes();
3299
    $accountline->_result()->discard_changes();
3300
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'Forgiven' })->next();
3300
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'APPLY' })->next();
3301
3301
3302
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3302
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3303
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
3303
    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 944-950 subtest "payout() tests" => sub { Link Here
944
944
945
subtest "reduce() tests" => sub {
945
subtest "reduce() tests" => sub {
946
946
947
    plan tests => 29;
947
    plan tests => 34;
948
948
949
    $schema->storage->txn_begin;
949
    $schema->storage->txn_begin;
950
950
Lines 1067-1078 subtest "reduce() tests" => sub { Link Here
1067
    is( $reduction->status(),    'APPLIED', "Reduction status is 'APPLIED'" );
1067
    is( $reduction->status(),    'APPLIED', "Reduction status is 'APPLIED'" );
1068
1068
1069
    my $offsets = Koha::Account::Offsets->search(
1069
    my $offsets = Koha::Account::Offsets->search(
1070
        { credit_id => $reduction->id, debit_id => $debit1->id } );
1070
        { credit_id => $reduction->id } );
1071
    is( $offsets->count, 1, 'Only one offset is generated' );
1071
    is( $offsets->count, 2, 'Two offsets generated' );
1072
    my $THE_offset = $offsets->next;
1072
    my $THE_offset = $offsets->next;
1073
    is( $THE_offset->type, 'CREATE', 'CREATE offset added for discount line');
1073
    is( $THE_offset->amount * 1,
1074
    is( $THE_offset->amount * 1,
1074
        -5, 'Correct amount was applied against debit' );
1075
        -5, 'Correct offset amount recorded');
1075
    is( $THE_offset->type, 'DISCOUNT', "Offset type set to 'DISCOUNT'" );
1076
    $THE_offset = $offsets->next;
1077
    is( $THE_offset->type, 'APPLY', "APPLY offset added for 'DISCOUNT'" );
1078
    is( $THE_offset->amount * 1, -5, 'Correct amount offset against debt');
1079
    is( $THE_offset->debit_id, $debit1->accountlines_id, 'APPLY offset recorded the correct debit_id');
1076
1080
1077
    # Zero offset created when zero outstanding
1081
    # Zero offset created when zero outstanding
1078
    # (Refund another 5 on paid debt of 20)
1082
    # (Refund another 5 on paid debt of 20)
Lines 1087-1098 subtest "reduce() tests" => sub { Link Here
1087
    is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED");
1091
    is( $debit1->status(), 'REFUNDED', "Debit status updated to REFUNDED");
1088
1092
1089
    $offsets = Koha::Account::Offsets->search(
1093
    $offsets = Koha::Account::Offsets->search(
1090
        { credit_id => $reduction->id, debit_id => $debit1->id } );
1094
        { credit_id => $reduction->id } );
1091
    is( $offsets->count, 1, 'Only one new offset is generated' );
1095
    is( $offsets->count, 2, 'Two offsets generated' );
1096
    $THE_offset = $offsets->next;
1097
    is( $THE_offset->type, 'CREATE', 'CREATE offset added for refund line');
1098
    is( $THE_offset->amount * 1,
1099
        -5, 'Correct offset amount recorded');
1092
    $THE_offset = $offsets->next;
1100
    $THE_offset = $offsets->next;
1101
    is( $THE_offset->type, 'APPLY', "APPLY offset added for 'REFUND'" );
1093
    is( $THE_offset->amount * 1,
1102
    is( $THE_offset->amount * 1,
1094
        0, 'Zero offset created for already paid off debit' );
1103
        0, 'Zero offset created for already paid off debit' );
1095
    is( $THE_offset->type, 'REFUND', "Offset type set to 'REFUND'" );
1096
1104
1097
    # Compound reduction should not allow more than original amount
1105
    # Compound reduction should not allow more than original amount
1098
    # (Reduction of 5 + 5 + 20 > 20)
1106
    # (Reduction of 5 + 5 + 20 > 20)
Lines 1123-1129 subtest "reduce() tests" => sub { Link Here
1123
};
1131
};
1124
1132
1125
subtest "cancel() tests" => sub {
1133
subtest "cancel() tests" => sub {
1126
    plan tests => 16;
1134
    plan tests => 18;
1127
1135
1128
    $schema->storage->txn_begin;
1136
    $schema->storage->txn_begin;
1129
1137
Lines 1209-1221 subtest "cancel() tests" => sub { Link Here
1209
    is( $account->balance() * 1, 15, "Account balance is 15" );
1217
    is( $account->balance() * 1, 15, "Account balance is 15" );
1210
1218
1211
    my $offsets = Koha::Account::Offsets->search(
1219
    my $offsets = Koha::Account::Offsets->search(
1212
        { credit_id => $cancellation->id, debit_id => $debit1->id } );
1220
        { credit_id => $cancellation->id } );
1213
    is( $offsets->count, 1, 'Only one offset is generated' );
1221
    is( $offsets->count, 2, 'Two offsets are generated' );
1214
    my $THE_offset = $offsets->next;
1222
    my $THE_offset = $offsets->next;
1223
    is( $THE_offset->type, 'CREATE', 'CREATE offset added for cancel line');
1224
    is( $THE_offset->amount * 1, -10, 'Correct offset amount recorded' );
1225
    $THE_offset = $offsets->next;
1226
    is( $THE_offset->type, 'APPLY', "APPLY offset added" );
1215
    is( $THE_offset->amount * 1,
1227
    is( $THE_offset->amount * 1,
1216
        -10, 'Correct amount was applied against debit' );
1228
        -10, 'Correct amount was applied against debit' );
1217
    is( $THE_offset->type, 'CANCELLATION',
1218
        "Offset type set to 'CANCELLATION'" );
1219
1229
1220
    $schema->storage->txn_rollback;
1230
    $schema->storage->txn_rollback;
1221
};
1231
};
1222
- 

Return to bug 22435