From e8222d60744d47170c0db30fbe2f4be6b922fc19 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Wed, 19 Oct 2022 11:32:09 +0000 Subject: [PATCH] Bug 32030: Add documents to license Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/License.pm | 16 +++++++ Koha/REST/V1/ERM/Licenses.pm | 6 +++ .../js/vue/components/ERM/LicensesFormAdd.vue | 8 +++- .../js/vue/components/ERM/LicensesShow.vue | 42 +++++++++++++++++++ koha-tmpl/intranet-tmpl/prog/js/vue/fetch.js | 2 +- 5 files changed, 72 insertions(+), 2 deletions(-) diff --git a/Koha/ERM/License.pm b/Koha/ERM/License.pm index 86f20ac10a..9dd22991d2 100644 --- a/Koha/ERM/License.pm +++ b/Koha/ERM/License.pm @@ -22,6 +22,7 @@ use Koha::Database; use base qw(Koha::Object); use Koha::Acquisition::Bookseller; +use Koha::ERM::Documents; =head1 NAME @@ -33,6 +34,21 @@ Koha::ERM::License - Koha ERM License Object class =cut +=head3 documents + +Returns or updates the documents for this license + +=cut + +sub documents { + my ( $self, $documents ) = @_; + if ($documents) { + $self->documents->replace_with($documents, $self); + } + my $documents_rs = $self->_result->erm_documents; + return Koha::ERM::Documents->_new_from_dbic($documents_rs); +} + =head3 vendor Return the vendor for this license diff --git a/Koha/REST/V1/ERM/Licenses.pm b/Koha/REST/V1/ERM/Licenses.pm index 11573ecbcb..cc5a9ef5ee 100644 --- a/Koha/REST/V1/ERM/Licenses.pm +++ b/Koha/REST/V1/ERM/Licenses.pm @@ -91,7 +91,10 @@ sub add { my $body = $c->validation->param('body'); + my $documents = delete $body->{documents} // []; + my $license = Koha::ERM::License->new_from_api($body)->store; + $license->documents($documents); $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); return $c->render( @@ -163,7 +166,10 @@ sub update { my $body = $c->validation->param('body'); + my $documents = delete $body->{documents} // []; + $license->set_from_api($body)->store; + $license->documents($documents); $c->res->headers->location($c->req->url->to_string . '/' . $license->license_id); return $c->render( diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue index 3c152c74d9..9c453fc2b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/LicensesFormAdd.vue @@ -108,6 +108,7 @@ :config="fp_config" /> +
@@ -127,6 +128,7 @@