From 93e418c0b3e6b41aae99e3bd66664bc0ac94b24f Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Mon, 12 Sep 2022 13:52:23 -0400 Subject: [PATCH] Bug 31552: SIP2 option format_due_date not honored for AH field in item information response 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 Signed-off-by: Katrin Fischer Signed-off-by: Tomas Cohen Arazi --- C4/SIP/Sip/MsgType.pm | 23 +++++++++++++---------- t/db_dependent/SIP/Message.t | 14 +++++++++++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index fb4322f21c..cad82e0b35 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -574,12 +574,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 ); @@ -1203,10 +1201,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; @@ -1266,7 +1265,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 ); diff --git a/t/db_dependent/SIP/Message.t b/t/db_dependent/SIP/Message.t index a4d787d8ee..e985c3e27a 100755 --- a/t/db_dependent/SIP/Message.t +++ b/t/db_dependent/SIP/Message.t @@ -296,7 +296,7 @@ subtest "Test build_custom_field_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}; @@ -368,6 +368,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 { -- 2.39.5