namespace :notice_complaints do
  desc 'Change notice complaints status'
  task :change_status => :environment do
    NoticeComplaint.all.each do |complaint|
      if complaint.status.to_s == 'delayed' or complaint.status.to_s == 'process' or complaint.status.to_s == 'newest'
        complaint.notice_complaint_records.each do |record|
          if record.status.to_s == 'delayed' or record.status.to_s == 'process'
            record.status = 'newest'
            record.save
          end
        end
        complaint.status = 'newest'
        complaint.save
      end
    end
  end
end