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

(-)a/t/db_dependent/Accounts.t (-10 / +36 lines)
Lines 329-335 subtest "Koha::Account::pay writeoff tests" => sub { Link Here
329
329
330
subtest "More Koha::Account::pay tests" => sub {
330
subtest "More Koha::Account::pay tests" => sub {
331
331
332
    plan tests => 8;
332
    plan tests => 12;
333
333
334
    # Create a borrower
334
    # Create a borrower
335
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
335
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
Lines 363-373 subtest "More Koha::Account::pay tests" => sub { Link Here
363
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
363
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
364
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
364
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
365
    # make the full payment
365
    # make the full payment
366
    $account->pay({ lines => [$line], amount => $amount, library_id => $branch, note => 'A payment note' });
366
    my $payment = $account->pay(
367
        {
368
            lines      => [$line],
369
            amount     => $amount,
370
            library_id => $branch,
371
            note       => 'A payment note'
372
        }
373
    );
367
374
368
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->{accountlines_id} })->next();
375
    my $offsets = Koha::Account::Offsets->search({ credit_id => $payment->{payment_id} });
369
    is( $offset->amount+0, -100, 'Offset amount is -100.00' );
376
    is( $offsets->count, 2, 'Two offsets recorded');
370
    is( $offset->type(), 'Payment', 'Offset type is Payment' );
377
    my $offset = $offsets->next;
378
    is( $offset->type(), 'CREATE', 'First offset type is CREATE' );
379
    is( $offset->amount+0, -100, 'First offset amount is -100.00' );
380
    $offset = $offsets->next;
381
    is( $offset->type(), 'APPLY', 'Second offset type is APPLY' );
382
    is( $offset->amount+0, -100, 'Second offset amount is -100.00' );
383
    is( $offset->debit_id, $accountline->{accountlines_id}, 'Second offset is against the right accountline');
371
384
372
    my $stat = $schema->resultset('Statistic')->search({
385
    my $stat = $schema->resultset('Statistic')->search({
373
        branch  => $branch,
386
        branch  => $branch,
Lines 388-394 subtest "More Koha::Account::pay tests" => sub { Link Here
388
401
389
subtest "Even more Koha::Account::pay tests" => sub {
402
subtest "Even more Koha::Account::pay tests" => sub {
390
403
391
    plan tests => 8;
404
    plan tests => 12;
392
405
393
    # Create a borrower
406
    # Create a borrower
394
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
407
    my $category   = $builder->build({ source => 'Category' })->{ categorycode };
Lines 423-433 subtest "Even more Koha::Account::pay tests" => sub { Link Here
423
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
436
    my $account = Koha::Account->new( { patron_id => $borrowernumber } );
424
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
437
    my $line = Koha::Account::Lines->find( $accountline->{ accountlines_id } );
425
    # make the full payment
438
    # make the full payment
426
    $account->pay({ lines => [$line], amount => $partialamount, library_id => $branch, note => 'A payment note' });
439
    my $payment = $account->pay(
440
        {
441
            lines      => [$line],
442
            amount     => $partialamount,
443
            library_id => $branch,
444
            note       => 'A payment note'
445
        }
446
    );
427
447
428
    my $offset = Koha::Account::Offsets->search( { debit_id => $accountline->{ accountlines_id } } )->next();
448
    my $offsets = Koha::Account::Offsets->search({ credit_id => $payment->{payment_id} });
429
    is( $offset->amount+0, -60, 'Offset amount is -60.00' );
449
    is( $offsets->count, 2, 'Two offsets recorded');
430
    is( $offset->type, 'Payment', 'Offset type is payment' );
450
    my $offset = $offsets->next;
451
    is( $offset->type(), 'CREATE', 'First offset type is CREATE' );
452
    is( $offset->amount+0, -60, 'First offset amount is -60.00' );
453
    $offset = $offsets->next;
454
    is( $offset->type(), 'APPLY', 'Second offset type is APPLY' );
455
    is( $offset->amount+0, -60, 'Second offset amount is -60.00' );
456
    is( $offset->debit_id, $accountline->{accountlines_id}, 'Second offset is against the right accountline');
431
457
432
    my $stat = $schema->resultset('Statistic')->search({
458
    my $stat = $schema->resultset('Statistic')->search({
433
        branch  => $branch,
459
        branch  => $branch,
(-)a/t/db_dependent/Circulation.t (-2 / +2 lines)
Lines 1374-1380 subtest "CanBookBeRenewed tests" => sub { Link Here
1374
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
1374
    is( $line->issue_id, $issue->id, 'Account line issue id matches' );
1375
1375
1376
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
1376
    my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next();
1377
    is( $offset->type, 'OVERDUE', 'Account offset type is Fine' );
1377
    is( $offset->type, 'CREATE', 'Account offset type is CREATE' );
1378
    is( $offset->amount+0, 15, 'Account offset amount is 15.00' );
1378
    is( $offset->amount+0, 15, 'Account offset amount is 15.00' );
1379
1379
1380
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
1380
    t::lib::Mocks::mock_preference('WhenLostForgiveFine','0');
Lines 3386-3392 subtest '_FixOverduesOnReturn' => sub { Link Here
3386
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 1, 'RETURNED' );
3386
    C4::Circulation::_FixOverduesOnReturn( $patron->{borrowernumber}, $item->itemnumber, 1, 'RETURNED' );
3387
3387
3388
    $accountline->_result()->discard_changes();
3388
    $accountline->_result()->discard_changes();
3389
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'Forgiven' })->next();
3389
    my $offset = Koha::Account::Offsets->search({ debit_id => $accountline->id, type => 'APPLY' })->next();
3390
3390
3391
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3391
    is( $accountline->amountoutstanding + 0, 0, 'Fine amountoutstanding has been reduced to 0' );
3392
    isnt( $accountline->status, 'UNRETURNED', 'Open fine ( account type OVERDUE ) has been closed out ( status not UNRETURNED )');
3392
    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.t (-12 / +12 lines)
Lines 1264-1282 subtest 'Koha::Account::payout_amount() tests' => sub { Link Here
1264
    my $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } );
1264
    my $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } );
1265
    is( $offsets->count, 4, 'Four offsets generated' );
1265
    is( $offsets->count, 4, 'Four offsets generated' );
1266
    my $offset = $offsets->next;
1266
    my $offset = $offsets->next;
1267
    is( $offset->type, 'PAYOUT', 'PAYOUT offset added for payout line' );
1267
    is( $offset->type, 'CREATE', 'CREATE offset added for payout line' );
1268
    is( $offset->amount * 1, 10, 'Correct offset amount recorded' );
1268
    is( $offset->amount * 1, 10, 'Correct offset amount recorded' );
1269
    $offset = $offsets->next;
1269
    $offset = $offsets->next;
1270
    is( $offset->credit_id, $credit_1->id, "Offset added against credit_1");
1270
    is( $offset->credit_id, $credit_1->id, "Offset added against credit_1");
1271
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1271
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1272
    is( $offset->amount * 1, -2,      'Correct amount offset against credit_1' );
1272
    is( $offset->amount * 1, -2,      'Correct amount offset against credit_1' );
1273
    $offset = $offsets->next;
1273
    $offset = $offsets->next;
1274
    is( $offset->credit_id, $credit_2->id, "Offset added against credit_2");
1274
    is( $offset->credit_id, $credit_2->id, "Offset added against credit_2");
1275
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1275
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1276
    is( $offset->amount * 1, -3,      'Correct amount offset against credit_2' );
1276
    is( $offset->amount * 1, -3,      'Correct amount offset against credit_2' );
1277
    $offset = $offsets->next;
1277
    $offset = $offsets->next;
1278
    is( $offset->credit_id, $credit_3->id, "Offset added against credit_3");
1278
    is( $offset->credit_id, $credit_3->id, "Offset added against credit_3");
1279
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1279
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1280
    is( $offset->amount * 1, -5,      'Correct amount offset against credit_3' );
1280
    is( $offset->amount * 1, -5,      'Correct amount offset against credit_3' );
1281
1281
1282
    my $credit_5 = $account->add_credit( { amount => 5, interface => 'commandline' } );
1282
    my $credit_5 = $account->add_credit( { amount => 5, interface => 'commandline' } );
Lines 1297-1307 subtest 'Koha::Account::payout_amount() tests' => sub { Link Here
1297
    $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } );
1297
    $offsets = Koha::Account::Offsets->search( { debit_id => $payout->id } );
1298
    is( $offsets->count, 2, 'Two offsets generated' );
1298
    is( $offsets->count, 2, 'Two offsets generated' );
1299
    $offset = $offsets->next;
1299
    $offset = $offsets->next;
1300
    is( $offset->type, 'PAYOUT', 'PAYOUT offset added for payout line' );
1300
    is( $offset->type, 'CREATE', 'CREATE offset added for payout line' );
1301
    is( $offset->amount * 1, 2.50, 'Correct offset amount recorded' );
1301
    is( $offset->amount * 1, 2.50, 'Correct offset amount recorded' );
1302
    $offset = $offsets->next;
1302
    $offset = $offsets->next;
1303
    is( $offset->credit_id, $credit_5->id, "Offset added against credit_5");
1303
    is( $offset->credit_id, $credit_5->id, "Offset added against credit_5");
1304
    is( $offset->type,       'PAYOUT', "PAYOUT used for offset_type" );
1304
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1305
    is( $offset->amount * 1, -2.50,      'Correct amount offset against credit_5' );
1305
    is( $offset->amount * 1, -2.50,      'Correct amount offset against credit_5' );
1306
1306
1307
    $schema->storage->txn_rollback;
1307
    $schema->storage->txn_rollback;
Lines 1391-1409 subtest 'Koha::Account::payin_amount() tests' => sub { Link Here
1391
    my $offsets = Koha::Account::Offsets->search( { credit_id => $payin->id } );
1391
    my $offsets = Koha::Account::Offsets->search( { credit_id => $payin->id } );
1392
    is( $offsets->count, 4, 'Four offsets generated' );
1392
    is( $offsets->count, 4, 'Four offsets generated' );
1393
    my $offset = $offsets->next;
1393
    my $offset = $offsets->next;
1394
    is( $offset->type, 'Payment', 'Payment offset added for payin line' );
1394
    is( $offset->type, 'CREATE', 'CREATE offset added for payin line' );
1395
    is( $offset->amount * 1, -10, 'Correct offset amount recorded' );
1395
    is( $offset->amount * 1, -10, 'Correct offset amount recorded' );
1396
    $offset = $offsets->next;
1396
    $offset = $offsets->next;
1397
    is( $offset->debit_id, $debit_1->id, "Offset added against debit_1");
1397
    is( $offset->debit_id, $debit_1->id, "Offset added against debit_1");
1398
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1398
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1399
    is( $offset->amount * 1, -2,      'Correct amount offset against debit_1' );
1399
    is( $offset->amount * 1, -2,      'Correct amount offset against debit_1' );
1400
    $offset = $offsets->next;
1400
    $offset = $offsets->next;
1401
    is( $offset->debit_id, $debit_2->id, "Offset added against debit_2");
1401
    is( $offset->debit_id, $debit_2->id, "Offset added against debit_2");
1402
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1402
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1403
    is( $offset->amount * 1, -3,      'Correct amount offset against debit_2' );
1403
    is( $offset->amount * 1, -3,      'Correct amount offset against debit_2' );
1404
    $offset = $offsets->next;
1404
    $offset = $offsets->next;
1405
    is( $offset->debit_id, $debit_3->id, "Offset added against debit_3");
1405
    is( $offset->debit_id, $debit_3->id, "Offset added against debit_3");
1406
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1406
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1407
    is( $offset->amount * 1, -5,      'Correct amount offset against debit_3' );
1407
    is( $offset->amount * 1, -5,      'Correct amount offset against debit_3' );
1408
1408
1409
    my $debit_5 = $account->add_debit( { amount => 5, interface => 'commandline', type => 'OVERDUE' } );
1409
    my $debit_5 = $account->add_debit( { amount => 5, interface => 'commandline', type => 'OVERDUE' } );
Lines 1424-1434 subtest 'Koha::Account::payin_amount() tests' => sub { Link Here
1424
    $offsets = Koha::Account::Offsets->search( { credit_id => $payin->id } );
1424
    $offsets = Koha::Account::Offsets->search( { credit_id => $payin->id } );
1425
    is( $offsets->count, 2, 'Two offsets generated' );
1425
    is( $offsets->count, 2, 'Two offsets generated' );
1426
    $offset = $offsets->next;
1426
    $offset = $offsets->next;
1427
    is( $offset->type, 'Payment', 'Payment offset added for payin line' );
1427
    is( $offset->type, 'CREATE', 'CREATE offset added for payin line' );
1428
    is( $offset->amount * 1, -2.50, 'Correct offset amount recorded' );
1428
    is( $offset->amount * 1, -2.50, 'Correct offset amount recorded' );
1429
    $offset = $offsets->next;
1429
    $offset = $offsets->next;
1430
    is( $offset->debit_id, $debit_5->id, "Offset added against debit_5");
1430
    is( $offset->debit_id, $debit_5->id, "Offset added against debit_5");
1431
    is( $offset->type,       'Payment', "Payment used for offset_type" );
1431
    is( $offset->type,       'APPLY', "APPLY used for offset_type" );
1432
    is( $offset->amount * 1, -2.50,      'Correct amount offset against debit_5' );
1432
    is( $offset->amount * 1, -2.50,      'Correct amount offset against debit_5' );
1433
1433
1434
    $schema->storage->txn_rollback;
1434
    $schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Account/Line.t (-20 / +30 lines)
Lines 208-214 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
    $credit = $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
211
    $credit = $credit->apply( { debits => [ $debits->as_list ] } );
212
    is( ref($credit), 'Koha::Account::Line', '->apply returns the updated Koha::Account::Line credit object');
212
    is( ref($credit), 'Koha::Account::Line', '->apply returns the updated Koha::Account::Line credit object');
213
    is( $credit->amountoutstanding * -1, 90, 'Remaining credit is correctly calculated' );
213
    is( $credit->amountoutstanding * -1, 90, 'Remaining credit is correctly calculated' );
214
214
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 266-272 subtest 'apply() tests' => sub { Link Here
266
266
267
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } });
267
    $debits = Koha::Account::Lines->search({ accountlines_id => { -in => [ $debit_1->id, $debit_2->id, $debit_3->id, $credit->id ] } });
268
    throws_ok {
268
    throws_ok {
269
        $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } ); }
269
        $credit_2->apply( { debits => [ $debits->as_list ] }
270
        'Koha::Exceptions::Account::IsNotDebit',
270
        'Koha::Exceptions::Account::IsNotDebit',
271
        '->apply() rolls back if any of the passed lines is not a debit';
271
        '->apply() rolls back if any of the passed lines is not a debit';
272
272
Lines 276-282 subtest 'apply() tests' => sub { Link Here
276
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
276
    is( $credit_2->discard_changes->amountoutstanding * -1, 20, 'No changes made' );
277
277
278
    $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 ] } });
279
    $credit_2 = $credit_2->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
279
    $credit_2 = $credit_2->apply( { debits => [ $debits->as_list ] } );
280
280
281
    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' );
282
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
282
    is( $debit_2->discard_changes->amountoutstanding * 1,  0, 'Debit cancelled' );
Lines 333-339 subtest 'apply() tests' => sub { Link Here
333
        }
333
        }
334
    );
334
    );
335
    my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list;
335
    my $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list;
336
    $credit_forgive = $credit_forgive->apply( { debits => $debits_renew, offset_type => 'Forgiven' } );
336
    $credit_forgive = $credit_forgive->apply( { debits => $debits_renew } );
337
    is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' );
337
    is( $called, 0, 'C4::Circulation::AddRenew NOT called when RenewAccruingItemWhenPaid enabled but credit type is "FORGIVEN"' );
338
338
339
    $accountline = Koha::Account::Line->new(
339
    $accountline = Koha::Account::Line->new(
Lines 352-358 subtest 'apply() tests' => sub { Link Here
352
    )->store();
352
    )->store();
353
    my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
353
    my $credit_renew = $account->add_credit({ amount => 100, user_id => $patron->id, interface => 'commandline' });
354
    $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list;
354
    $debits_renew = Koha::Account::Lines->search({ accountlines_id => $accountline->id })->as_list;
355
    $credit_renew = $credit_renew->apply( { debits => $debits_renew, offset_type => 'Manual Credit' } );
355
    $credit_renew = $credit_renew->apply( { debits => $debits_renew } );
356
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
356
    is( $called, 1, 'RenewAccruingItemWhenPaid causes C4::Circulation::AddRenew to be called when appropriate' );
357
357
358
    my @messages = @{$credit_renew->messages};
358
    my @messages = @{$credit_renew->messages};
Lines 554-560 subtest 'adjust() tests' => sub { Link Here
554
554
555
    # Update fine to partially paid
555
    # Update fine to partially paid
556
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
556
    my $debits = Koha::Account::Lines->search({ accountlines_id => $debit_2->id });
557
    $credit->apply( { debits => [ $debits->as_list ], offset_type => 'Manual Credit' } );
557
    $credit->apply( { debits => [ $debits->as_list ] } );
558
558
559
    $debit_2->discard_changes;
559
    $debit_2->discard_changes;
560
    is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' );
560
    is( $debit_2->amount * 1, 150, 'Fine amount unaffected by partial payment' );
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' );
1126
    $THE_offset = $offsets->next;
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');
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
};
(-)a/t/db_dependent/Koha/Items.t (-18 / +9 lines)
Lines 347-354 subtest 'store' => sub { Link Here
347
                    interface => 'test',
347
                    interface => 'test',
348
                }
348
                }
349
            );
349
            );
350
            $credit->apply(
350
            $credit->apply( { debits => [ $debts->as_list ] } );
351
                { debits => [ $debts->as_list ], offset_type => 'Writeoff' } );
352
351
353
            # Simulate item marked as found
352
            # Simulate item marked as found
354
            $item->itemlost(0)->store;
353
            $item->itemlost(0)->store;
Lines 431-438 subtest 'store' => sub { Link Here
431
                    interface => 'test',
430
                    interface => 'test',
432
                }
431
                }
