From c92fcb923d3e1e6dd4918e50f845545894dc44c7 Mon Sep 17 00:00:00 2001 From: Baptiste Wojtkowski Date: Fri, 13 Sep 2024 16:53:20 +0200 Subject: [PATCH] Bug 37892: (follow-up) Fix patron creation TEST PLAN: 1 - Do the 22 parts of the test plan 2 - Add a guarantor to one patron not selected before (let's say A is the guarantee, B the guarantor) 3 - Try and add a guarantor to B -> you will success 4 - Remove B's guarantor 5 - Apply this patch 6 - Repeat 3 -> you will not be able to Signed-off-by: Brendan Lawlor --- Koha/Patron.pm | 13 +++++++++++++ members/memberentry.pl | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 06565b7d70..ea64231411 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -569,6 +569,19 @@ sub guarantee_relationships { ); } + +=head3 is_guarantor + +Returns true if the patron is a guarantor. + +=cut + +sub is_guarantor { + my ($self) = @_; + return $self->guarantee_relationships()->count() +} + + =head3 relationships_debt Returns the amount owed by the patron's guarantors *and* the other guarantees of those guarantors diff --git a/members/memberentry.pl b/members/memberentry.pl index 9025e0d06e..0d09b16bbd 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 ) || $guarantor->is_guarantee) { + if ( ( $op eq 'cud-save' || $op eq 'cud-insert' ) && ($guarantor->is_child ) || $guarantor->is_guarantee || $patron->is_guarantor) { push @errors, 'ERROR_guarantor_is_guarantee'; } } -- 2.39.2