From 9b95b26329340f5248d0838d5e92740833bf4f4f Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Fri, 13 Sep 2024 13:56:42 +0200 Subject: [PATCH] Bug 37892: (follow-up) Fix patron creation This patch fixes the 22. of the test plan (22 - Confirm you cannot add a guarantor - "Guarantor cannot be a guarantee" ) Signed-off-by: Olivier V --- Koha/Patron.pm | 12 ++++++++++++ members/memberentry.pl | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 9a897ae2ed..7b94aef412 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -533,6 +533,18 @@ sub guarantor_relationships { return Koha::Patron::Relationships->search( { guarantee_id => $self->id } ); } +=head3 is_guarantee + +Returns true if the patron has a guarantor. + +=cut + +sub is_guarantee { + my ($self) = @_; + return $self->guarantor_relationships()->count() +} + + =head3 guarantee_relationships Returns Koha::Patron::Relationships object for this patron's guarantors diff --git a/members/memberentry.pl b/members/memberentry.pl index 23aef6ad1f..9025e0d06e 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -285,7 +285,7 @@ if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) } foreach my $guarantor (@guarantors) { - if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && $guarantor->is_child ) { + if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && ($guarantor->is_child ) || $guarantor->is_guarantee) { push @errors, 'ERROR_guarantor_is_guarantee'; } } -- 2.34.1