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 <jonathan.field@ptfs-europe.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
a387b37c1c
commit
5e3980502b
4 changed files with 83 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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});
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
[% USE raw %]
|
||||
[% USE To %]
|
||||
[% USE Asset %]
|
||||
[% USE KohaDates %]
|
||||
[% USE AuthorisedValues %]
|
||||
|
@ -170,6 +171,11 @@
|
|||
<label for="vendor_type">Vendor type: </label>
|
||||
[% PROCESS 'av-build-dropbox.inc' name="vendor_type", category="VENDOR_TYPE", default=type, empty=1, size = 20 %]
|
||||
</li>
|
||||
<li>
|
||||
<label for="aliases">Aliases: </label>
|
||||
<div id="aliases" style="padding-left: 11rem;"></div>
|
||||
</li>
|
||||
|
||||
</ol>
|
||||
</fieldset>
|
||||
<fieldset class="rows">
|
||||
|
@ -311,6 +317,16 @@
|
|||
[% IF ( accountnumber ) %]
|
||||
<p><span class="label">Account number: </span>[% accountnumber | html %]</p>
|
||||
[% END %]
|
||||
[% IF vendor.aliases.count %]
|
||||
<p>
|
||||
<span class="label">Aliases: </span>
|
||||
<ul>
|
||||
[% FOR alias IN vendor.aliases %]
|
||||
<li>[% alias.alias | html %]</li>
|
||||
[% END %]
|
||||
</ul>
|
||||
</p>
|
||||
[% END %]
|
||||
</div> <!-- /#supplier-company-details -->
|
||||
|
||||
<div id="supplier-ordering-information" class="page-section">
|
||||
|
@ -441,6 +457,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 = $("<div></div>");
|
||||
aliases.forEach((a, i) => {
|
||||
let n = $("<div></div>").append(a.alias);
|
||||
n.append(`<input type="hidden" name="alias" value="${a.alias}">`)
|
||||
n.append(`<a onclick="remove_alias(${i});"><i class="fa fa-trash" aria-hidden="true"></i></a>`);
|
||||
nodes.append(n);
|
||||
});
|
||||
nodes.append("<input id='new_alias' type='text' />");
|
||||
nodes.append(`<a onclick="add_alias();"><i class="fa fa-plus" aria-hidden="true"></i></a>`);
|
||||
$("#aliases").html(nodes.html());
|
||||
}
|
||||
|
||||
var Sticky;
|
||||
|
||||
$(document).ready(function() {
|
||||
|
@ -480,6 +524,8 @@
|
|||
$(this).next('.contact_claimissues_hidden').val($(this).is(':checked') ? '1' : '0');
|
||||
});
|
||||
|
||||
refresh_aliases();
|
||||
|
||||
Sticky = $("#toolbar");
|
||||
Sticky.hcSticky({
|
||||
stickTo: "main",
|
||||
|
|
Loading…
Reference in a new issue