diff --git a/Koha/AdditionalField.pm b/Koha/AdditionalField.pm
index 7e5c16a049..fd9621d681 100644
--- a/Koha/AdditionalField.pm
+++ b/Koha/AdditionalField.pm
@@ -60,6 +60,7 @@ sub to_api {
'aqbasket' => 'basket',
'aqinvoices' => 'invoice',
'erm_licenses' => 'license',
+ 'erm_agreements' => 'agreement',
'aqorders' => 'order',
};
diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm
index dac3e56c9e..785c5e30c7 100644
--- a/Koha/ERM/Agreement.pm
+++ b/Koha/ERM/Agreement.pm
@@ -25,7 +25,7 @@ use Koha::DateUtils qw( dt_from_string );
use Koha::Exceptions;
use Koha::Acquisition::Bookseller;
-use base qw(Koha::Object);
+use base qw(Koha::Object::Mixin::AdditionalFields Koha::Object);
use Koha::ERM::Agreement::Periods;
use Koha::ERM::Agreement::Licenses;
diff --git a/Koha/ERM/Agreements.pm b/Koha/ERM/Agreements.pm
index e8b23c82e5..9c786ca107 100644
--- a/Koha/ERM/Agreements.pm
+++ b/Koha/ERM/Agreements.pm
@@ -24,7 +24,7 @@ use Koha::DateUtils qw( dt_from_string );
use Koha::ERM::Agreement;
use Koha::ERM::Agreement::Periods;
-use base qw(Koha::Objects);
+use base qw(Koha::Objects::Mixin::AdditionalFields Koha::Objects);
=head1 NAME
diff --git a/Koha/REST/V1/ERM/Agreements.pm b/Koha/REST/V1/ERM/Agreements.pm
index dd67576d05..2ba2e0fede 100644
--- a/Koha/REST/V1/ERM/Agreements.pm
+++ b/Koha/REST/V1/ERM/Agreements.pm
@@ -97,6 +97,7 @@ sub add {
my $agreement_licenses = delete $body->{agreement_licenses} // [];
my $agreement_relationships = delete $body->{agreement_relationships} // [];
my $documents = delete $body->{documents} // [];
+ my $extended_attributes = delete $body->{extended_attributes} // [];
my $agreement = Koha::ERM::Agreement->new_from_api($body)->store;
$agreement->periods($periods);
@@ -105,6 +106,9 @@ sub add {
$agreement->agreement_relationships($agreement_relationships);
$agreement->documents($documents);
+ my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
+ $agreement->extended_attributes( \@extended_attributes );
+
$c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id);
return $c->render(
status => 201,
@@ -181,6 +185,7 @@ sub update {
my $agreement_licenses = delete $body->{agreement_licenses} // [];
my $agreement_relationships = delete $body->{agreement_relationships} // [];
my $documents = delete $body->{documents} // [];
+ my $extended_attributes = delete $body->{extended_attributes} // [];
$agreement->set_from_api($body)->store;
$agreement->periods($periods);
@@ -189,6 +194,9 @@ sub update {
$agreement->agreement_relationships($agreement_relationships);
$agreement->documents($documents);
+ my @extended_attributes = map { {'id' => $_->{field_id}, 'value' => $_->{value}} } @{$extended_attributes};
+ $agreement->extended_attributes( \@extended_attributes );
+
$c->res->headers->location($c->req->url->to_string . '/' . $agreement->agreement_id);
return $c->render(
status => 200,
diff --git a/Koha/REST/V1/ExtendedAttributeTypes.pm b/Koha/REST/V1/ExtendedAttributeTypes.pm
index 8dfa4ea6ed..f891c41dd1 100644
--- a/Koha/REST/V1/ExtendedAttributeTypes.pm
+++ b/Koha/REST/V1/ExtendedAttributeTypes.pm
@@ -46,12 +46,13 @@ sub list {
# FIXME: Maybe not the best place for this mapping
my $resource_to_table = {
- basket => 'aqbasket',
- credit => 'accountlines:credit',
- debit => 'accountlines:debit',
- invoice => 'aqinvoices',
- license => 'erm_licenses',
- order => 'aqorders',
+ basket => 'aqbasket',
+ credit => 'accountlines:credit',
+ debit => 'accountlines:debit',
+ invoice => 'aqinvoices',
+ license => 'erm_licenses',
+ agreement => 'erm_agreements',
+ order => 'aqorders',
};
return try {
diff --git a/Koha/Schema/Result/ErmAgreement.pm b/Koha/Schema/Result/ErmAgreement.pm
index b2b97e4f3e..78679d364f 100644
--- a/Koha/Schema/Result/ErmAgreement.pm
+++ b/Koha/Schema/Result/ErmAgreement.pm
@@ -281,6 +281,38 @@ __PACKAGE__->add_columns(
'+is_perpetual' => { is_boolean => 1 }
);
+__PACKAGE__->has_many(
+ "additional_field_values",
+ "Koha::Schema::Result::AdditionalFieldValue",
+ sub {
+ my ($args) = @_;
+
+ return {
+ "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.agreement_id" },
+
+ "$args->{foreign_alias}.field_id" =>
+ { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_agreements")' },
+ };
+ },
+ { 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}.agreement_id" },
+
+ "$args->{foreign_alias}.field_id" =>
+ { -in => \'(SELECT id FROM additional_fields WHERE tablename="erm_agreements")' },
+ };
+ },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
sub koha_object_class {
'Koha::ERM::Agreement';
}
diff --git a/api/v1/swagger/definitions/erm_agreement.yaml b/api/v1/swagger/definitions/erm_agreement.yaml
index e8fc871d34..d355d69b3c 100644
--- a/api/v1/swagger/definitions/erm_agreement.yaml
+++ b/api/v1/swagger/definitions/erm_agreement.yaml
@@ -69,6 +69,16 @@ properties:
type:
- object
- "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_agreements.yaml b/api/v1/swagger/paths/erm_agreements.yaml
index 43a48e1179..933192191a 100644
--- a/api/v1/swagger/paths/erm_agreements.yaml
+++ b/api/v1/swagger/paths/erm_agreements.yaml
@@ -69,6 +69,8 @@
enum:
- user_roles
- vendor
+ - extended_attributes
+ - +strings
collectionFormat: csv
- $ref: "../swagger.yaml#/parameters/match"
- $ref: "../swagger.yaml#/parameters/order_by"
@@ -198,6 +200,8 @@
- agreement_packages.package
- documents
- vendor
+ - extended_attributes
+ - +strings
collectionFormat: csv
responses:
200:
@@ -265,6 +269,8 @@
- agreement_licenses
- agreement_relationships
- documents
+ - 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 7bad73967c..08f8141873 100644
--- a/api/v1/swagger/paths/extended_attribute_types.yaml
+++ b/api/v1/swagger/paths/extended_attribute_types.yaml
@@ -19,6 +19,7 @@
- debit
- invoice
- license
+ - agreement
- 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 02c7ab20e1..2b47151537 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
@@ -24,7 +24,7 @@
[% marcfield_tables = ['subscription', 'aqorders'] %]
-[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices', 'erm_licenses'] %]
+[% searchable_tables = ['subscription', 'aqbasket', 'aqinvoices', 'erm_licenses', 'erm_agreements'] %]
[% show_marcfield = marcfield_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %]
[% show_searchable = searchable_tables.grep('^' _ tablename _ '$').size ? 1 : 0 %]
@@ -137,7 +137,8 @@
[% WRAPPER table_option value="accountlines:debit" %]Account lines (debit)[% END %]
[% END %]
[% IF CAN_user_erm %]
- [% WRAPPER table_option value="erm_licenses" %]ERM licenses[% END %]
+ [% WRAPPER table_option value="erm_licenses" %]ERM Licenses[% END %]
+ [% WRAPPER table_option value="erm_agreements" %]ERM Agreements[% END %]
[% END %]
[% ELSE %]
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue
index 645a13b5be..f7e8d26412 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsFormAdd.vue
@@ -132,6 +132,11 @@
+
this.table_url(),
table_settings: this.agreement_table_settings,
add_filters: true,
@@ -161,7 +165,15 @@ export default {
},
beforeRouteEnter(to, from, next) {
next(vm => {
- vm.getAgreementCount().then(() => (vm.initialized = true))
+ vm.getAgreementCount().then(() =>
+ vm
+ .getSearchableAdditionalFields()
+ .then(() =>
+ vm
+ .getSearchableAVOptions()
+ .then(() => (vm.initialized = true))
+ )
+ )
})
},
methods: {
@@ -173,6 +185,41 @@ export default {
},
error => {}
)
+ },
+ async getSearchableAdditionalFields() {
+ const client = APIClient.additional_fields
+ await client.additional_fields.getAll("agreement").then(
+ searchable_additional_fields => {
+ this.searchable_additional_fields =
+ searchable_additional_fields.filter(
+ field => field.searchable
+ )
+ },
+ error => {}
+ )
+ },
+ async getSearchableAVOptions() {
+ const client_av = APIClient.authorised_values
+ let av_cat_array = this.searchable_additional_fields
+ .filter(field => field.authorised_value_category_name)
+ .map(field => field.authorised_value_category_name)
+
+ await client_av.values
+ .getCategoriesWithValues([
+ ...new Set(av_cat_array.map(av_cat => '"' + av_cat + '"')),
+ ]) // unique
+ .then(av_categories => {
+ av_cat_array.forEach(av_cat => {
+ let av_match = av_categories.find(
+ element => element.category_name == av_cat
+ )
+ this.searchable_av_options[av_cat] =
+ av_match.authorised_values.map(av => ({
+ value: av.value,
+ label: av.description,
+ }))
+ })
+ })
},
doShow: function ({ agreement_id }, dt, event) {
event.preventDefault()
diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue
index 27eee68c05..7b49fe88d6 100644
--- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue
+++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/AgreementsShow.vue
@@ -322,6 +322,12 @@
+