Advertisement
NameL3ss

ultimos varios

Sep 28th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. enum trucks
  2. serializer
  3. attribute :swap_bodies_permitted do |object|
  4. Truck.swap_bodies_by_truck(object.truck_type)
  5. end
  6.  
  7. class << self
  8. def truck_response_swap_bodies
  9. Truck.truck_types.each_with_object([]) do |el, arr|
  10. arr << { resource: el[0], swap_body_types: swap_bodies_by_truck(el[0]) }
  11. end
  12. end
  13.  
  14. def swap_bodies_by_truck(resource)
  15. Truck.truck_types[resource].eql?(0) ? SwapBody.swap_body_types.keys : []
  16. end
  17. end
  18.  
  19.  
  20. trucks = current_account.trucks.left_joins(:expeditions).where(expeditions: { id: nil })
  21. drivers = current_account.drivers.left_joins(:expeditions).where(expeditions: { id: nil })
  22. swap_bodies = current_account.swap_bodies.left_joins(:trips).where(trips: { id: nil })
  23.  
  24. ActiveRecord::Base.connection.exec_query("(#{trucks.select('trucks.id AS truck_id').to_sql} UNION #{drivers.select('drivers.id AS driver_id').to_sql}) UNION #{swap_bodies.select('swap_bodies.id AS swap_body_id').to_sql}").map{|x| x }
  25.  
  26. attributes.select do |x|
  27. if klass_enum.include?(x.values.shift)
  28. x[el.keys.shift] = klass_enum[el.values.shift]
  29. else
  30. attributes
  31. end
  32. end
  33.  
  34. destination
  35. current_account.expeditions.joins(trips: :destination_warehouse).where(trips: { warehouses: { address: params[:destination]}})
  36.  
  37. current_account.expeditions.joins(trips: :destination_warehouse).where('warehouses.address ilike ?', "%#{destination}%")
  38.  
  39.  
  40. origin
  41. current_account.expeditions.joins(trips: :origin_warehouse).where(trips: { warehouses: { address: params[:origin]}})
  42.  
  43. current_account.expeditions.joins(trips: :origin_warehouse).where('warehouses.address ilike ?', "%#{origin}%")
  44.  
  45. scope :date_range, (proc { |from, to|
  46. if from && to
  47. where(created_at: from.beginning_of_day..to.end_of_day)
  48. else
  49. where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)
  50. end
  51. })
  52.  
  53.  
  54. refactor serializadores
  55. vista de administracion -> from expedicion
  56. filtros from expedicion
  57.  
  58.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement