Bug 32030: Allow only one controlling license per agreement

Signed-off-by: Jonathan Field <jonathan.field@ptfs-europe.com>

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Jonathan Druart 2022-07-21 08:48:45 +02:00 committed by Tomas Cohen Arazi
parent 64a838ce32
commit abd80f4c6a
No known key found for this signature in database
GPG Key ID: 0A272EA1B2F3C15F
2 changed files with 11 additions and 0 deletions

View File

@ -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 {

View File

@ -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)
})