433
            );
432
            );
434
            $credit->apply(
433
            $credit->apply( { debits => [ $debts->as_list ] } );
435
                { debits => [ $debts->as_list ], offset_type => 'Payment' } );
436
434
437
            # Simulate item marked as found
435
            # Simulate item marked as found
438
            $item->itemlost(0)->store;
436
            $item->itemlost(0)->store;
Lines 630-637 subtest 'store' => sub { Link Here
630
                }
628
                }
631
            );
629
            );
632
630
633
            $payment->apply(
631
            $payment->apply( { debits => [$lost_fee_line] } );
634
                { debits => [$lost_fee_line], offset_type => 'Payment' } );
635
632
636
            # Partially write off fee
633
            # Partially write off fee
637
            my $write_off_amount = 25;
634
            my $write_off_amount = 25;
Lines 642-649 subtest 'store' => sub { Link Here
642
                    interface => 'test',
639
                    interface => 'test',
643
                }
640
                }
644
            );
641
            );
645
            $write_off->apply(
642
            $write_off->apply( { debits => [$lost_fee_line] } );
646
                { debits => [$lost_fee_line], offset_type => 'Writeoff' } );
647
643
648
            is(
644
            is(
649
                $account->balance,
645
                $account->balance,
Lines 771-778 subtest 'store' => sub { Link Here
771
                    interface => 'test',
767
                    interface => 'test',
772
                }
768
                }
773
            );
