From Edgy Wolf, 3 Days ago, written in Plain Text.
Embed
  1. def update_assigned_status
  2.     request_batches_list = []
  3.  
  4.     requests.find_each do |request|
  5.  
  6.       unless request.status_declined_by_admin? || request.status_declined_by_customer? || request.status_overdue? || request.status_completed? || request.status_unable_to_provide?
  7.         request.update_columns(technician_id: nil)
  8.       end
  9.  
  10.       if request.status_assigned? || request.status_on_the_way? || request.status_work_in_progress? || request.status_not_finished?
  11.         if (request.area&.assignment_method_pool_assignment? || request.area&.assignment_method_auto_assignment?) && request.order_date
  12.  
  13.           unless request_batches_list.include?(request[:request_sub_batch_id])
  14.             request.update_status!(:not_assigned, 'Technician deleted')
  15.             disabling = false
  16.  
  17.             if enabled
  18.               self.update_columns(enabled: false)
  19.               disabling = true
  20.             end
  21.            
  22.             request.process_pool_assignment
  23.             request.process_auto_assignment
  24.             self.update_columns(enabled: false) if disabling
  25.             request_batches_list << request[:request_sub_batch_id]
  26.  
  27.           end
  28.         else
  29.           request.update_status!(:pending, 'Technician deleted')
  30.         end
  31.       end
  32.     end
  33.   end