From abd80f4c6a049d2421e6bbce0a8afd6f8ba7ffeb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 21 Jul 2022 08:48:45 +0200 Subject: [PATCH] Bug 32030: Allow only one controlling license per agreement Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/Agreement.pm | 7 +++++++ .../prog/js/vue/components/ERM/AgreementsFormAdd.vue | 4 ++++ 2 files changed, 11 insertions(+) diff --git a/Koha/ERM/Agreement.pm b/Koha/ERM/Agreement.pm index 817d57b10f..cc867ef66a 100644 --- a/Koha/ERM/Agreement.pm +++ b/Koha/ERM/Agreement.pm @@ -22,6 +22,7 @@ use MIME::Types; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); +use Koha::Exceptions; use base qw(Koha::Object); @@ -103,6 +104,12 @@ sub agreement_licenses { my ( $self, $agreement_licenses ) = @_; if ( $agreement_licenses ) { + my $controlling = grep { $_->{status} eq 'controlling' } @$agreement_licenses; + if ( $controlling > 1 ) { + Koha::Exceptions::DuplicateObject->throw( + "Only one controlling license can exist for a given agreement"); + } + my $schema = $self->_result->result_source->schema; $schema->txn_do( sub { 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 9229d8c1e4..28c529960d 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 @@ -305,6 +305,10 @@ export default { errors.push(this.$t("Only one controlling license is allowed")) } + if (agreement_licenses.filter(al => al.status == 'controlling').length > 1) { + errors.push(this.$t("Only one controlling license is allowed")) + } + errors.forEach(function (e) { setWarning(e) }) -- 2.39.5