769
            );
774
            $payment->apply(
770
            $payment->apply( { debits => [$lost_fee_line] } );
775
                { debits => [$lost_fee_line], offset_type => 'Payment' } );
776
771
777
            is(
772
            is(
778
                $account->balance,
773
                $account->balance,
Lines 962-969 subtest 'store' => sub { Link Here
962
                    interface => 'test',
957
                    interface => 'test',
963
                }
958
                }
964
            );
959
            );
965
            $credit->apply(
960
            $credit->apply( { debits => [ $debts->as_list ] } );
966
                { debits => [ $debts->as_list ], offset_type => 'Payment' } );
967
961
968
            # Simulate item marked as found
962
            # Simulate item marked as found
969
            $item->itemlost(0)->store;
963
            $item->itemlost(0)->store;
Lines 1054-1061 subtest 'store' => sub { Link Here
1054
                    interface => 'test',
1048
                    interface => 'test',
1055
                }
1049
                }
1056
            );
1050
            );
1057
            $credit->apply(
1051
            $credit->apply( { debits => [ $debts->as_list ] } );
1058
                { debits => [ $debts->as_list ], offset_type => 'Payment' } );
1059
1052
1060
            # Fine not forgiven
1053
            # Fine not forgiven
1061
            my $overdue = $account->add_debit(
1054
            my $overdue = $account->add_debit(
Lines 1165-1172 subtest 'store' => sub { Link Here
1165
                    interface => 'test',
1158
                    interface => 'test',
1166
                }
1159
                }
1167
            );
