Bug 31552: SIP2 option format_due_date not honored for AH field in item information...
authorKyle Hall <kyle@bywatersolutions.com>
Mon, 12 Sep 2022 17:52:23 +0000 (13:52 -0400)
committerArthur Suzuki <arthur.suzuki@biblibre.com>
Wed, 14 Dec 2022 15:20:28 +0000 (16:20 +0100)
Bug 28730 added the ability to format due dates based on Koha's date format, but missed formatting the due date field in the item information response.

Test Plan:
1) Apply this patch
2) prove t/db_dependent/SIP/Message.t

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 93e418c0b3e6b41aae99e3bd66664bc0ac94b24f)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 0c7b340508ea2ccecf24f4883b491cb877e57c4d)
Signed-off-by: Arthur Suzuki <arthur.suzuki@biblibre.com>
C4/SIP/Sip/MsgType.pm
t/db_dependent/SIP/Message.t

index d18029d..2152bd1 100644 (file)
@@ -565,12 +565,10 @@ sub handle_checkout {
         $resp .= add_field( FID_ITEM_ID,   $item_id, $server );
         $resp .= add_field( FID_TITLE_ID,  $item->title_id, $server );
         if ( $item->due_date ) {
-            my $due_date;
-            if( $account->{format_due_date} ){
-                $due_date = output_pref({ str => $item->due_date, as_due_date => 1 });
-            } else {
-                $due_date = timestamp( $item->due_date );
-            }
+            my $due_date =
+              $account->{format_due_date}
+              ? output_pref( { str => $item->due_date, as_due_date => 1 } )
+              : timestamp( $item->due_date );
             $resp .= add_field( FID_DUE_DATE, $due_date, $server );
         } else {
             $resp .= add_field( FID_DUE_DATE, q{}, $server );
@@ -1194,10 +1192,11 @@ sub handle_fee_paid {
 
 sub handle_item_information {
     my ( $self, $server ) = @_;
-    my $ils = $server->{ils};
+    my $account = $server->{account};
+    my $ils     = $server->{ils};
+    my $fields  = $self->{fields};
+    my $resp    = ITEM_INFO_RESP;
     my $trans_date;
-    my $fields = $self->{fields};
-    my $resp   = ITEM_INFO_RESP;
     my $item;
     my $i;
 
@@ -1257,7 +1256,11 @@ sub handle_item_information {
             $resp .= add_field( FID_HOLD_QUEUE_LEN, $i, $server );
         }
         if ( $item->due_date ) {
-            $resp .= add_field( FID_DUE_DATE, timestamp( $item->due_date ), $server );
+            my $due_date =
+              $account->{format_due_date}
+              ? output_pref( { str => $item->due_date, as_due_date => 1 } )
+              : timestamp( $item->due_date );
+            $resp .= add_field( FID_DUE_DATE, $due_date, $server );
         }
         if ( ( $i = $item->recall_date ) != 0 ) {
             $resp .= add_field( FID_RECALL_DATE, timestamp($i), $server );
index 7cc113b..df7a462 100755 (executable)
@@ -213,7 +213,7 @@ subtest "Test build_additional_item_fields_string" => sub {
 };
 
 subtest "Test cr_item_field" => sub {
-    plan tests => 2;
+    plan tests => 3;
 
     my $builder = t::lib::TestBuilder->new();
     my $branchcode  = $builder->build({ source => 'Branch' })->{branchcode};
@@ -285,6 +285,18 @@ subtest "Test cr_item_field" => sub {
 
     my $itype = $item_object->itype;
     ok( $response =~ m/CR$itype/, "Found correct CR field in response");
+
+    $server->{account}->{format_due_date} = 1;
+    t::lib::Mocks::mock_preference( 'dateFormat',  'sql' );
+    my $issue = Koha::Checkout->new({ branchcode => $branchcode, borrowernumber => $patron1->{borrowernumber}, itemnumber => $item_object->itemnumber, date_due => "1999-01-01 12:59:00" })->store;
+    $siprequest = ITEM_INFORMATION . 'YYYYMMDDZZZZHHMMSS' .
+        FID_INST_ID . $branchcode . '|'.
+        FID_ITEM_ID . $item_object->barcode . '|' .
+        FID_TERMINAL_PWD . 'ignored' . '|';
+    undef $response;
+    $msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
+    $msg->handle_item_information( $server );
+    ok( $response =~ m/AH1999-01-01 12:59/, "Found correct CR field in response");
 };
 
 subtest 'Patron info summary > 5 should not crash server' => sub {