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 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.