diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 8c522c466..b72c4c70d 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -45,6 +45,13 @@ class SalesLog < Log query.all } scope :filter_by_purchaser_code, ->(purchid) { where("purchid ILIKE ?", "%#{purchid}%") } + scope :filter_by_salestype, ->(salestype) { where(ownershipsch: salestype) } + scope :filter_by_salestypes, lambda { |salestypes, _user = nil| + first_salestype = salestypes.shift + query = filter_by_salestype(first_salestype) + salestypes.each { |salestype| query = query.or(filter_by_salestype(salestype)) } + query.all + } scope :search_by, lambda { |param| sanitized_param = ActiveRecord::Base.sanitize_sql(param) param_without_spaces = sanitized_param.delete(" ") diff --git a/app/models/user.rb b/app/models/user.rb index 823e78b2b..1733aeb7d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -228,9 +228,9 @@ class User < ApplicationRecord def logs_filters(specific_org: false) if (support? && !specific_org) || organisation.has_managing_agents? || organisation.has_stock_owners? - %w[years status needstypes assigned_to user owning_organisation managing_organisation bulk_upload_id user_text_search owning_organisation_text_search managing_organisation_text_search] + %w[years status needstypes salestypes assigned_to user owning_organisation managing_organisation bulk_upload_id user_text_search owning_organisation_text_search managing_organisation_text_search] else - %w[years status needstypes assigned_to user bulk_upload_id user_text_search] + %w[years status needstypes salestypes assigned_to user bulk_upload_id user_text_search] end end