1160
            );
1168
            $credit->apply(
1161
            $credit->apply( { debits => [ $debts->as_list ] } );
1169
                { debits => [ $debts->as_list ], offset_type => 'Payment' } );
1170
1162
1171
            # Add overdue
1163
            # Add overdue
1172
            my $overdue = $account->add_debit(
1164
            my $overdue = $account->add_debit(
Lines 1196-1203 subtest 'store' => sub { Link Here
1196
                    item_id    => $item->itemnumber
1188
                    item_id    => $item->itemnumber
1197
                }
1189
                }
1198
            );
1190
            );
1199
            $credit->apply(
1191
            $credit->apply( { debits => [$overdue] } );
1200
                { debits => [$overdue], offset_type => 'Forgiven' } );
1201
1192
1202
            # Simulate item marked as found
1193
            # Simulate item marked as found
1203
            $item->itemlost(0)->store;
1194
            $item->itemlost(0)->store;
(-)a/t/db_dependent/api/v1/patrons_accounts.t (-3 / +1 lines)
Lines 116-123 subtest 'get_balance() tests' => sub { Link Here
116
            note         => 'He paid!',
116
            note         => 'He paid!',
117
            description  => 'Finally!',
117
            description  => 'Finally!',
118
            library_id   => $patron->branchcode,
118
            library_id   => $patron->branchcode,
119
            account_type => 'PAYMENT',
119
            account_type => 'PAYMENT'
120
            offset_type  => 'Payment'
121
        }
120
        }
122
    );
121
    );
123
122
124
- 

Return to bug 22435