From a29221cf573db59451498de4f5b85f7738bb9e3c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Aug 2020 11:36:34 +0200 Subject: [PATCH] Bug 8675: Display vendor's name when cataloguing items If items.booksellerid is mapped to a MARC field (952$e, Source of acquisition) then we could display a dropdown list with the list of vendors when items are edited. *However* we could have a weird display if it does not match the vendor from which the items have been effectively ordered within Koha. You could then see "Vendor X" in the cataloguing items view (additem.pl), but "Vendor Y" on the item list (moredetail.pl) Is this patch relevant? Test plan: Order and receive an item Edit the item and note the new dropdown list for "Source of acquisition" Note that the items table has replaced the value with the name of the vendor's name as well Signed-off-by: Brandon J https://bugs.koha-community.org/show_bug.cgi?id=8676 --- C4/Biblio.pm | 5 +++++ cataloguing/additem.pl | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index da86e62fdd..6b43c2e81e 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -97,6 +97,7 @@ use C4::Debug; use Koha::Caches; use Koha::Authority::Types; +use Koha::Acquisition::Booksellers; use Koha::Acquisition::Currencies; use Koha::Biblio::Metadatas; use Koha::Holds; @@ -1362,6 +1363,10 @@ descriptions rather than normal ones when they exist. sub GetAuthorisedValueDesc { my ( $tag, $subfield, $value, $framework, $tagslib, $category, $opac ) = @_; + if ( $tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.booksellerid' ) { + my $vendor = Koha::Acquisition::Booksellers->find($value); + return $vendor ? $vendor->name : $value; + } if ( !$category ) { return $value unless defined $tagslib->{$tag}->{$subfield}->{'authorised_value'}; diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index bbdedf6d1d..022d04c09d 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -335,7 +335,25 @@ sub generate_subfield_form { id => $subfield_data{id}, value => $value, }; - } else { + } + elsif ($value && $subfieldlib->{kohafield} eq 'items.booksellerid' ) { + # It's linked with items.booksellerid (expected for "Source of acquisition") + my $vendors = Koha::Acquisition::Booksellers->search; + my @authorised_values; + my %authorised_lib; + while ( my $vendor = $vendors->next ) { + push @authorised_values, $vendor->id; + $authorised_lib{$vendor->id} = $vendor->name; + } + $subfield_data{marc_value} = { + type => 'select', + id => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield, + values => \@authorised_values, + labels => \%authorised_lib, + default => $value, + }; + } + else { # it's a standard field $subfield_data{marc_value} = { type => 'text', -- 2.17.1