From 5cf3569ee61b486ddacfb8277d7acfa10d22664a Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Thu, 29 Feb 2024 15:26:54 +0000 Subject: [PATCH] Bug 34920: Ensure 'description' property is an empty string if 'lib' is null Test plan: 1. Enable ERM module 2. Confirm that you can open the ERM module in the staff interface. 3. Go to the authorized values, select 'ERM_AGREEMENT_CLOSURE_REASON' and edit the 'Cancelled' authorized value by removing the description. Making this change with any of the ERM authorized values will result in an error. 4. Go back to the ERM module and notice that there is an error. 'Something went wrong: Error: Expected string - got null.' 5. Apply patch. Run yarn js:build. Repeat test plan 6. Create a new agreement. Pick status 'Closed'. 7. Open 'Closure reason'. Confirm there is an entry for 'Expired' and an empty entry below that. Signed-off-by: Laura Escamilla Signed-off-by: Martin Renvoize --- Koha/AuthorisedValue.pm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Koha/AuthorisedValue.pm b/Koha/AuthorisedValue.pm index f831e4b75b5..5669ab6086a 100644 --- a/Koha/AuthorisedValue.pm +++ b/Koha/AuthorisedValue.pm @@ -132,6 +132,26 @@ sub is_integer_only { return $self->_result->category->is_integer_only; } +=head3 to_api + + my $json = $av->to_api; + +Overloaded method that returns a JSON representation of the Koha::AuthorisedValue object, +suitable for API output. + +=cut + +sub to_api { + my ( $self, $params ) = @_; + + my $response = $self->SUPER::to_api($params); + my $overrides = {}; + + $overrides->{description} = $self->lib // q{}; + + return { %$response, %$overrides }; +} + =head2 Internal methods =head3 _check_is_integer_only -- 2.45.2