Lines 18-28
Link Here
|
18 |
|
18 |
|
19 |
use Modern::Perl; |
19 |
use Modern::Perl; |
20 |
|
20 |
|
21 |
use Test::More tests => 22; |
21 |
use Test::More tests => 23; |
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
24 |
|
24 |
|
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
|
|
26 |
use t::lib::Mocks; |
26 |
|
27 |
|
27 |
use Koha::Account; |
28 |
use Koha::Account; |
28 |
use Koha::Account::Lines; |
29 |
use Koha::Account::Lines; |
Lines 478-481
subtest 'balance' => sub {
Link Here
|
478 |
$patron->delete; |
479 |
$patron->delete; |
479 |
}; |
480 |
}; |
480 |
|
481 |
|
|
|
482 |
subtest "Koha::Account::chargelostitem tests" => sub { |
483 |
plan tests => 32; |
484 |
|
485 |
my $lostfine; |
486 |
my $procfee; |
487 |
|
488 |
my $itype_no_replace_no_fee = $builder->build({ source => 'Itemtype', value => { |
489 |
rentalcharge => 0, |
490 |
defaultreplacecost => undef, |
491 |
processfee => undef, |
492 |
}}); |
493 |
my $itype_replace_no_fee = $builder->build({ source => 'Itemtype', value => { |
494 |
rentalcharge => 0, |
495 |
defaultreplacecost => 16.32, |
496 |
processfee => undef, |
497 |
}}); |
498 |
my $itype_no_replace_fee = $builder->build({ source => 'Itemtype', value => { |
499 |
rentalcharge => 0, |
500 |
defaultreplacecost => undef, |
501 |
processfee => 8.16, |
502 |
}}); |
503 |
my $itype_replace_fee = $builder->build({ source => 'Itemtype', value => { |
504 |
rentalcharge => 0, |
505 |
defaultreplacecost => 4.08, |
506 |
processfee => 2.04, |
507 |
}}); |
508 |
my $cli_borrowernumber = $builder->build({ source => 'Borrower' })->{'borrowernumber'}; |
509 |
my $cli_itemnumber1 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_no_fee->{itemtype} } })->{'itemnumber'}; |
510 |
my $cli_itemnumber2 = $builder->build({ source => 'Item', value => { itype => $itype_replace_no_fee->{itemtype} } })->{'itemnumber'}; |
511 |
my $cli_itemnumber3 = $builder->build({ source => 'Item', value => { itype => $itype_no_replace_fee->{itemtype} } })->{'itemnumber'}; |
512 |
my $cli_itemnumber4 = $builder->build({ source => 'Item', value => { itype => $itype_replace_fee->{itemtype} } })->{'itemnumber'}; |
513 |
my $duck = Koha::Items->find({itemnumber=>$cli_itemnumber1}); |
514 |
|
515 |
t::lib::Mocks::mock_preference('item-level_itypes', '1'); |
516 |
t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0'); |
517 |
|
518 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor"); |
519 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); |
520 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); |
521 |
ok( !$lostfine, "No lost fine if no replacementcost or default when pref off"); |
522 |
ok( !$procfee, "No processing fee if no processing fee"); |
523 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor"); |
524 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); |
525 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); |
526 |
ok( $lostfine->amount == 6.12, "Lost fine equals replacementcost when pref off and no default set"); |
527 |
ok( !$procfee, "No processing fee if no processing fee"); |
528 |
$lostfine->delete(); |
529 |
|
530 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor"); |
531 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); |
532 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); |
533 |
ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off"); |
534 |
ok( !$procfee, "No processing fee if no processing fee"); |
535 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor"); |
536 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); |
537 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); |
538 |
ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set"); |
539 |
ok( !$procfee, "No processing fee if no processing fee"); |
540 |
$lostfine->delete(); |
541 |
|
542 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor"); |
543 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); |
544 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); |
545 |
ok( !$lostfine, "No lost fine if no replacementcost and no default set when pref off"); |
546 |
ok( $procfee->amount == 8.16, "Processing fee if processing fee"); |
547 |
$procfee->delete(); |
548 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor"); |
549 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); |
550 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); |
551 |
ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and no default set"); |
552 |
ok( $procfee->amount == 8.16, "Processing fee if processing fee"); |
553 |
$lostfine->delete(); |
554 |
$procfee->delete(); |
555 |
|
556 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); |
557 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); |
558 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); |
559 |
ok( !$lostfine, "No lost fine if no replacementcost but default set when pref off"); |
560 |
ok( $procfee->amount == 2.04, "Processing fee if processing fee"); |
561 |
$procfee->delete(); |
562 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); |
563 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); |
564 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); |
565 |
ok( $lostfine->amount == 6.12 , "Lost fine equals replacementcost when pref off and default set"); |
566 |
ok( $procfee->amount == 2.04, "Processing fee if processing fee"); |
567 |
$lostfine->delete(); |
568 |
$procfee->delete(); |
569 |
|
570 |
t::lib::Mocks::mock_preference('useDefaultReplacementCost', '1'); |
571 |
|
572 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 0, "Perdedor"); |
573 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); |
574 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); |
575 |
ok( !$lostfine, "No lost fine if no replacementcost or default when pref on"); |
576 |
ok( !$procfee, "No processing fee if no processing fee"); |
577 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber1, 6.12, "Perdedor"); |
578 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'L' }); |
579 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber1, accounttype => 'PF' }); |
580 |
is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set"); |
581 |
ok( !$procfee, "No processing fee if no processing fee"); |
582 |
|
583 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 0, "Perdedor"); |
584 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); |
585 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); |
586 |
is( $lostfine->amount(), "16.320000", "Lost fine is default if no replacementcost but default set when pref on"); |
587 |
ok( !$procfee, "No processing fee if no processing fee"); |
588 |
$lostfine->delete(); |
589 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber2, 6.12, "Perdedor"); |
590 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'L' }); |
591 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2, accounttype => 'PF' }); |
592 |
is( $lostfine->amount, "6.120000" , "Lost fine equals replacementcost when pref on and default set"); |
593 |
ok( !$procfee, "No processing fee if no processing fee"); |
594 |
|
595 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 0, "Perdedor"); |
596 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); |
597 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); |
598 |
ok( !$lostfine, "No lost fine if no replacementcost and default not set when pref on"); |
599 |
is( $procfee->amount, "8.160000", "Processing fee if processing fee"); |
600 |
$procfee->delete(); |
601 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber3, 6.12, "Perdedor"); |
602 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'L' }); |
603 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3, accounttype => 'PF' }); |
604 |
is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and no default set"); |
605 |
is( $procfee->amount, "8.160000", "Processing fee if processing fee"); |
606 |
|
607 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 0, "Perdedor"); |
608 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); |
609 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); |
610 |
is( $lostfine->amount, "4.080000", "Lost fine is default if no replacementcost but default set when pref on"); |
611 |
is( $procfee->amount, "2.040000", "Processing fee if processing fee"); |
612 |
$lostfine->delete(); |
613 |
$procfee->delete(); |
614 |
C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor"); |
615 |
$lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'L' }); |
616 |
$procfee = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' }); |
617 |
is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set"); |
618 |
is( $procfee->amount, "2.040000", "Processing fee if processing fee"); |
619 |
}; |
620 |
|
481 |
1; |
621 |
1; |