From 4a58a6eeabdb43f779db5cb91e402981a40a6000 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 26 Aug 2024 17:01:09 +0200 Subject: [PATCH 1/2] return validation_error when failing to refresh invoice --- app/services/invoices/refresh_draft_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/invoices/refresh_draft_service.rb b/app/services/invoices/refresh_draft_service.rb index a6faa2d370b..eff6a32be6e 100644 --- a/app/services/invoices/refresh_draft_service.rb +++ b/app/services/invoices/refresh_draft_service.rb @@ -62,7 +62,9 @@ def call CreditNotes::RefreshDraftService.call(credit_note:, fee:, old_fee_values:) end - return calculate_result if tax_error?(calculate_result.error) + if tax_error?(calculate_result.error) + return result.validation_failure!(errors: {tax_error: [calculate_result.error.error_message]}) + end calculate_result.raise_if_error! # NOTE: In case of a refresh the same day of the termination. From 868a4f4319f08e2d5293e343937b39e2e2960c10 Mon Sep 17 00:00:00 2001 From: Anna Velentsevich Date: Mon, 26 Aug 2024 17:23:07 +0200 Subject: [PATCH 2/2] update usage of refresh service when it returns error --- app/services/invoices/refresh_draft_and_finalize_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/invoices/refresh_draft_and_finalize_service.rb b/app/services/invoices/refresh_draft_and_finalize_service.rb index 9aa1e9f057f..ba455a9c940 100644 --- a/app/services/invoices/refresh_draft_and_finalize_service.rb +++ b/app/services/invoices/refresh_draft_and_finalize_service.rb @@ -17,7 +17,7 @@ def call refresh_result = Invoices::RefreshDraftService.call(invoice:, context: :finalize) if tax_error?(refresh_result.error) invoice.update!(issuing_date: drafted_issuing_date) - return result.validation_failure!(errors: {tax_error: [refresh_result.error.error_message]}) + return refresh_result end refresh_result.raise_if_error! @@ -82,7 +82,7 @@ def flag_lifetime_usage_for_refresh end def tax_error?(error) - error&.code == 'tax_error' + error&.messages&.dig(:tax_error) end end end