Bug 38010: Adjust vendor update logic

This patch handles the embedded data that might also need updating when editing a vendor

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-09-30 14:22:34 +00:00 committed by Katrin Fischer
parent 069381a815
commit 8e99ee7dd6
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 25 additions and 6 deletions

View File

@ -85,10 +85,13 @@ Controller function that handles adding a new Koha::Acquisition::Bookseller obje
sub add {
my $c = shift->openapi->valid_input or return;
my $vendor = $c->req->json;
my $contacts = delete $vendor->{contacts};
my $interfaces = delete $vendor->{interfaces};
my $aliases = delete $vendor->{aliases};
my $vendor = $c->req->json;
my $contacts = delete $vendor->{contacts};
my $interfaces = delete $vendor->{interfaces};
my $aliases = delete $vendor->{aliases};
my $subscriptions = delete $vendor->{subscriptions};
my $baskets = delete $vendor->{baskets};
my $contracts = delete $vendor->{contracts};
my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json );
@ -121,15 +124,31 @@ Controller function that handles updating a Koha::Acquisition::Bookseller object
sub update {
my $c = shift->openapi->valid_input or return;
my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') );
my $vendor_id = $c->param('vendor_id');
my $vendor = Koha::Acquisition::Booksellers->find($vendor_id);
return $c->render_resource_not_found("Vendor")
unless $vendor;
return try {
$vendor->set_from_api( $c->req->json );
my $vendor_update = $c->req->json;
my $contacts = delete $vendor_update->{contacts};
my $interfaces = delete $vendor_update->{interfaces};
my $aliases = delete $vendor_update->{aliases};
my $subscriptions = delete $vendor_update->{subscriptions};
my $baskets = delete $vendor_update->{baskets};
my $contracts = delete $vendor_update->{contracts};
$vendor->set_from_api($vendor_update);
$vendor->store();
foreach my $contact (@$contacts) {
$contact->{booksellerid} = $vendor_id;
Koha::Acquisition::Bookseller::Contact->new($contact)->store;
}
$vendor->aliases($aliases) if scalar($aliases) > 0;
$vendor->interfaces($interfaces) if scalar($interfaces) > 0;
return $c->render(
status => 200,
openapi => $c->objects->to_api($vendor),