Refactor: Replace BillingValidator with inline validations in bill method and update error messages in locale

This commit is contained in:
2026-03-01 12:29:20 -05:00
parent 46f06df995
commit ef3f00c445
3 changed files with 5 additions and 22 deletions

View File

@@ -33,7 +33,10 @@ class QboController < ApplicationController
# Manual billing endpoint to trigger the billing process for a specific issue. Validates the issue and its associations, enqueues a job to bill the issue's time entries, and redirects back to the issue with a notice. If validation fails, redirects back with an error message.
def bill
issue = Issue.find_by(id: params[:id])
BillingValidator.validate!(issue)
raise I18n.t(:notice_error_issue_not_found) unless issue
raise I18n.t(:label_billing_error_no_customer) unless issue.customer
raise I18n.t(:label_billing_error_no_employee) unless issue.assigned_to&.employee_id.present?
raise I18n.t(:label_billing_error_no_qbo) unless Qbo.exists?
BillIssueTimeJob.perform_later(issue.id)

View File

@@ -1,21 +0,0 @@
#The MIT License (MIT)
#
#Copyright (c) 2016 - 2026 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class BillingValidator
# Validates that the given issue is eligible for billing by checking for the presence of the issue, its associated customer, assigned employee, and an active QBO connection. Raises descriptive errors if any of these conditions are not met.
def self.validate!(issue)
raise "Issue not found" unless issue
raise I18n.t(:label_billing_error_no_customer) unless issue.customer
raise I18n.t(:label_billing_error_no_employee) unless issue.assigned_to&.employee_id.present?
raise I18n.t(:label_billing_error_no_qbo) unless Qbo.exists?
end
end