Bug 38010: Prevent vendor contacts from duplicating

Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Matt Blenkinsop 2024-12-05 13:58:30 +00:00 committed by Katrin Fischer
parent 027582efef
commit 29ca78bb48
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 25 additions and 13 deletions

View File

@ -60,9 +60,27 @@ Returns the list of contacts for the vendor
=cut
sub contacts {
my ($self) = @_;
my $contacts_rs = $self->_result->aqcontacts;
return Koha::Acquisition::Bookseller::Contacts->_new_from_dbic($contacts_rs);
my ( $self, $contacts ) = @_;
if ($contacts) {
my $schema = $self->_result->result_source->schema;
$schema->txn_do(
sub {
$self->contacts->delete;
for my $contact (@$contacts) {
Koha::Acquisition::Bookseller::Contact->new(
{
%$contact,
booksellerid => $self->id,
}
)->store;
}
}
);
}
my $rs = $self->_result->aqcontacts;
return Koha::Acquisition::Bookseller::Contacts->_new_from_dbic($rs);
}
=head3 contracts

View File

@ -98,10 +98,7 @@ sub add {
return try {
$vendor_to_store->store;
foreach my $contact (@$contacts) {
$contact->{booksellerid} = $vendor_to_store->id;
Koha::Acquisition::Bookseller::Contact->new($contact)->store;
}
$vendor_to_store->contacts($contacts) if scalar($contacts) > 0;
$vendor_to_store->aliases($aliases) if scalar($aliases) > 0;
$vendor_to_store->interfaces($interfaces) if scalar($interfaces) > 0;
@ -142,10 +139,7 @@ sub update {
$vendor->set_from_api($vendor_update);
$vendor->store();
foreach my $contact (@$contacts) {
$contact->{booksellerid} = $vendor_id;
Koha::Acquisition::Bookseller::Contact->new($contact)->store;
}
$vendor->contacts($contacts) if scalar($contacts) > 0;
$vendor->aliases($aliases) if scalar($aliases) > 0;
$vendor->interfaces($interfaces) if scalar($interfaces) > 0;

View File

@ -149,7 +149,7 @@
<div style="display: flex">
<div>
<fieldset class="rows">
<legend>Acquisitions options</legend>
<legend>{{ $__("Acquisitions options") }}</legend>
<ol class="radio">
<li>
<label>
@ -216,7 +216,7 @@
</div>
<div>
<fieldset class="rows">
<legend>Serials options</legend>
<legend>{{ $__("Serials options") }}</legend>
<ol class="radio">
<li>
<label>