From 1c2447fdb2fde444da18098908875e8c785b498c Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 1 Mar 2023 11:57:23 +0100 Subject: [PATCH] Bug 33103: Add the ability to create vendor aliases This patchset is adding the ability to create aliases for vendors. It will then be easier to search for vendors. * new DB table aqbookseller_aliases(id, vendor_id, alias) * new pair of Koha classes Koha::Acquisition::Bookseller::Alias[es] * new method to retrieve the aliases from the vendor Koha::Acquisition::Bookseller->aliases * The api spec changes to allow aliases to be embeded on GET /acquisitions/vendors * Add/Delete alias when editing a vendor * Display the aliases on the vendor show view * Search vendors by aliases * Display the aliases in the dropdown list of the vendors in the ERM module Test plan: - Create a vendor, add it some aliases - Edit the vendor, remove some aliases => Behaviour must be consistent - Search the vendor in the acquisition module by its aliases => The vendor must be returned in the result - Go to the ERM module, add a new agreement or license => Notice that the dropdown list of the vendors is displaying the aliases, that make vendors searchable by their aliases Signed-off-by: Jonathan Field --- Koha/Acquisition/Bookseller.pm | 29 ++++++++++++ acqui/supplier.pl | 2 + acqui/updatesupplier.pl | 8 +++- .../prog/en/modules/acqui/supplier.tt | 46 +++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index 7cf76d6705..0ba30a3243 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -17,6 +17,7 @@ package Koha::Acquisition::Bookseller; use Modern::Perl; +use Koha::Acquisition::Bookseller::Aliases; use Koha::Acquisition::Bookseller::Contacts; use Koha::Subscriptions; @@ -76,6 +77,34 @@ sub subscriptions { return Koha::Subscriptions->search( { aqbooksellerid => $self->id } ); } +=head3 aliases + + my $aliases = $vendor->aliases + + $vendor->aliases([{ alias => 'one alias'}]); + +=cut + +sub aliases { + my ($self, $aliases) = @_; + + if ($aliases) { + my $schema = $self->_result->result_source->schema; + $schema->txn_do( + sub { + $self->aliases->delete; + for my $alias (@$aliases) { + $self->_result->add_to_aqbookseller_aliases($alias); + } + } + ); + } + + my $rs = $self->_result->aqbookseller_aliases; + return Koha::Acquisition::Bookseller::Aliases->_new_from_dbic( $rs ); +} + + =head3 to_api_mapping This method returns the mapping for representing a Koha::Acquisition::Bookseller object diff --git a/acqui/supplier.pl b/acqui/supplier.pl index 0e3570780a..bd988551de 100755 --- a/acqui/supplier.pl +++ b/acqui/supplier.pl @@ -85,6 +85,7 @@ if ( $op eq 'display' ) { listprice => $supplier->listprice, basketcount => $supplier->baskets->count, subscriptioncount => $supplier->subscriptions->count, + vendor => $supplier, contracts => $contracts, ); } elsif ( $op eq 'delete' ) { @@ -106,6 +107,7 @@ if ( $op eq 'display' ) { # set active ON by default for supplier add (id empty for add) active => $supplier ? $supplier->active : 1, tax_rate => $supplier ? $supplier->tax_rate + 0.0 : 0, + vendor => $supplier, gst_values => \@gst_values, currencies => Koha::Acquisition::Currencies->search, enter => 1, diff --git a/acqui/updatesupplier.pl b/acqui/updatesupplier.pl index 75dca3c22b..ac0d50ba64 100755 --- a/acqui/updatesupplier.pl +++ b/acqui/updatesupplier.pl @@ -93,6 +93,8 @@ $data{'tax_rate'} = $input->param('tax_rate'); $data{'discount'} = $input->param('discount'); $data{deliverytime} = $input->param('deliverytime'); $data{'active'}=$input->param('status'); + +my @aliases = $input->multi_param('alias'); my @contacts; my %contact_info; @@ -111,15 +113,16 @@ for my $cnt (0..scalar(@{$contact_info{'id'}})) { } if($data{'name'}) { + my $bookseller; if ( $data{id} ) { # Update - my $bookseller = Koha::Acquisition::Booksellers->find( $data{id} )->set(\%data)->store; + $bookseller = Koha::Acquisition::Booksellers->find( $data{id} )->set(\%data)->store; # Delete existing contacts $bookseller->contacts->delete; } else { # Insert delete $data{id}; # Remove the key if exists - my $bookseller = Koha::Acquisition::Bookseller->new( \%data )->store; + $bookseller = Koha::Acquisition::Bookseller->new( \%data )->store; $data{id} = $bookseller->id; } # Insert contacts @@ -127,6 +130,7 @@ if($data{'name'}) { $contact->{booksellerid} = $data{id}; Koha::Acquisition::Bookseller::Contact->new( $contact )->store } + $bookseller->aliases([ map { { alias => $_ } } @aliases ]); #redirect to booksellers.pl print $input->redirect("booksellers.pl?booksellerid=".$data{id}); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt index 9dd49954e9..ad73ec84bb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/supplier.tt @@ -1,4 +1,5 @@ [% USE raw %] +[% USE To %] [% USE Asset %] [% USE KohaDates %] [% USE AuthorisedValues %] @@ -181,6 +182,11 @@ [% PROCESS 'av-build-dropbox.inc' name="vendor_type", category="VENDOR_TYPE", default=type, empty=1, size = 20 %] +
  • + +
    +
  • +
    @@ -322,6 +328,16 @@ [% IF ( accountnumber ) %]

    Account number: [% accountnumber | html %]

    [% END %] + [% IF vendor.aliases.count %] +

    + Aliases: +

      + [% FOR alias IN vendor.aliases %] +
    • [% alias.alias | html %]
    • + [% END %] +
    +

    + [% END %]
    @@ -452,6 +468,34 @@ ev.preventDefault(); } + [% IF vendor %] + let aliases = [% To.json(vendor.aliases.unblessed) | $raw %]; + [% ELSE %] + let aliases = []; + [% END %] + function remove_alias(i){ + aliases.splice(i, 1); + refresh_aliases(); + } + function add_alias(){ + let alias = $("#new_alias").val(); + if ( !alias.length > 0 ) { return } + aliases.push({alias}); + refresh_aliases(); + } + function refresh_aliases(){ + let nodes = $("
    "); + aliases.forEach((a, i) => { + let n = $("
    ").append(a.alias); + n.append(``) + n.append(``); + nodes.append(n); + }); + nodes.append(""); + nodes.append(``); + $("#aliases").html(nodes.html()); + } + var Sticky; $(document).ready(function() { @@ -491,6 +535,8 @@ $(this).next('.contact_claimissues_hidden').val($(this).is(':checked') ? '1' : '0'); }); + refresh_aliases(); + Sticky = $("#toolbar"); Sticky.hcSticky({ stickTo: "main", -- 2.30.2