From e51abd779d5e6a82d10a4339d05534d00ced2365 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Tue, 9 Sep 2025 16:19:24 +0200 Subject: [PATCH] Bug 32748: (follow-up) Fix list behavior if AV is restricted and add itemtype restricted values Signed-off-by: Mathieu Saby --- Koha/UI/Form/Builder/Item.pm | 23 +++++++++++-------- .../prog/en/includes/html_helpers.inc | 12 ++++++++-- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm index a71b563c0b..3b0ec1be11 100644 --- a/Koha/UI/Form/Builder/Item.pm +++ b/Koha/UI/Form/Builder/Item.pm @@ -169,7 +169,7 @@ sub generate_subfield_form { if ( $subfield->{authorised_value} ) { my @authorised_values; my %authorised_lib; - my %authorised_restricted; + my %restricted_values; # builds list, depending on authorised value... if ( $subfield->{authorised_value} eq "LOST" ) { @@ -203,16 +203,22 @@ sub generate_subfield_form { } } elsif ( $subfield->{authorised_value} eq "itemtypes" ) { push @authorised_values, ""; - my $itemtypes; + my $all_itemtypes = Koha::ItemTypes->search_with_localization; + my $filtered_itemtypes; if ($branch_limit) { - $itemtypes = Koha::ItemTypes->search_with_localization( { branchcode => $branch_limit } ); + $filtered_itemtypes = Koha::ItemTypes->search_with_localization( { branchcode => $branch_limit } ); } else { - $itemtypes = Koha::ItemTypes->search_with_localization; + $filtered_itemtypes = $all_itemtypes; } - while ( my $itemtype = $itemtypes->next ) { + while (my $itemtype = $filtered_itemtypes->next) { push @authorised_values, $itemtype->itemtype; $authorised_lib{ $itemtype->itemtype } = $itemtype->translated_description; } + while (my $itemtype = $all_itemtypes->next) { + if (!grep { $_ eq $itemtype->itemtype } @authorised_values) { + $restricted_values{ $itemtype->itemtype } = $itemtype->translated_description; + } + } if ( !$value && $biblionumber ) { my $itype_sth = $dbh->prepare("SELECT itemtype FROM biblioitems WHERE biblionumber = ?"); @@ -249,9 +255,8 @@ sub generate_subfield_form { my $av = GetAuthorisedValues( $subfield->{authorised_value}, undef, { 'no_limit' => 1 } ); for my $r (@$av) { push @authorised_values, $r->{authorised_value}; - - $authorised_lib{ $r->{authorised_value} } = $r->{lib}; - $authorised_restricted{ $r->{authorised_value} } = $r->{restricted}; + $authorised_lib{ $r->{authorised_value} } = $r->{lib}; + $restricted_values{ $r->{authorised_value} } = $r->{restricted}; } } @@ -273,7 +278,7 @@ sub generate_subfield_form { id => "tag_" . $tag . "_subfield_" . $subfieldtag . "_" . $index_subfield, values => \@authorised_values, labels => \%authorised_lib, - restricted => \%authorised_restricted, + restricted => \%restricted_values, default => $value, ( ( grep { $_ eq $subfield->{authorised_value} } (qw(branches itemtypes cn_source)) ) diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc index a0716f8416..f94e3307ab 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc @@ -135,13 +135,21 @@ [% ELSIF subfield.IS_LOST_AV && Koha.Preference("BundleLostValue") && aval == Koha.Preference("BundleLostValue") %] [% ELSE %] - + [% UNLESS mv.restricted.$aval %] + + [% END %] [% END %] [% END %] [% END %] [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %] [%# If the current value is not in the authorised list and is not a field where 0 means unset #%] - + [% IF mv.restricted %] + [% FOREACH code IN mv.restricted.keys %] + [% IF mv.default == code %] + + [% END %] + [% END %] + [% END %] [% END %] [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %] -- 2.39.5