From f55989f2dd011f9fa988f0e26fc52b7a302bf481 Mon Sep 17 00:00:00 2001
From: Thibaud Guillot <thibaud.guillot@biblibre.com>
Date: Thu, 16 Mar 2023 10:25:35 +0100
Subject: [PATCH] Bug 33276: Get auth values for location on serials

Serial location is linked to a library, if we want to modify serial
with users does not belongs to, location is not in select and we could
erase it.

Test plan:

1) Be sure to have a LOC authorized value limited to one library at
least
2) See when editing serial subscription you didn't get the current
location
3) Apply this patch
4) Refresh and now you've got the value

Signed-off-by: Clemens Tubach <clemens.tubach@kit.edu>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

https://bugs.koha-community.org/show_bug.cgi?id=21548
---
 serials/subscription-add.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/serials/subscription-add.pl b/serials/subscription-add.pl
index c08142b897..700c815a05 100755
--- a/serials/subscription-add.pl
+++ b/serials/subscription-add.pl
@@ -124,6 +124,19 @@ if ($op eq 'modify' || $op eq 'dup' || $op eq 'modsubscription') {
 
 my $locations_loop = GetAuthorisedValues("LOC");
 my $ccodes_loop     = GetAuthorisedValues("CCODE");
+my @loc_av;
+
+for my $loc (@$locations_loop) {
+    push @loc_av, $loc->{authorised_value};
+}
+
+if ( !grep { $_ eq $subs->{location} } @loc_av ) {
+    my $location_av = Koha::AuthorisedValues->search(
+        { authorised_value => $subs->{location} } )->next;
+    if ($location_av) {
+        push @$locations_loop, $location_av;
+    }
+}
 
 $template->param(
     branchcode => $subs->{branchcode},
-- 
2.30.2