Skip to content

Instantly share code, notes, and snippets.

@edivandecastro
Last active July 2, 2020 15:47
Show Gist options
  • Save edivandecastro/b732fbea431d2c1fbfa327962f97a72f to your computer and use it in GitHub Desktop.
Save edivandecastro/b732fbea431d2c1fbfa327962f97a72f to your computer and use it in GitHub Desktop.
def execute
@movements.each do |movement|
spu_movement = Activity::SpuMovement.find_or_initialize_by(code: movement["id"], procedure_id: @procedure.id)
next if spu_movement.persisted?
original_individual_id = @procedure.individual_id
progress = create_progress_with_virtual_assistant(@procedure)
spu_movement.assign_attributes(
action: movement["procedimento"],
responsible: movement["responsavel"],
execution_date: movement["data"],
origin_code: movement["lotacao_origem_id"],
origin: movement["lotacao_origem"],
destination_code: movement["lotacao_destino_id"],
destination: movement["lotacao_destino"],
progress_id: progress.id
)
spu_movement.documents = movement["files"].map do |file|
Shared::Document.new(
owner: spu_movement,
document: file,
document_type: Activity::SpuMovement.document_types[:judicial_order],
original_filename: file.original_filename
)
end
if spu_movement.save
progress.finish_progress_in_activity(spu_movement)
@procedure.update_attribute(:individual_id, original_individual_id)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment