Enhance identical contact lookup

#746
This commit is contained in:
Artur Beljajev 2018-03-06 10:39:32 +02:00
parent c733c0910d
commit ecc68f083d
3 changed files with 67 additions and 25 deletions

View file

@ -1,18 +1,34 @@
module Concerns::Contact::Identical
extend ActiveSupport::Concern
ATTRIBUTE_FILTER = %w[
IDENTIFIABLE_ATTRIBUTES = %w[
name
email
phone
fax
ident
ident_type
ident_country_code
phone
email
org_name
]
private_constant :ATTRIBUTE_FILTER
private_constant :IDENTIFIABLE_ATTRIBUTES
def identical(registrar)
self.class.where(attributes.slice(*ATTRIBUTE_FILTER)).where(registrar: registrar)
self.class.where(identifiable_hash)
.where(["statuses = ?::character varying[]", "{#{read_attribute(:statuses).join(',')}}"])
.where(registrar: registrar)
.where.not(id: id).take
end
private
def identifiable_hash
attributes = IDENTIFIABLE_ATTRIBUTES
if self.class.address_processing?
attributes += self.class.address_attribute_names
end
slice(*attributes)
end
end