Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref-1556, improve filtering destinations by rate plan, country #1566

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/models/routing/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,12 @@ class Routing::Destination < ApplicationRecord
scope :time_valid, -> { where('valid_till >= :time AND valid_from < :time', time: Time.now) }
scope :rateplan_id_filter, lambda { |value|
rate_group_ids = Routing::RatePlanGroup.where(rateplan_id: value).pluck(:rate_group_id)
where('rate_group_id IN (?)', rate_group_ids)
where(rate_group_id: rate_group_ids)
}
scope :country_id_filter, lambda { |value|
network_prefix_ids = System::NetworkPrefix.where(country_id: value).pluck(:id)
where(network_prefix_id: network_prefix_ids)
}

scope :where_customer, lambda { |id|
joins(:rate_group).joins(:rateplans).joins(:customers_auths).where(CustomersAuth.table_name => { customer_id: id })
}
Expand Down Expand Up @@ -176,6 +179,7 @@ def self.ransackable_scopes(_auth_object = nil)
tagged
routing_tag_ids_count_equals
rateplan_id_filter
country_id_filter
]
end
end
8 changes: 6 additions & 2 deletions app/resources/api/rest/admin/routing/destination_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,12 @@ module CONST
ransack_filter :reverse_billing, type: :boolean
ransack_filter :profit_control_mode_id, type: :number
ransack_filter :rate_policy_id, type: :number
ransack_filter :rateplan_id, type: :foreign_key, column: :rate_group_rateplans_id
ransack_filter :country_id, type: :foreign_key, column: :network_prefix_country_id
filter :rateplan_id_eq, apply: lambda { |records, values, _options|
records.ransack(rateplan_id_filter: values).result
}
filter :country_id_eq, apply: lambda { |records, values, _options|
records.ransack(country_id_filter: values).result
}

def self.updatable_fields(_context)
%i[
Expand Down
Loading