Improve storage locations search [SCI-11129]

This commit is contained in:
Anton 2024-10-02 11:02:18 +02:00
parent 5ab1fbbab9
commit ba1162c453
2 changed files with 20 additions and 2 deletions

View file

@ -6,6 +6,7 @@ class StorageLocation < ApplicationRecord
ID_PREFIX = 'SL'
include PrefixedIdModel
include Shareable
include SearchableModel
default_scope -> { kept }

View file

@ -44,8 +44,25 @@ module Lists
@records = @records.where(parent_id: @parent_id)
end
@records = @records.where('LOWER(storage_locations.name) ILIKE ?', "%#{@filters[:query].downcase}%") if @filters[:query].present?
@records = @records.where('LOWER(storage_locations.name) ILIKE ?', "%#{@params[:search].downcase}%") if @params[:search].present?
if @filters[:query].present?
@records = @records.where_attributes_like(
[
'storage_locations.name',
'storage_locations.description',
StorageLocation::PREFIXED_ID_SQL
], @filters[:query]
)
end
if @params[:search].present?
@records = @records.where_attributes_like(
[
'storage_locations.name',
'storage_locations.description',
StorageLocation::PREFIXED_ID_SQL
], @params[:search]
)
end
end
private