Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum trucks
- serializer
- attribute :swap_bodies_permitted do |object|
- Truck.swap_bodies_by_truck(object.truck_type)
- end
- class << self
- def truck_response_swap_bodies
- Truck.truck_types.each_with_object([]) do |el, arr|
- arr << { resource: el[0], swap_body_types: swap_bodies_by_truck(el[0]) }
- end
- end
- def swap_bodies_by_truck(resource)
- Truck.truck_types[resource].eql?(0) ? SwapBody.swap_body_types.keys : []
- end
- end
- trucks = current_account.trucks.left_joins(:expeditions).where(expeditions: { id: nil })
- drivers = current_account.drivers.left_joins(:expeditions).where(expeditions: { id: nil })
- swap_bodies = current_account.swap_bodies.left_joins(:trips).where(trips: { id: nil })
- 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 }
- attributes.select do |x|
- if klass_enum.include?(x.values.shift)
- x[el.keys.shift] = klass_enum[el.values.shift]
- else
- attributes
- end
- end
- destination
- current_account.expeditions.joins(trips: :destination_warehouse).where(trips: { warehouses: { address: params[:destination]}})
- current_account.expeditions.joins(trips: :destination_warehouse).where('warehouses.address ilike ?', "%#{destination}%")
- origin
- current_account.expeditions.joins(trips: :origin_warehouse).where(trips: { warehouses: { address: params[:origin]}})
- current_account.expeditions.joins(trips: :origin_warehouse).where('warehouses.address ilike ?', "%#{origin}%")
- scope :date_range, (proc { |from, to|
- if from && to
- where(created_at: from.beginning_of_day..to.end_of_day)
- else
- where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day)
- end
- })
- refactor serializadores
- vista de administracion -> from expedicion
- filtros from expedicion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement