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