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

(-)a/C4/Accounts.pm (-3 / +4 lines)
Lines 71-77 FIXME : if no replacement price, borrower just doesn't get charged? Link Here
71
71
72
=cut
72
=cut
73
73
74
sub chargelostitem{
74
sub chargelostitem {
75
    my $dbh = C4::Context->dbh();
75
    my $dbh = C4::Context->dbh();
76
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
76
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
77
    my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() });
77
    my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() });
Lines 83-88 sub chargelostitem{ Link Here
83
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
83
    if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
84
        $replacementprice = $defaultreplacecost;
84
        $replacementprice = $defaultreplacecost;
85
    }
85
    }
86
    my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
87
    my $issue_id = $checkout ? $checkout->issue_id : undef;
86
88
87
    my $account = Koha::Account->new({ patron_id => $borrowernumber });
89
    my $account = Koha::Account->new({ patron_id => $borrowernumber });
88
    # first make sure the borrower hasn't already been charged for this item
90
    # first make sure the borrower hasn't already been charged for this item
Lines 92-104 sub chargelostitem{ Link Here
92
        {
94
        {
93
            itemnumber     => $itemnumber,
95
            itemnumber     => $itemnumber,
94
            accounttype    => 'LOST',
96
            accounttype    => 'LOST',
97
            issue_id       => $issue_id
95
        }
98
        }
96
    )->count();
99
    )->count();
97
100
98
    # OK, they haven't
101
    # OK, they haven't
99
    unless ($existing_charges) {
102
    unless ($existing_charges) {
100
        my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
101
        my $issue_id = $checkout ? $checkout->issue_id : undef;
102
        #add processing fee
103
        #add processing fee
103
        if ($processfee && $processfee > 0){
104
        if ($processfee && $processfee > 0){
104
            my $accountline = $account->add_debit(
105
            my $accountline = $account->add_debit(
(-)a/t/db_dependent/Accounts.t (-6 / +20 lines)
Lines 32-37 use Koha::Notice::Messages; Link Here
32
use Koha::Notice::Templates;
32
use Koha::Notice::Templates;
33
use Koha::DateUtils qw( dt_from_string );
33
use Koha::DateUtils qw( dt_from_string );
34
34
35
use C4::Circulation qw( MarkIssueReturned );
36
35
BEGIN {
37
BEGIN {
36
    use_ok('C4::Accounts');
38
    use_ok('C4::Accounts');
37
    use_ok('Koha::Object');
39
    use_ok('Koha::Object');
Lines 569-580 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
569
    my $cli_issue_id_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2 } })->{issue_id};
571
    my $cli_issue_id_2 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber2 } })->{issue_id};
570
    my $cli_issue_id_3 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3 } })->{issue_id};
572
    my $cli_issue_id_3 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber3 } })->{issue_id};
571
    my $cli_issue_id_4 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
573
    my $cli_issue_id_4 = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
574
    my $cli_issue_id_4X = undef;
572
575
573
    my $lostfine;
576
    my $lostfine;
574
    my $procfee;
577
    my $procfee;
575
578
576
    subtest "fee application tests" => sub {
579
    subtest "fee application tests" => sub {
577
        plan tests => 40;
580
        plan tests => 44;
578
581
579
        t::lib::Mocks::mock_preference('item-level_itypes', '1');
582
        t::lib::Mocks::mock_preference('item-level_itypes', '1');
580
        t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
583
        t::lib::Mocks::mock_preference('useDefaultReplacementCost', '0');
Lines 688-695 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
688
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
691
        is( $lostfine->amount, "6.120000", "Lost fine equals replacementcost when pref on and default set");
689
        is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
692
        is( $procfee->amount, "2.040000",  "Processing fee if processing fee");
690
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
693
        is( $procfee->issue_id, $cli_issue_id_4, "Processing fee issue id is correct" );
691
        $lostfine->delete();
694
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
692
        $procfee->delete();
695
        my $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
696
        my $procfees  = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
697
        ok( $lostfines->count == 1 , "Lost fine cannot be double charged for the same issue_id");
698
        ok( $procfees->count == 1,  "Processing fee cannot be double charged for the same issue_id");
699
        MarkIssueReturned($cli_borrowernumber, $cli_itemnumber4);
700
        $cli_issue_id_4X = $builder->build({ source => 'Issue', value => { borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4 } })->{issue_id};
701
        C4::Accounts::chargelostitem( $cli_borrowernumber, $cli_itemnumber4, 6.12, "Perdedor");
702
        $lostfines = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
703
        $procfees  = Koha::Account::Lines->search({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
704
        ok( $lostfines->count == 2 , "Lost fine can be charged twice for the same item if they are distinct issue_id's");
705
        ok( $procfees->count == 2,  "Processing fee can be charged twice for the same item if they are distinct issue_id's");
706
        $lostfines->delete();
707
        $procfees->delete();
693
    };
708
    };
694
709
695
    subtest "basic fields tests" => sub {
710
    subtest "basic fields tests" => sub {
Lines 702-708 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
702
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
717
        $lostfine = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'LOST' });
703
        ok($lostfine, "Lost fine created");
718
        ok($lostfine, "Lost fine created");
704
        is($lostfine->manager_id, $staff_id, "Lost fine manager_id set correctly");
719
        is($lostfine->manager_id, $staff_id, "Lost fine manager_id set correctly");
705
        is($lostfine->issue_id, $cli_issue_id_4, "Lost fine issue_id set correctly");
720
        is($lostfine->issue_id, $cli_issue_id_4X, "Lost fine issue_id set correctly");
706
        is($lostfine->description, "Perdedor", "Lost fine issue_id set correctly");
721
        is($lostfine->description, "Perdedor", "Lost fine issue_id set correctly");
707
        is($lostfine->note, '', "Lost fine does not contain a note");
722
        is($lostfine->note, '', "Lost fine does not contain a note");
708
        is($lostfine->branchcode, $branchcode, "Lost fine branchcode set correctly");
723
        is($lostfine->branchcode, $branchcode, "Lost fine branchcode set correctly");
Lines 711-717 subtest "C4::Accounts::chargelostitem tests" => sub { Link Here
711
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
726
        $procfee  = Koha::Account::Lines->find({ borrowernumber => $cli_borrowernumber, itemnumber => $cli_itemnumber4, accounttype => 'PF' });
712
        ok($procfee, "Processing fee created");
727
        ok($procfee, "Processing fee created");
713
        is($procfee->manager_id, $staff_id, "Processing fee manager_id set correctly");
728
        is($procfee->manager_id, $staff_id, "Processing fee manager_id set correctly");
714
        is($procfee->issue_id, $cli_issue_id_4, "Processing fee issue_id set correctly");
729
        is($procfee->issue_id, $cli_issue_id_4X, "Processing fee issue_id set correctly");
715
        is($procfee->description, "Perdedor", "Processing fee issue_id set correctly");
730
        is($procfee->description, "Perdedor", "Processing fee issue_id set correctly");
716
        is($procfee->note, C4::Context->preference("ProcessingFeeNote"), "Processing fee contains note matching ProcessingFeeNote");
731
        is($procfee->note, C4::Context->preference("ProcessingFeeNote"), "Processing fee contains note matching ProcessingFeeNote");
717
        is($procfee->branchcode, $branchcode, "Processing fee branchcode set correctly");
732
        is($procfee->branchcode, $branchcode, "Processing fee branchcode set correctly");
718
- 

Return to bug 22563