Bug 25596: Identify overpayment refunds for translation
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 9 Sep 2020 13:34:34 +0000 (14:34 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 25 Oct 2020 23:14:41 +0000 (00:14 +0100)
This patch ensures we can uniquely identify automatic overpayment refund
credits from the accountlines by introducing a new account credit type
and adding appropriate translations for the new code.

Test plan
1/ You'll need an overpayment refund to start...
1a/ Issue yourself and item and set the date due early enough
to create an overdue fine for at least 2 days worth of overdue fines
1b/ Run the fines.pl script to add the fines
1c/ As a patron, pay off the accruing fine
1d/ Return the item ensuring you backdate it at least a day
1e/ Check that there is an 'Overpayment refund' credit on the patrons
account.
2/ Check that the overpayment string is translatable (i.e. it appears in
the accounts include file)

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Caroline Cyr La Rose <caroline.cyr-la-rose@inlibro.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Account.pm
Koha/Account/Line.pm
installer/data/mysql/atomicupdate/bug_25596.perl [new file with mode: 0644]
installer/data/mysql/mandatory/account_credit_types.sql
installer/data/mysql/mandatory/account_offset_types.sql
koha-tmpl/intranet-tmpl/prog/en/includes/accounts.inc
koha-tmpl/opac-tmpl/bootstrap/en/includes/account-table.inc
t/db_dependent/Koha/Account/Line.t

index 5178d98..b4838bc 100644 (file)
@@ -361,6 +361,8 @@ $credit_type can be any of:
   - 'PAYMENT'
   - 'FORGIVEN'
   - 'LOST_FOUND'
+  - 'OVERPAYMENT'
+  - 'PAYMENT'
   - 'WRITEOFF'
 
 =cut
@@ -776,6 +778,7 @@ our $offset_type = {
     'CREDIT'           => 'Manual Credit',
     'FORGIVEN'         => 'Writeoff',
     'LOST_FOUND'       => 'Lost Item Found',
+    'OVERPAYMENT'      => 'Overpayment',
     'PAYMENT'          => 'Payment',
     'WRITEOFF'         => 'Writeoff',
     'ACCOUNT'          => 'Account Fee',
index 98d7ef3..8772942 100644 (file)
@@ -695,8 +695,7 @@ sub adjust {
                 my $credit = $account->add_credit(
                     {
                         amount      => $new_outstanding * -1,
-                        description => 'Overpayment refund',
-                        type        => 'CREDIT',
+                        type        => 'OVERPAYMENT',
                         interface   => $interface,
                         ( $update_type eq 'overdue_update' ? ( item_id => $self->itemnumber ) : ()),
                     }
diff --git a/installer/data/mysql/atomicupdate/bug_25596.perl b/installer/data/mysql/atomicupdate/bug_25596.perl
new file mode 100644 (file)
index 0000000..faa7493
--- /dev/null
@@ -0,0 +1,25 @@
+$DBversion = 'XXX';    # will be replaced by the RM
+if ( CheckVersion($DBversion) ) {
+
+    $dbh->do(
+        qq{
+            INSERT IGNORE INTO account_credit_types (code, description, can_be_added_manually, is_system)
+            VALUES
+              ('OVERPAYMENT', 'Overpayment refund', 0, 1)
+        }
+    );
+
+    $dbh->do(
+        qq{
+            INSERT IGNORE INTO account_offset_types ( type ) VALUES ('Overpayment');
+        }
+    );
+
+    $dbh->do(
+        qq{
+            UPDATE accountlines SET credit_type_code = 'OVERPAYMENT' WHERE credit_type_code = 'CREDIT' AND description = 'Overpayment refund'
+        }
+    );
+
+    NewVersion( $DBversion, 25596, "Add OVERPAYMENT credit type" );
+}
index 178b98b..d7d8a5b 100644 (file)
@@ -1,4 +1,5 @@
 INSERT INTO account_credit_types ( code, description, can_be_added_manually, is_system ) VALUES
+('OVERPAYMENT', 'Overpayment refund', 0, 1),
 ('PAYMENT', 'Payment', 0, 1),
 ('WRITEOFF', 'Writeoff', 0, 1),
 ('FORGIVEN', 'Forgiven', 1, 1),
index c27a689..1f4f24c 100644 (file)
@@ -14,6 +14,7 @@ INSERT INTO account_offset_types ( type ) VALUES
 ('Rental Fee'),
 ('Reserve Fee'),
 ('Hold Expired'),
+('Overpayment'),
 ('OVERDUE_INCREASE'),
 ('OVERDUE_DECREASE'),
 ('OVERDUE'),
index 62ea570..2fb08ab 100644 (file)
@@ -7,6 +7,7 @@
             [%- CASE 'FORGIVEN'         -%]Forgiven
             [%- CASE 'CREDIT'           -%]Credit
             [%- CASE 'LOST_FOUND'       -%]Lost item fee refund
+            [%- CASE 'OVERPAYMENT'      -%]Overpayment refund
             [%- CASE 'REFUND'           -%]Refund
             [%- CASE                    -%][% account.credit_type.description | html %]
         [%- END -%]
index 54fd662..70f8358 100644 (file)
                 [%- CASE 'FORGIVEN'         -%]Forgiven
                 [%- CASE 'CREDIT'           -%]Credit
                 [%- CASE 'LOST_FOUND'       -%]Lost item fee refund
+                [%- CASE 'OVERPAYMENT'      -%]Overpayment refund
                 [%- CASE 'REFUND'           -%]Refund
                 [%- CASE                    -%][% account.credit_type.description | html %]
             [%- END -%]
index 1831346..81b5366 100755 (executable)
@@ -570,7 +570,7 @@ subtest 'adjust() tests' => sub {
 
     my $overpayment_refund = $account->lines->last;
     is( $overpayment_refund->amount * 1, -10, 'A new credit has been added' );
-    is( $overpayment_refund->description, 'Overpayment refund', 'Credit generated with the expected description' );
+    is( $overpayment_refund->credit_type_code, 'OVERPAYMENT', 'Credit generated with the expected credit_type_code' );
 
     $schema->storage->txn_rollback;
 };