Bug 30642: Record renewal type
authorMatt Blenkinsop <matt.blenkinsop@ptfs-europe.com>
Tue, 6 Dec 2022 16:48:45 +0000 (16:48 +0000)
committerTomas Cohen Arazi <tomascohen@theke.io>
Fri, 10 Feb 2023 14:07:57 +0000 (11:07 -0300)
A requirement has been requested to record whether a renewal was done manually or automatically. A column has been added to the checkout_renewals table in the database to record this and a check is now in place to determine whether the renewal was manual or automatic. The API has also been updated to reflect this new column and return the data when requested. The renewals modal view has also been updated to show what type the renewal was.

Test plan:
1) In the database shell run "show columns from checkout_renewals;" and observe that there is currently no column for recording the type of renewal
2) Apply patch
3) In the shell run "dbic" and "perl installer/data/mysql/updatedatabase.pl" to update the database schema with the new column.
4) Create some checkouts
5) Renew some checkouts manually and observe in the database that there is now a column called "renewal_type" that will have recorded these as "Manual"
6) Create some checkouts that can be automatically renewed
7) Run the cron script in automatic_renewals.pl and observe that there are now also entries with a renewal_type of "Automatic"
8) Send a GET request to http://localhost:8081/api/v1/checkouts/1/renewals and observe that the renewal_type is now returned in the response
9) In the Item Details tab for a record, there is the "Current renewals" option which has a button to view renewals. Click on this and observe that the modal now displays the new information.

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
C4/Circulation.pm
Koha/Schema/Result/CheckoutRenewal.pm
api/v1/swagger/definitions/renewal.yaml
installer/data/mysql/atomicupdate/bug_30642-add_renewal_type.pl [new file with mode: 0644]
installer/data/mysql/kohastructure.sql
koha-tmpl/intranet-tmpl/prog/en/includes/str/checkout_renewals.inc
koha-tmpl/intranet-tmpl/prog/js/checkout_renewals_modal.js

index 6fcd491..068093e 100644 (file)
@@ -3068,6 +3068,9 @@ sub AddRenewal {
     my $issue  = $item_object->checkout;
     my $item_unblessed = $item_object->unblessed;
 
+    my ($package, $filename, $line) = caller;
+    my $renewal_type = $filename =~ m/automatic_renewals.pl/ ? "Automatic" : "Manual";
+
     my $dbh = C4::Context->dbh;
 
     return unless $issue;
@@ -3206,7 +3209,8 @@ sub AddRenewal {
                 checkout_id => $issue->issue_id,
                 renewer_id  => C4::Context->userenv ? C4::Context->userenv->{'number'} : undef,
                 seen        => $seen,
-                interface   => C4::Context->interface
+                interface   => C4::Context->interface,
+                renewal_type => $renewal_type
             }
         )->store();
 
index bf3cbe1..9efbd93 100644 (file)
@@ -69,6 +69,14 @@ the interface this renewal took place on
 
 the date and time the renewal took place
 
+=head2 renewal_type
+
+  data_type: 'varchar'
+  is_nullable: 0
+  size: 9
+
+whether the renewal was an automatic or manual renewal
+
 =cut
 
 __PACKAGE__->add_columns(
@@ -89,6 +97,8 @@ __PACKAGE__->add_columns(
     default_value => \"current_timestamp",
     is_nullable => 0,
   },
+  "renewal_type",
+  { data_type => "varchar", is_nullable => 0, size => 9 },
 );
 
 =head1 PRIMARY KEY
@@ -126,8 +136,8 @@ __PACKAGE__->belongs_to(
 );
 
 
-# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-04-27 19:43:17
-# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:7mjiEx634L5FZyjroACUkg
+# Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-12-06 16:44:53
+# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BcbN0Iceh09H2DWEA6CDwA
 
 =head2 checkout
 
index 95e6d94..895fe48 100644 (file)
@@ -28,6 +28,10 @@ properties:
   timestamp:
     type: string
     description: Last update time
+  renewal_type:
+    type:
+      - string
+      - "null"
   renewer:
     type:
       - object
diff --git a/installer/data/mysql/atomicupdate/bug_30642-add_renewal_type.pl b/installer/data/mysql/atomicupdate/bug_30642-add_renewal_type.pl
new file mode 100644 (file)
index 0000000..cc86ed1
--- /dev/null
@@ -0,0 +1,18 @@
+use Modern::Perl;
+
+return {
+    bug_number => "BUG_30642",
+    description => "Record whether a renewal has been done manually or automatically.",
+    up => sub {
+        my ($args) = @_;
+        my ($dbh, $out) = @$args{qw(dbh out)};
+
+        if( !column_exists( 'checkout_renewals', 'renewal_type' ) ) {
+          $dbh->do(q{
+              ALTER TABLE checkout_renewals ADD COLUMN `renewal_type` varchar(9) NOT NULL AFTER `timestamp`
+          });
+
+          say $out "Added column 'checkout_renewals.column_name'";
+        }
+    },
+};
\ No newline at end of file
index df66cee..fbd6539 100644 (file)
@@ -1714,6 +1714,7 @@ CREATE TABLE `checkout_renewals` (
   `seen` tinyint(1) DEFAULT 0 COMMENT 'boolean denoting whether the item was present or not',
   `interface` varchar(16) NOT NULL COMMENT 'the interface this renewal took place on',
   `timestamp` timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'the date and time the renewal took place',
+  `renewal_type` varchar(9) NOT NULL COMMENT 'whether the renewal was an automatic or manual renewal',
   PRIMARY KEY (`renewal_id`),
   KEY `renewer_id` (`renewer_id`),
   CONSTRAINT `renewals_renewer_id` FOREIGN KEY (`renewer_id`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
index a8dfcde..3dc7138 100644 (file)
@@ -2,4 +2,5 @@
 <script>
     var renewed_prop = _("Note: %s out of %s renewals have been logged");
     var renewed = _("Renewed by");
+    var renewed_type = _(" Renewal type:");
 </script>
index d6448eb..4ca4c6c 100644 (file)
@@ -20,6 +20,6 @@ $(document).ready(function(){
         });
     });
     function createLi(renewal) {
-        return '<li><span style="font-weight:bold">' + $datetime(renewal.timestamp) + '</span> ' + renewed + ' <span style="font-weight:bold">' + $patron_to_html(renewal.renewer) + '</span></li>';
+        return '<li><span style="font-weight:bold">' + $datetime(renewal.timestamp) + '</span> ' + renewed + ' <span style="font-weight:bold">' + $patron_to_html(renewal.renewer) + '</span>' + renewed_type + ' <span style="font-weight:bold">' + renewal.renewal_type + '</span></li>';
     }
 });