Skip to content

Commit

Permalink
feat(BO): add Quote edits
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasleger committed Feb 12, 2025
1 parent c1f3cd0 commit 40aee6f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/admin/quote_checks.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# frozen_string_literal: true

def geste_id_errors(quote_check, geste_index)
geste_id = QuoteValidator::Base.geste_index(
quote_check.id, geste_index
)
geste_errors = quote_check.validation_error_details&.select { |error| error["geste_id"] == geste_id }

[geste_id, geste_errors]
end

# rubocop:disable Rails/I18nLocaleTexts
ActiveAdmin.register QuoteCheck do # rubocop:disable Metrics/BlockLength
actions :index, :show, :edit, :update
Expand All @@ -14,6 +23,7 @@
scope "tous", :all, default: true
scope "avec valeurs test", :with_expected_value
scope "fichier en erreur", :with_file_error
scope "devis avec corrections", :with_edits

controller do
def update # rubocop:disable Metrics/MethodLength
Expand Down Expand Up @@ -198,6 +208,35 @@ def update # rubocop:disable Metrics/MethodLength
column "Attributs" do |geste|
pre JSON.pretty_generate(geste)
end
column "Erreur(s) et correction(s)" do |geste|
_, geste_errors = geste_id_errors(resource, gestes.index(geste))

if geste_errors.any?
content_tag(:ul) do
geste_errors.map do
content = "#{it.fetch('code')} : #{it.fetch('title')} #{it.fetch('id')}"

if resource.validation_error_edits&.key?(it.fetch("id"))
deletetion_reason = resource.validation_error_edits&.dig(it.fetch("id"), "reason")
if deletetion_reason
deletetion_reason = I18n.t(
"quote_checks.validation_error_detail_deletion_reasons.#{deletetion_reason}", fallback: deletetion_reason
)
end

content = safe_join([
content,
content_tag(:br),
content_tag(:strong,
["\nSupprimée", deletetion_reason].compact.join(" : "))
])
end

concat(content_tag(:li, content))
end
end
end
end
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/models/concerns/quote_check_backoffice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def ransackable_attributes(_auth_object = nil)
%i[
with_expected_value
with_file_error
with_edits
]
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/concerns/quote_check_edits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ module QuoteCheckEdits
included do
before_validation :format_validation_error_edits
validate :validation_error_edits_data

scope :with_edits, -> { where.not(validation_error_edits: nil) }
end

def delete_validation_error_detail!(error_id, reason: nil)
Expand Down

0 comments on commit 40aee6f

Please sign in to comment.