From e0eb579e28583019d72ad79f393a5eba269ede2f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 27 Mar 2019 11:39:30 +0000 Subject: [PATCH] Bug 22521: (QA follow-up) Corrections to tests --- C4/Overdues.pm | 4 +- Koha/Account/Line.pm | 4 +- installer/data/mysql/account_offset_types.sql | 6 +- .../data/mysql/atomicupdate/bug_22521.perl | 27 +++++++++ t/db_dependent/Circulation.t | 10 ++-- t/db_dependent/Koha/Account/Lines.t | 59 +++++++++++-------- 6 files changed, 75 insertions(+), 35 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index e43e7a7afa..7e6c8521ad 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -560,7 +560,7 @@ sub UpdateFine { if ( $accountline ) { if ( $accountline->amount != $amount ) { - $accountline->adjust({ amount => $amount, type => 'fine_update' }); + $accountline->adjust({ amount => $amount, type => 'overdue_update' }); } } else { if ( $amount ) { # Don't add new fines with an amount of 0 @@ -579,7 +579,7 @@ sub UpdateFine { note => undef, user_id => undef, library_id => undef, - type => 'fine', + type => 'overdue', item_id => $itemnum, issue_id => $issue_id, } diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index f0c426e849..2f90029d06 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -284,8 +284,8 @@ sub adjust { my $difference = $amount - $amount_before; my $new_outstanding = $amount_outstanding_before + $difference; - my $offset_type = substr( $update_type, 0, index( $update_type, '_' ) ); - $offset_type .= ( $difference > 0 ) ? "_increase" : "_decrease"; + my $offset_type = $account_type; + $offset_type .= ( $difference > 0 ) ? "_INCREASE" : "_DECREASE"; # Catch cases that require patron refunds if ( $new_outstanding < 0 ) { diff --git a/installer/data/mysql/account_offset_types.sql b/installer/data/mysql/account_offset_types.sql index f2177f0601..78f3a3ba53 100644 --- a/installer/data/mysql/account_offset_types.sql +++ b/installer/data/mysql/account_offset_types.sql @@ -12,8 +12,8 @@ INSERT INTO account_offset_types ( type ) VALUES ('Rental Fee'), ('Reserve Fee'), ('Hold Expired'), -('fine_increase'), -('fine_decrease'), -('Fine'), +('OVERDUE_INCREASE'), +('OVERDUE_DECREASE'), +('OVERDUE'), ('Void Payment'), ('Credit Applied'); diff --git a/installer/data/mysql/atomicupdate/bug_22521.perl b/installer/data/mysql/atomicupdate/bug_22521.perl index a631f4140f..d437db3137 100644 --- a/installer/data/mysql/atomicupdate/bug_22521.perl +++ b/installer/data/mysql/atomicupdate/bug_22521.perl @@ -1,6 +1,33 @@ $DBversion = 'XXX'; # will be replaced by the RM if ( CheckVersion($DBversion) ) { + $dbh->do(qq{ + UPDATE + `account_offset_types` + SET + type = 'OVERDUE' + WHERE + type = 'Fine'; + }); + + $dbh->do(qq{ + UPDATE + `account_offset_types` + SET + type = 'OVERDUE_INCREASE' + WHERE + type = 'fine_increase'; + }); + + $dbh->do(qq{ + UPDATE + `account_offset_types` + SET + type = 'OVERDUE_DECREASE' + WHERE + type = 'fine_decrease'; + }); + if ( column_exists( 'accountlines', 'accounttype' ) ) { $dbh->do( qq{ diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t index fefcbf2ee6..99d6ced91a 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -684,7 +684,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); $account->add_debit( { amount => $fines_amount, - type => 'fine', + type => 'overdue', item_id => $item_to_auto_renew->{itemnumber}, description => "Some fines" } @@ -697,7 +697,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); $account->add_debit( { amount => $fines_amount, - type => 'fine', + type => 'overdue', item_id => $item_to_auto_renew->{itemnumber}, description => "Some fines" } @@ -710,7 +710,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); $account->add_debit( { amount => $fines_amount, - type => 'fine', + type => 'overdue', item_id => $item_to_auto_renew->{itemnumber}, description => "Some fines" } @@ -856,7 +856,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); is( $line->issue_id, $issue->id, 'Account line issue id matches' ); my $offset = Koha::Account::Offsets->search({ debit_id => $line->id })->next(); - is( $offset->type, 'Fine', 'Account offset type is Fine' ); + is( $offset->type, 'OVERDUE', 'Account offset type is Fine' ); is( $offset->amount, '15.000000', 'Account offset amount is 15.00' ); t::lib::Mocks::mock_preference('WhenLostForgiveFine','0'); @@ -2337,7 +2337,7 @@ subtest '_FixAccountForLostAndReturned' => sub { ); my $manual_debit_amount = 80; - $account->add_debit( { amount => $manual_debit_amount, type => 'fine' } ); + $account->add_debit( { amount => $manual_debit_amount, type => 'overdue' } ); is( $account->balance, $manual_debit_amount + $replacement_amount - $payment_amount, 'Manual debit applied' ); diff --git a/t/db_dependent/Koha/Account/Lines.t b/t/db_dependent/Koha/Account/Lines.t index aafda5f43d..1d9c8cfd6e 100755 --- a/t/db_dependent/Koha/Account/Lines.t +++ b/t/db_dependent/Koha/Account/Lines.t @@ -57,7 +57,8 @@ subtest 'item() tests' => sub { { borrowernumber => $patron->{borrowernumber}, itemnumber => $item->itemnumber, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 10, })->store; @@ -84,7 +85,8 @@ subtest 'total_outstanding() tests' => sub { my $debit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 10, amountoutstanding => 10 } @@ -92,7 +94,8 @@ subtest 'total_outstanding() tests' => sub { my $debit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 10, amountoutstanding => 10 } @@ -103,7 +106,8 @@ subtest 'total_outstanding() tests' => sub { my $credit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => -10, amountoutstanding => -10 } @@ -114,7 +118,8 @@ subtest 'total_outstanding() tests' => sub { my $credit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => -10, amountoutstanding => -10 } @@ -125,7 +130,8 @@ subtest 'total_outstanding() tests' => sub { my $credit_3 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => -100, amountoutstanding => -100 } @@ -154,7 +160,8 @@ subtest 'is_credit() and is_debit() tests' => sub { my $debit = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 10, })->store; @@ -177,7 +184,8 @@ subtest 'apply() tests' => sub { my $debit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 10, amountoutstanding => 10 } @@ -185,7 +193,8 @@ subtest 'apply() tests' => sub { my $debit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 100, amountoutstanding => 100 } @@ -246,7 +255,8 @@ subtest 'apply() tests' => sub { my $credit_2 = $account->add_credit({ amount => 20 }); my $debit_3 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 100, amountoutstanding => 100 } @@ -294,7 +304,8 @@ subtest 'Keep account info when related patron, staff or item is deleted' => sub borrowernumber => $patron->borrowernumber, manager_id => $staff->borrowernumber, itemnumber => $item->itemnumber, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 10, })->store; @@ -331,7 +342,8 @@ subtest 'adjust() tests' => sub { my $debit_1 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 10, amountoutstanding => 10 } @@ -339,7 +351,8 @@ subtest 'adjust() tests' => sub { my $debit_2 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "FU", + accounttype => "OVERDUE", + status => "UNRETURNED", amount => 100, amountoutstanding => 100 } @@ -350,12 +363,12 @@ subtest 'adjust() tests' => sub { throws_ok { $debit_1->adjust( { amount => 50, type => 'bad' } ) } qr/Update type not recognised/, 'Exception thrown for unrecognised type'; - throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update' } ) } + throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update' } ) } qr/Update type not allowed on this accounttype/, 'Exception thrown for type conflict'; # Increment an unpaid fine - $debit_2->adjust( { amount => 150, type => 'fine_update' } )->discard_changes; + $debit_2->adjust( { amount => 150, type => 'overdue_update' } )->discard_changes; is( $debit_2->amount * 1, 150, 'Fine amount was updated in full' ); is( $debit_2->amountoutstanding * 1, 150, 'Fine amountoutstanding was update in full' ); @@ -366,7 +379,7 @@ subtest 'adjust() tests' => sub { is( $offsets->count, 1, 'An offset is generated for the increment' ); my $THIS_offset = $offsets->next; is( $THIS_offset->amount * 1, 50, 'Amount was calculated correctly (increment by 50)' ); - is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' ); + is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); is( $schema->resultset('ActionLog')->count(), $action_logs + 0, 'No log was added' ); @@ -382,7 +395,7 @@ subtest 'adjust() tests' => sub { t::lib::Mocks::mock_preference( 'FinesLog', 1 ); # Increment the partially paid fine - $debit_2->adjust( { amount => 160, type => 'fine_update' } )->discard_changes; + $debit_2->adjust( { amount => 160, type => 'overdue_update' } )->discard_changes; is( $debit_2->amount * 1, 160, 'Fine amount was updated in full' ); is( $debit_2->amountoutstanding * 1, 120, 'Fine amountoutstanding was updated by difference' ); @@ -392,12 +405,12 @@ subtest 'adjust() tests' => sub { is( $offsets->count, 3, 'An offset is generated for the increment' ); $THIS_offset = $offsets->last; is( $THIS_offset->amount * 1, 10, 'Amount was calculated correctly (increment by 10)' ); - is( $THIS_offset->type, 'fine_increase', 'Adjust type stored correctly' ); + is( $THIS_offset->type, 'OVERDUE_INCREASE', 'Adjust type stored correctly' ); is( $schema->resultset('ActionLog')->count(), $action_logs + 1, 'Log was added' ); # Decrement the partially paid fine, less than what was paid - $debit_2->adjust( { amount => 50, type => 'fine_update' } )->discard_changes; + $debit_2->adjust( { amount => 50, type => 'overdue_update' } )->discard_changes; is( $debit_2->amount * 1, 50, 'Fine amount was updated in full' ); is( $debit_2->amountoutstanding * 1, 10, 'Fine amountoutstanding was updated by difference' ); @@ -407,10 +420,10 @@ subtest 'adjust() tests' => sub { is( $offsets->count, 4, 'An offset is generated for the decrement' ); $THIS_offset = $offsets->last; is( $THIS_offset->amount * 1, -110, 'Amount was calculated correctly (decrement by 110)' ); - is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' ); + is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' ); # Decrement the partially paid fine, more than what was paid - $debit_2->adjust( { amount => 30, type => 'fine_update' } )->discard_changes; + $debit_2->adjust( { amount => 30, type => 'overdue_update' } )->discard_changes; is( $debit_2->amount * 1, 30, 'Fine amount was updated in full' ); is( $debit_2->amountoutstanding * 1, 0, 'Fine amountoutstanding was zeroed (payment was 40)' ); is( $debit_2->lastincrement * 1, -20, 'lastincrement is the to the right value' ); @@ -419,7 +432,7 @@ subtest 'adjust() tests' => sub { is( $offsets->count, 5, 'An offset is generated for the decrement' ); $THIS_offset = $offsets->last; is( $THIS_offset->amount * 1, -20, 'Amount was calculated correctly (decrement by 20)' ); - is( $THIS_offset->type, 'fine_decrease', 'Adjust type stored correctly' ); + is( $THIS_offset->type, 'OVERDUE_DECREASE', 'Adjust type stored correctly' ); my $overpayment_refund = $account->lines->last; is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' ); @@ -445,7 +458,7 @@ subtest 'checkout() tests' => sub { amount => 10, item_id => $item->itemnumber, issue_id => $checkout->issue_id, - type => 'fine', + type => 'overdue', }); my $line_checkout = $line->checkout; -- 2.20.1