2022-11-28 15:54:14 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-12-01 09:37:00 +01:00
|
|
|
module DossierPrefillableConcern
|
2022-11-28 15:54:14 +01:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
2023-09-07 10:03:17 +02:00
|
|
|
def prefill!(champs_attributes, identity_attributes)
|
|
|
|
return if champs_attributes.empty? && identity_attributes.empty?
|
2023-01-19 11:51:56 +01:00
|
|
|
|
2023-06-14 11:23:04 +02:00
|
|
|
attributes = { prefilled: true }
|
|
|
|
attributes[:champs_attributes] = champs_attributes.map { |h| h.merge(prefilled: true) }
|
2023-09-18 16:24:55 +02:00
|
|
|
attributes[:individual_attributes] = identity_attributes if identity_attributes.present?
|
2022-11-28 15:54:14 +01:00
|
|
|
|
2023-06-14 11:23:04 +02:00
|
|
|
assign_attributes(attributes)
|
2022-11-28 15:54:14 +01:00
|
|
|
save(validate: false)
|
|
|
|
end
|
|
|
|
end
|