@@ -, +, @@ --- t/db_dependent/Overdues.t | 42 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) --- a/t/db_dependent/Overdues.t +++ a/t/db_dependent/Overdues.t @@ -132,7 +132,7 @@ $schema->storage->txn_rollback; subtest 'UpdateFine tests' => sub { - plan tests => 25; + plan tests => 43; $schema->storage->txn_begin; @@ -185,6 +185,7 @@ subtest 'UpdateFine tests' => sub { is( $fines->count, 1, "Fine added when amount is greater than 0" ); my $fine = $fines->next; is( $fine->amount, '50.000000', "Fine amount correctly set to 50" ); + is( $fine->amountoutstanding, '50.000000', "Fine amountoutstanding correctly set to 50" ); is( $fine->issue_id, $checkout1->issue_id, "Fine is associated with the correct issue" ); is( $fine->itemnumber, $checkout1->itemnumber, "Fine is associated with the correct item" ); @@ -204,6 +205,7 @@ subtest 'UpdateFine tests' => sub { is( $fines->count, 1, "Existing fine updated" ); $fine = $fines->next; is( $fine->amount, '80.000000', "Fine amount correctly updated to 80" ); + is( $fine->amountoutstanding, '80.000000', "Fine amountoutstanding correctly updated to 80" ); # Add fine 2 UpdateFine( @@ -223,13 +225,15 @@ subtest 'UpdateFine tests' => sub { is( $fines->count, 2, "New fine added for second checkout" ); $fine = $fines->next; is( $fine->amount, '80.000000', "First fine amount unchanged" ); + is( $fine->amountoutstanding, '80.000000', "First fine amountoutstanding unchanged" ); my $fine2 = $fines->next; is( $fine2->amount, '20.000000', "Second fine capped at '20' by MaxFine" ); + is( $fine2->amountoutstanding, '20.000000', "Second fine amountoutstanding capped at '20' by MaxFine" ); is( $fine2->issue_id, $checkout2->issue_id, "Second fine is associated with the correct issue" ); is( $fine2->itemnumber, $checkout2->itemnumber, "Second fine is associated with the correct item" ); # Partial pay fine 1 - $fine->amountoutstanding('50')->store; + $fine->amountoutstanding('50.000000')->store; UpdateFine( { issue_id => $checkout2->issue_id, @@ -247,8 +251,10 @@ subtest 'UpdateFine tests' => sub { is( $fines->count, 2, "Still two fines after second checkout update" ); $fine = $fines->next; is( $fine->amount, '80.000000', "First fine amount unchanged" ); + is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" ); $fine2 = $fines->next; is( $fine2->amount, '30.000000', "Second fine increased after partial payment of first" ); + is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding increased after partial payment of first" ); # Fix fine 1, create third fine $fine->status('RETURNED')->store; @@ -269,10 +275,42 @@ subtest 'UpdateFine tests' => sub { is( $fines->count, 3, "Third fine added for overdue renewal" ); $fine = $fines->next; is( $fine->amount, '80.000000', "First fine amount unchanged" ); + is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" ); $fine2 = $fines->next; is( $fine2->amount, '30.000000', "Second fine amount unchanged" ); + is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding unchanged" ); my $fine3 = $fines->next; is( $fine3->amount, '20.000000', "Third fine amount capped due to MaxFine" ); + is( $fine3->amountoutstanding, '20.000000', "Third fine amountoutstanding capped at '20' by MaxFine" ); + is( $fine3->issue_id, $checkout1->issue_id, "Third fine is associated with the correct issue" ); + is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" ); + + # Payoff accruing fine and ensure next increment doesn't create a new one (bug #24146) + $fine3->amountoutstanding('0.000000')->store; + UpdateFine( + { + issue_id => $checkout1->issue_id, + itemnumber => $item1->itemnumber, + borrowernumber => $patron->borrowernumber, + amount => '50', + due => $checkout1->date_due + } + ); + + $fines = Koha::Account::Lines->search( + { borrowernumber => $patron->borrowernumber }, + { order_by => { '-asc' => 'accountlines_id' } } + ); + is( $fines->count, 3, "Still three fines after third checkout update" ); + $fine = $fines->next; + is( $fine->amount, '80.000000', "First fine amount unchanged" ); + is( $fine->amountoutstanding, '50.000000', "First fine amountoutstanding unchanged" ); + $fine2 = $fines->next; + is( $fine2->amount, '30.000000', "Second fine amount unchanged" ); + is( $fine2->amountoutstanding, '30.000000', "Second fine amountoutstanding unchanged" ); + $fine3 = $fines->next; + is( $fine3->amount, '50.000000', "Third fine amount capped due to MaxFine" ); + is( $fine3->amountoutstanding, '20.000000', "Third fine amountoutstanding increased ..." ); is( $fine3->issue_id, $checkout1->issue_id, "Third fine is associated with the correct issue" ); is( $fine3->itemnumber, $checkout1->itemnumber, "Third fine is associated with the correct item" ); --