From 6e202934a93ce66fd055af1cc9a11bb9e2d59402 Mon Sep 17 00:00:00 2001 From: Jake Deery Date: Mon, 9 Sep 2024 11:42:36 +0000 Subject: [PATCH] Bug 37577: Add additional fields for ERM packages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This bug adds support for additional fields in the ERM module's packages, similar to how Bug 35287 added support for additional fields in the ERM module's licences, and Bug 37576 added support for additional fields in the ERM module's agreements. To test (k.t.d): a) APPLY PATCH b) Run cypress --spec t/cypress/integration/AdditionalFields_spec.ts 1) Note how the tests pass c) Add new additional fields for 'erm_packages' 1) Go to /cgi-bin/koha/admin/additional-fields.pl?tablename=erm_packages 2) Create field one called 'text non-repeatable' 3) Create field two called 'text repeatable', check 'repeatable' 4) Create field three called 'av non-repeatable', pick LANG authorised value 5) Create field four called 'av repeatable', pick LOC authorised value, check repeatable d) Create new local package 1) Go to /cgi-bin/koha/erm/eholdings/local/packages/add, notice the new additional fields section 2) Complete all mandatory fields for a new package 3) Experiment with the four different additional field types – it may be useful to watch the Cypress-generated test video for guidance 4) Select some AV options from the AV fields, deselect them, notice the repeatable one allows for multiple selection, the non-repeatable one does not e) Save the package, then view it 1) To view the package, click its name in the table list on /cgi-bin/koha/erm/eholdings/local/packages 2) notice the additional fields on display 3) also notice that the authorised values are in their human-readable form, and not their coded form f) Edit the package, then view it again 1) Go to /cgi-bin/koha/erm/eholdings/local/packages/edit/1 2) Play around again with the fields. Save. 3) Repeat step e, have the edits shown up? g) Test searchability 1) Go to /cgi-bin/koha/admin/additional-fields.pl?tablename=erm_packages 2) Edit one of the fields and make sure searchable is checked (ensure you choose a field that has some data in it) 3) Go to /cgi-bin/koha/erm/eholdings/local/packages 4) Notice that the searchable field(s) are now columns in the table 5) Notice that searchable AV fields contain a drop-down 6) Notice that searchable text fields have an input field 7) Perform a search on the additional field 8) Notice that the searching is working as expected h) SIGN OFF --- Koha/AdditionalField.pm | 1 + Koha/ERM/EHoldings/Package.pm | 2 +- Koha/ERM/EHoldings/Packages.pm | 2 +- Koha/REST/V1/ERM/EHoldings/Packages/Local.pm | 8 + Koha/REST/V1/ExtendedAttributeTypes.pm | 1 + Koha/Schema/Result/ErmEholdingsPackage.pm | 32 ++ .../definitions/erm_eholdings_package.yaml | 10 + .../swagger/paths/erm_eholdings_packages.yaml | 6 + .../paths/extended_attribute_types.yaml | 1 + .../en/modules/admin/additional-fields.tt | 3 +- .../ERM/EHoldingsLocalPackagesFormAdd.vue | 12 + .../ERM/EHoldingsLocalPackagesList.vue | 51 +- .../ERM/EHoldingsLocalPackagesShow.vue | 10 + .../prog/js/vue/fetch/erm-api-client.js | 2 +- .../integration/AdditionalFields_spec.ts | 535 ++++++++++++++++++ 15 files changed, 670 insertions(+), 6 deletions(-) diff --git a/Koha/AdditionalField.pm b/Koha/AdditionalField.pm index fd9621d681..ec0263697f 100644 --- a/Koha/AdditionalField.pm +++ b/Koha/AdditionalField.pm @@ -61,6 +61,7 @@ sub to_api { 'aqinvoices' => 'invoice', 'erm_licenses' => 'license', 'erm_agreements' => 'agreement', + 'erm_packages' => 'package', 'aqorders' => 'order', }; diff --git a/Koha/ERM/EHoldings/Package.pm b/Koha/ERM/EHoldings/Package.pm index 6ee7975277..06c3c3a2a6 100644 --- a/Koha/ERM/EHoldings/Package.pm +++ b/Koha/ERM/EHoldings/Package.pm @@ -19,7 +19,7 @@ use Modern::Perl; use Koha::Database; -use base qw(Koha::Object); +use base qw(Koha::Object::Mixin::AdditionalFields Koha::Object); use Koha::Acquisition::Booksellers; use Koha::ERM::EHoldings::Package::Agreements; diff --git a/Koha/ERM/EHoldings/Packages.pm b/Koha/ERM/EHoldings/Packages.pm index fe063770c6..021f1b1aec 100644 --- a/Koha/ERM/EHoldings/Packages.pm +++ b/Koha/ERM/EHoldings/Packages.pm @@ -22,7 +22,7 @@ use Koha::Database; use Koha::ERM::EHoldings::Package; -use base qw(Koha::Objects); +use base qw(Koha::Objects::Mixin::AdditionalFields Koha::Objects); =head1 NAME diff --git a/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm b/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm index 63ca976540..2985477421 100644 --- a/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm +++ b/Koha/REST/V1/ERM/EHoldings/Packages/Local.pm @@ -88,11 +88,15 @@ sub add { my $body = $c->req->json; my $package_agreements = delete $body->{package_agreements} // []; + my $extended_attributes = delete $body->{extended_attributes} // []; delete $body->{external_id} unless $body->{external_id}; my $package = Koha::ERM::EHoldings::Package->new_from_api($body)->store; $package->package_agreements($package_agreements); + my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes}; + $package->extended_attributes( \@extended_attributes ); + $c->res->headers->location($c->req->url->to_string . '/' . $package->package_id); return $c->render( status => 201, @@ -160,6 +164,7 @@ sub update { my $body = $c->req->json; my $package_agreements = delete $body->{package_agreements} // []; + my $extended_attributes = delete $body->{extended_attributes} // []; delete $body->{external_id} unless $body->{external_id}; $package->set_from_api($body)->store; @@ -168,6 +173,9 @@ sub update { # ie. It's coming from EBSCO and we don't have local data linked to it $package->package_agreements($package_agreements); + my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes}; + $package->extended_attributes( \@extended_attributes ); + $c->res->headers->location($c->req->url->to_string . '/' . $package->package_id); return $c->render( status => 200, diff --git a/Koha/REST/V1/ExtendedAttributeTypes.pm b/Koha/REST/V1/ExtendedAttributeTypes.pm index f891c41dd1..844582c5a4 100644 --- a/Koha/REST/V1/ExtendedAttributeTypes.pm +++ b/Koha/REST/V1/ExtendedAttributeTypes.pm @@ -52,6 +52,7 @@ sub list { invoice => 'aqinvoices', license => 'erm_licenses', agreement => 'erm_agreements', + package => 'erm_packages', order => 'aqorders', }; diff --git a/Koha/Schema/Result/ErmEholdingsPackage.pm b/Koha/Schema/Result/ErmEholdingsPackage.pm index 847f2685bb..27d2e4938a 100644 --- a/Koha/Schema/Result/ErmEholdingsPackage.pm +++ b/Koha/Schema/Result/ErmEholdingsPackage.pm @@ -201,6 +201,38 @@ __PACKAGE__->many_to_many("agreements", "erm_eholdings_packages_agreements", "ag # Created by DBIx::Class::Schema::Loader v0.07049 @ 2022-11-11 11:52:09 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:3YA6xOwdLHDLoZnQJNk8eQ +__PACKAGE__->has_many( + "additional_field_values", + "Koha::Schema::Result::AdditionalFieldValue", + sub { + my ($args) = @_; + + return { + "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.package_id" }, + + "$args->{foreign_alias}.field_id" => + { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_packages")' }, + }; + }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +__PACKAGE__->has_many( + "extended_attributes", + "Koha::Schema::Result::AdditionalFieldValue", + sub { + my ($args) = @_; + + return { + "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.package_id" }, + + "$args->{foreign_alias}.field_id" => + { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_packages")' }, + }; + }, + { cascade_copy => 0, cascade_delete => 0 }, +); + sub koha_object_class { 'Koha::ERM::EHoldings::Package'; } diff --git a/api/v1/swagger/definitions/erm_eholdings_package.yaml b/api/v1/swagger/definitions/erm_eholdings_package.yaml index 328971897c..377d445d2f 100644 --- a/api/v1/swagger/definitions/erm_eholdings_package.yaml +++ b/api/v1/swagger/definitions/erm_eholdings_package.yaml @@ -70,6 +70,16 @@ properties: type: - integer - "null" + extended_attributes: + description: Related additional field values + type: + - array + items: + $ref: extended_attribute_value.yaml + _strings: + type: + - object + - "null" additionalProperties: false required: diff --git a/api/v1/swagger/paths/erm_eholdings_packages.yaml b/api/v1/swagger/paths/erm_eholdings_packages.yaml index 895c1acf05..d3ae91f205 100644 --- a/api/v1/swagger/paths/erm_eholdings_packages.yaml +++ b/api/v1/swagger/paths/erm_eholdings_packages.yaml @@ -72,6 +72,8 @@ - vendor.name - resources+count - resources + - extended_attributes + - +strings collectionFormat: csv responses: 200: @@ -193,6 +195,8 @@ - package_agreements.agreement - resources+count - vendor + - extended_attributes + - +strings collectionFormat: csv responses: 200: @@ -262,6 +266,8 @@ enum: - agreements - resources + - extended_attributes + - +strings collectionFormat: csv responses: 200: diff --git a/api/v1/swagger/paths/extended_attribute_types.yaml b/api/v1/swagger/paths/extended_attribute_types.yaml index 08f8141873..eba7aec901 100644 --- a/api/v1/swagger/paths/extended_attribute_types.yaml +++ b/api/v1/swagger/paths/extended_attribute_types.yaml @@ -20,6 +20,7 @@ - invoice - license - agreement + - package - order - subscription - $ref: "../swagger.yaml#/parameters/match" diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt index e26e8690b4..ebc91de17a 100755 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/additional-fields.tt @@ -23,7 +23,7 @@ [% marcfield_tables = ['subscription', 'aqorders'] %] -[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices', 'erm_licenses', 'erm_agreements'] %] +[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices', 'erm_licenses', 'erm_agreements', 'erm_packages'] %] [% show_marcfield = marcfield_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %] [% show_searchable = searchable_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %] @@ -138,6 +138,7 @@ [% IF CAN_user_erm %] [% WRAPPER table_option value="erm_licenses" %]ERM Licenses[% END %] [% WRAPPER table_option value="erm_agreements" %]ERM Agreements[% END %] + [% WRAPPER table_option value="erm_packages" %]ERM Packages[% END %] [% END %] [% ELSE %] diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue index 8a382c5cf6..79c2b2952a 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsLocalPackagesFormAdd.vue @@ -63,6 +63,11 @@ + @@ -87,6 +92,7 @@