Bug 41311: Add ability for SIP to send patron home library ( branchcode ) in AO field

Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Kyle M Hall 2025-11-26 12:40:52 -05:00 committed by Lucas Gass
parent db1ab86bfe
commit 4310aebeda
No known key found for this signature in database
GPG Key ID: 60B447398B0D36CA
8 changed files with 64 additions and 6 deletions

View File

@ -244,6 +244,7 @@ sub new {
my %fields = (
id => 0,
borrowernumber => 0,
branchcode => 0,
name => 0,
address => 0,
email_addr => 0,

View File

@ -516,6 +516,9 @@ sub build_patron_status {
$resp .= $patron->build_custom_field_string($server);
$resp .= $patron->build_patron_attributes_string($server);
my $branchcode =
$server->{account}->{patron_branchcode_in_ao} ? $patron->branchcode : $fields->{ (FID_INST_ID) };
$resp .= add_field( FID_INST_ID, $branchcode, $server );
} else {
# Invalid patron (cardnumber)
@ -533,9 +536,10 @@ sub build_patron_status {
and $resp .= add_field( FID_VALID_PATRON, 'N', $server );
$resp .= maybe_add( FID_SCREEN_MSG, INVALID_CARD, $server );
$resp .= add_field( FID_INST_ID, $fields->{ (FID_INST_ID) }, $server );
}
$resp .= add_field( FID_INST_ID, $fields->{ (FID_INST_ID) }, $server );
return $resp;
}
@ -1090,7 +1094,8 @@ sub handle_patron_info {
$resp .= add_count( 'patron_info/recall_items', scalar @{ $patron->recall_items } );
$resp .= add_count( 'patron_info/unavail_holds', scalar @{ $patron->unavail_holds } );
$resp .= add_field( FID_INST_ID, ( $ils->institution_id || 'SIP2' ), $server );
my $branchcode = $server->{account}->{patron_branchcode_in_ao} ? $patron->branchcode : $ils->institution_id;
$resp .= add_field( FID_INST_ID, ( $branchcode || 'SIP2' ), $server );
# while the patron ID we got from the SC is valid, let's
# use the one returned from the ILS, just in case...

View File

@ -58,6 +58,11 @@ properties:
type:
- boolean
- 'null'
patron_branchcode_in_ao:
description: patron branchcode in ao
type:
- boolean
- 'null'
cv_send_00_on_success:
description: cv send 00 on success
type:

View File

@ -0,0 +1,19 @@
use Modern::Perl;
use Koha::Installer::Output qw(say_warning say_success say_info);
return {
bug_number => "41311",
description => "Add patron_branchcode_in_ao to sip_accounts table",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
$dbh->do(
q{
ALTER TABLE sip_accounts ADD COLUMN `patron_branchcode_in_ao` tinyint(1) AFTER `send_patron_home_library_in_af`;
}
);
say_success( $out, "Added column 'sip_accounts.patron_branchcode_in_ao'" );
},
};

View File

@ -6214,6 +6214,7 @@ CREATE TABLE `sip_accounts` (
`sip_account_id` int(11) NOT NULL AUTO_INCREMENT,
`sip_institution_id` int(11) NOT NULL COMMENT 'Foreign key to sip_institutions.sip_institution_id',
`ae_field_template` varchar(255) DEFAULT NULL,
`patron_branchcode_in_ao` tinyint(1) DEFAULT 0,
`allow_additional_materials_checkout` tinyint(1) DEFAULT NULL,
`allow_empty_passwords` tinyint(1) DEFAULT NULL,
`allow_fields` varchar(255) DEFAULT NULL,

View File

@ -463,6 +463,16 @@ export default {
hideIn: ["List"],
group: "Details",
},
{
name: "patron_branchcode_in_ao",
type: "boolean",
label: __("Send patron home library in AO"),
hideIn: ["List"],
group: "Details",
toolTip: __(
"Send patron branchcode in AO field for patron status and patron information responses"
),
},
{
name: "show_checkin_message",
type: "boolean",

View File

@ -12,6 +12,7 @@ function get_account() {
convert_nonprinting_characters: "",
cr_item_field: "collection_code",
ct_always_send: false,
patron_branchcode_in_ao: false,
cv_send_00_on_success: false,
cv_triggers_alert: false,
custom_item_fields: [],

View File

@ -64,7 +64,7 @@ subtest 'Testing Patron Status Request V2' => sub {
subtest 'Testing Patron Info Request V2' => sub {
my $schema = Koha::Database->new->schema;
$schema->storage->txn_begin;
plan tests => 32;
plan tests => 35;
$C4::SIP::Sip::protocol_version = 2;
test_request_patron_info_v2();
$schema->storage->txn_rollback;
@ -1070,8 +1070,9 @@ sub test_request_patron_status_v2 {
}
sub test_request_patron_info_v2 {
my $builder = t::lib::TestBuilder->new();
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $builder = t::lib::TestBuilder->new();
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
my $branchcode2 = $builder->build( { source => 'Branch' } )->{branchcode};
my ( $response, $findpatron );
my $mocks = create_mocks( \$response, \$findpatron, \$branchcode );
@ -1079,13 +1080,15 @@ sub test_request_patron_info_v2 {
{
source => 'Borrower',
value => {
password => hash_password(PATRON_PW),
password => hash_password(PATRON_PW),
branchcode => $branchcode2,
},
}
);
my $card = $patron2->{cardnumber};
my $sip_patron2 = C4::SIP::ILS::Patron->new($card);
$findpatron = $sip_patron2;
my $siprequest =
PATRON_INFO
. 'engYYYYMMDDZZZZHHMMSS'
@ -1130,6 +1133,19 @@ sub test_request_patron_info_v2 {
'Check customized patron name'
);
# Test patron_branchcode_in_ao
$server->{account}->{patron_branchcode_in_ao} = "1";
$msg = C4::SIP::Sip::MsgType->new( $siprequest, 0 );
undef $response;
is( $patron2->{branchcode}, $branchcode2, "Patron created with correct home library" );
is( $sip_patron2->branchcode, $branchcode2, "SIP Patron created with correct home library" );
$msg->handle_patron_info($server);
$respcode = substr( $response, 0, 2 );
check_field(
$respcode, $response, FID_INST_ID, $patron2->{branchcode},
"Patron home library is in the AO field( patron = $patron2->{branchcode}, INST = $branchcode"
);
# Test hide_fields
undef $response;
$server->{account}->{hide_fields} = join( ",", FID_HOME_ADDR, FID_EMAIL, FID_HOME_PHONE, FID_PATRON_BIRTHDATE );