Bug 22521: (QA follow-up) Corrections to tests
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 27 Mar 2019 11:39:30 +0000 (11:39 +0000)
committerNick Clemens <nick@bywatersolutions.com>
Wed, 17 Apr 2019 16:49:36 +0000 (16:49 +0000)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/Overdues.pm
Koha/Account/Line.pm
installer/data/mysql/account_offset_types.sql
installer/data/mysql/atomicupdate/bug_22521.perl
t/db_dependent/Circulation.t
t/db_dependent/Koha/Account/Lines.t

index f031ff3..78ec2e5 100644 (file)
@@ -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,
                 }
index 2845bf6..d2ac161 100644 (file)
@@ -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 ) {
index f2177f0..78f3a3b 100644 (file)
@@ -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');
index a631f41..d437db3 100644 (file)
@@ -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{
index fde631e..b8bbcda 100755 (executable)
@@ -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' );
 
index f25bfee..610a342 100755 (executable)
@@ -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;