Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return validation_error when failing to refresh invoice #2482

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/services/invoices/refresh_draft_and_finalize_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down Expand Up @@ -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
4 changes: 3 additions & 1 deletion app/services/invoices/refresh_draft_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down