Analyze PDF only if present

This commit is contained in:
2024-10-07 10:35:46 +02:00
parent 25b40f99d5
commit 3803d6657b

View File

@@ -13,8 +13,8 @@ class Job < ApplicationRecord
validates_presence_of :pdf, unless: :created_by_operator? validates_presence_of :pdf, unless: :created_by_operator?
validates :privacy_policy, acceptance: true, unless: :created_by_operator? validates :privacy_policy, acceptance: true, unless: :created_by_operator?
validates :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan, numericality: { greater_than_or_equal_to: 0 } validates :number_of_plans_a0, :number_of_plans_a1, :number_of_plans_a2, :number_of_plans_a3, :costum_qm_plan, numericality: { greater_than_or_equal_to: 0 }
validate :acceptable_pdf, unless: :created_by_operator?
validate :acceptable_pdf
before_save :update_status_changed_at, if: :will_save_change_to_status? before_save :update_status_changed_at, if: :will_save_change_to_status?
before_save :update_user_status_infos, if: -> { will_save_change_to_status? || new_record? } before_save :update_user_status_infos, if: -> { will_save_change_to_status? || new_record? }
@@ -173,6 +173,7 @@ class Job < ApplicationRecord
# TODO: add any check if attachment has changed # TODO: add any check if attachment has changed
# pdfs.each do |pdf| # pdfs.each do |pdf|
if pdf.blob
pdf.blob.open do |file| pdf.blob.open do |file|
# file = ActiveStorage::Blob.service.path_for(pdf.key).to_s # file = ActiveStorage::Blob.service.path_for(pdf.key).to_s
pdf_analyzer = Services::PdfAnalyzer.new(file) pdf_analyzer = Services::PdfAnalyzer.new(file)
@@ -183,6 +184,7 @@ class Job < ApplicationRecord
self.number_of_plans_a3 += pdf_analyzer.pages_a3 self.number_of_plans_a3 += pdf_analyzer.pages_a3
self.costum_qm_plan += pdf_analyzer.costum_qm self.costum_qm_plan += pdf_analyzer.costum_qm
end end
end
# end # end
calc_cost calc_cost
save save