From 65ec1a06e5ff5158cfb07e43674c56f813b2f94a Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Thu, 5 Dec 2024 13:58:30 +0000 Subject: [PATCH] Bug 38010: Prevent vendor contacts from duplicating --- Koha/Acquisition/Bookseller.pm | 24 ++++++++++++++++--- Koha/REST/V1/Acquisitions/Vendors.pm | 10 ++------ .../vue/components/Vendors/VendorContacts.vue | 4 ++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Koha/Acquisition/Bookseller.pm b/Koha/Acquisition/Bookseller.pm index 5041582d935..5f96b8c7a32 100644 --- a/Koha/Acquisition/Bookseller.pm +++ b/Koha/Acquisition/Bookseller.pm @@ -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 diff --git a/Koha/REST/V1/Acquisitions/Vendors.pm b/Koha/REST/V1/Acquisitions/Vendors.pm index ddd414d0b4d..4f5fb17dae8 100644 --- a/Koha/REST/V1/Acquisitions/Vendors.pm +++ b/Koha/REST/V1/Acquisitions/Vendors.pm @@ -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; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue index 26a98c8f646..4fd1452a4e4 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/Vendors/VendorContacts.vue @@ -149,7 +149,7 @@
- Acquisitions options + {{ $__("Acquisitions options") }}
- Serials options + {{ $__("Serials options") }}