From 02cd3a96c085fade58aa6ad40f072ff73d386fd5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 5 Aug 2020 11:36:34 +0200 Subject: [PATCH] Bug 8676: 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 --- 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 f62798db08..a80ccc4fe7 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -98,6 +98,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; @@ -1363,6 +1364,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 001d9d8c15..49c5359d1b 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -333,7 +333,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.20.1