From a6ba3bcc0d63784296d73a292780a994c2d09070 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 Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Nick Clemens --- 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 f031ff3999..78ec2e57fa 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -564,7 +564,7 @@ sub UpdateFine { $accountline->adjust( { amount => $amount, - type => 'fine_update', + type => 'overdue_update', interface => C4::Context->interface } ); @@ -587,7 +587,7 @@ sub UpdateFine { user_id => undef, interface => C4::Context->interface, library_id => undef, #FIXME: Should we grab the checkout or circ-control branch here perhaps? - type => 'fine', + type => 'overdue', item_id => $itemnum, issue_id => $issue_id, } diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index 2845bf6f2f..d2ac161e82 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -286,8 +286,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 fde631e40c..b8bbcda08c 100755 --- a/t/db_dependent/Circulation.t +++ b/t/db_dependent/Circulation.t @@ -692,7 +692,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); { amount => $fines_amount, interface => 'test', - type => 'fine', + type => 'overdue', item_id => $item_to_auto_renew->{itemnumber}, description => "Some fines" } @@ -706,7 +706,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); { amount => $fines_amount, interface => 'test', - type => 'fine', + type => 'overdue', item_id => $item_to_auto_renew->{itemnumber}, description => "Some fines" } @@ -720,7 +720,7 @@ my ( $reused_itemnumber_1, $reused_itemnumber_2 ); { amount => $fines_amount, interface => 'test', - type => 'fine', + type => 'overdue', item_id => $item_to_auto_renew->{itemnumber}, description => "Some fines" } @@ -865,7 +865,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'); @@ -2421,7 +2421,7 @@ subtest '_FixAccountForLostAndReturned' => sub { ); my $manual_debit_amount = 80; - $account->add_debit( { amount => $manual_debit_amount, type => 'fine', interface =>'test' } ); + $account->add_debit( { amount => $manual_debit_amount, type => 'overdue', interface =>'test' } ); 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 f25bfee410..610a342b3a 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, interface => 'commandline', })->store; @@ -85,7 +86,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, interface => 'commandline', @@ -94,7 +96,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, interface => 'commandline', @@ -106,7 +109,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, interface => 'commandline', @@ -118,7 +122,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, interface => 'commandline', @@ -130,7 +135,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, interface => 'commandline', @@ -160,7 +166,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, interface => 'commandline', })->store; @@ -184,7 +191,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, interface => 'commandline', @@ -193,7 +201,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, interface => 'commandline', @@ -255,7 +264,8 @@ subtest 'apply() tests' => sub { my $credit_2 = $account->add_credit({ amount => 20, interface => 'commandline' }); my $debit_3 = Koha::Account::Line->new( { borrowernumber => $patron->id, - accounttype => "F", + accounttype => "OVERDUE", + status => "RETURNED", amount => 100, amountoutstanding => 100, interface => 'commandline', @@ -304,7 +314,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, interface => 'commandline', })->store; @@ -342,7 +353,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, interface => 'commandline', @@ -351,7 +363,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, interface => 'commandline' @@ -363,12 +376,12 @@ subtest 'adjust() tests' => sub { throws_ok { $debit_1->adjust( { amount => 50, type => 'bad', interface => 'commandline' } ) } qr/Update type not recognised/, 'Exception thrown for unrecognised type'; - throws_ok { $debit_1->adjust( { amount => 50, type => 'fine_update', interface => 'commandline' } ) } + throws_ok { $debit_1->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } ) } 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', interface => 'commandline' } )->discard_changes; + $debit_2->adjust( { amount => 150, type => 'overdue_update', interface => 'commandline' } )->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' ); @@ -378,7 +391,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' ); @@ -394,7 +407,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', interface => 'commandline' } )->discard_changes; + $debit_2->adjust( { amount => 160, type => 'overdue_update', interface => 'commandline' } )->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' ); @@ -403,12 +416,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', interface => 'commandline' } )->discard_changes; + $debit_2->adjust( { amount => 50, type => 'overdue_update', interface => 'commandline' } )->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' ); @@ -417,10 +430,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', interface => 'commandline' } )->discard_changes; + $debit_2->adjust( { amount => 30, type => 'overdue_update', interface => 'commandline' } )->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)' ); @@ -428,7 +441,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' ); @@ -455,7 +468,7 @@ subtest 'checkout() tests' => sub { interface => 'commandline', item_id => $item->itemnumber, issue_id => $checkout->issue_id, - type => 'fine', + type => 'overdue', }); my $line_checkout = $line->checkout; -- 2.39.5