class CompaniesHouseCompany(BaseESModel): """Elasticsearch representation of CompaniesHouseCompany model.""" id = Keyword() company_category = fields.NormalizedKeyword() company_number = fields.NormalizedKeyword() company_status = fields.NormalizedKeyword() incorporation_date = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) registered_address = fields.address_field(index_country=False) # TODO: delete once the migration to nested registered address is complete registered_address_1 = Text() registered_address_2 = Text() registered_address_town = fields.NormalizedKeyword() registered_address_county = Text() registered_address_postcode = Text( copy_to='registered_address_postcode_trigram') registered_address_postcode_trigram = fields.TrigramText() registered_address_country = fields.id_name_field() sic_code_1 = Text() sic_code_2 = Text() sic_code_3 = Text() sic_code_4 = Text() uri = Text() COMPUTED_MAPPINGS = { 'registered_address': partial(dict_utils.address_dict, prefix='registered_address'), } MAPPINGS = { 'id': str, # TODO: delete once the migration to nested registered address is complete 'registered_address_country': dict_utils.id_name_dict, } SEARCH_FIELDS = ( 'name', # to find 2-letter words 'name.trigram', 'company_number', 'registered_address.postcode.trigram', ) class Meta: """Default document meta data.""" doc_type = DOC_TYPE class Index: doc_type = DOC_TYPE
class CompaniesHouseCompany(BaseESModel): """Elasticsearch representation of CompaniesHouseCompany model.""" id = Keyword() company_category = fields.SortableCaseInsensitiveKeywordText() company_number = fields.SortableCaseInsensitiveKeywordText() company_status = fields.SortableCaseInsensitiveKeywordText() incorporation_date = Date() name = fields.SortableText(copy_to=[ 'name_keyword', 'name_trigram', ], ) name_keyword = fields.SortableCaseInsensitiveKeywordText() name_trigram = fields.TrigramText() registered_address_1 = Text() registered_address_2 = Text() registered_address_town = fields.SortableCaseInsensitiveKeywordText() registered_address_county = Text() registered_address_postcode = Text( copy_to='registered_address_postcode_trigram') registered_address_postcode_trigram = fields.TrigramText() registered_address_country = fields.nested_id_name_field() sic_code_1 = Text() sic_code_2 = Text() sic_code_3 = Text() sic_code_4 = Text() uri = Text() MAPPINGS = { 'id': str, 'registered_address_country': dict_utils.id_name_dict, } SEARCH_FIELDS = ( # to match names like A & B 'name', 'name_trigram', 'company_number', 'registered_address_postcode_trigram', ) class Meta: """Default document meta data.""" doc_type = 'companieshousecompany'
class SearchSimpleModel(BaseSearchModel): """OpenSearch representation of SimpleModel model.""" id = Keyword() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) country = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) address = Text(fields={ 'trigram': fields.TrigramText(), }, ) date = Date() SEARCH_FIELDS = ( 'name', 'name.trigram', 'country.trigram', 'address.trigram', )
class ESSimpleModel(BaseESModel): """Elasticsearch representation of SimpleModel model.""" id = Keyword() name = fields.SortableText(copy_to=['name_keyword', 'name_trigram']) name_keyword = fields.SortableCaseInsensitiveKeywordText() name_trigram = fields.TrigramText() MAPPINGS = { 'id': str, } SEARCH_FIELDS = ( 'name', 'name_trigram', ) class Meta: """Default document meta data.""" doc_type = 'simplemodel'
class ESSimpleModel(BaseESModel): """Elasticsearch representation of SimpleModel model.""" id = Keyword() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) date = Date() SEARCH_FIELDS = ( 'name', 'name.trigram', ) class Meta: """Default document meta data.""" doc_type = DOC_TYPE class Index: doc_type = DOC_TYPE
class Company(BaseESModel): """Elasticsearch representation of Company model.""" id = Keyword() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() business_type = fields.id_name_field() companies_house_data = fields.ch_company_field() company_number = fields.NormalizedKeyword() created_on = Date() description = fields.EnglishText() employee_range = fields.id_name_field() export_experience_category = fields.id_name_field() export_to_countries = fields.id_name_field() future_interest_countries = fields.id_name_field() global_headquarters = fields.id_name_field() headquarter_type = fields.id_name_field() modified_on = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) reference_code = fields.NormalizedKeyword() sector = fields.sector_field() address = fields.address_field() registered_address = fields.address_field() # TODO: delete once the migration to address and registered address is complete registered_address_1 = Text() registered_address_2 = Text() registered_address_town = fields.NormalizedKeyword() registered_address_county = Text() registered_address_country = fields.id_name_partial_field() registered_address_postcode = Text(copy_to=[ 'registered_address_postcode_trigram', ], ) registered_address_postcode_trigram = fields.TrigramText() trading_address_1 = Text() trading_address_2 = Text() trading_address_town = fields.NormalizedKeyword() trading_address_county = Text() trading_address_postcode = Text( copy_to=['trading_address_postcode_trigram'], ) trading_address_postcode_trigram = fields.TrigramText() trading_address_country = fields.id_name_partial_field() trading_names = Text(copy_to=['trading_names_trigram'], ) trading_names_trigram = fields.TrigramText() turnover_range = fields.id_name_field() uk_region = fields.id_name_field() uk_based = Boolean() vat_number = Keyword(index=False) duns_number = Keyword() website = Text() suggest = Completion() COMPUTED_MAPPINGS = { 'suggest': get_suggestions, 'address': partial(dict_utils.address_dict, prefix='address'), 'registered_address': partial(dict_utils.address_dict, prefix='registered_address'), } MAPPINGS = { 'archived_by': dict_utils.contact_or_adviser_dict, 'business_type': dict_utils.id_name_dict, 'companies_house_data': dict_utils.ch_company_dict, 'employee_range': dict_utils.id_name_dict, 'export_experience_category': dict_utils.id_name_dict, 'export_to_countries': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'future_interest_countries': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'global_headquarters': dict_utils.id_name_dict, 'headquarter_type': dict_utils.id_name_dict, 'sector': dict_utils.sector_dict, # TODO: delete once the migration to address and registered address is complete 'registered_address_country': dict_utils.id_name_dict, 'trading_address_country': dict_utils.id_name_dict, 'turnover_range': dict_utils.id_name_dict, 'uk_based': bool, 'uk_region': dict_utils.id_name_dict, } SEARCH_FIELDS = ( 'id', 'name', # to find 2-letter words 'name.trigram', 'company_number', 'trading_names', # to find 2-letter words 'trading_names_trigram', 'reference_code', 'address.country.name.trigram', 'address.postcode.trigram', 'registered_address.country.name.trigram', 'registered_address.postcode.trigram', ) class Meta: """Default document meta data.""" doc_type = DOC_TYPE class Index: doc_type = DOC_TYPE
class LargeCapitalOpportunity(BaseSearchModel): """OpenSearch representation of LargeCapitalOpportunity.""" id = Keyword() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) type = fields.id_unindexed_name_field() description = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) uk_region_locations = fields.id_unindexed_name_field() promoters = fields.company_field() required_checks_conducted = fields.id_unindexed_name_field() required_checks_conducted_by = fields.contact_or_adviser_field( include_dit_team=True) required_checks_conducted_on = Date() lead_dit_relationship_manager = fields.contact_or_adviser_field( include_dit_team=True) other_dit_contacts = fields.contact_or_adviser_field(include_dit_team=True) asset_classes = fields.id_unindexed_name_field() opportunity_value_type = fields.id_unindexed_name_field() opportunity_value = Long() construction_risks = fields.id_unindexed_name_field() total_investment_sought = Long() current_investment_secured = Long() investment_types = fields.id_unindexed_name_field() estimated_return_rate = fields.id_unindexed_name_field() time_horizons = fields.id_unindexed_name_field() investment_projects = fields.id_unindexed_name_field() status = fields.id_unindexed_name_field() sources_of_funding = fields.id_unindexed_name_field() dit_support_provided = Boolean() reasons_for_abandonment = fields.id_unindexed_name_field() created_by = fields.contact_or_adviser_field(include_dit_team=True) created_on = Date() modified_on = Date() _MAIN_FIELD_MAPPINGS = { 'type': dict_utils.id_name_dict, 'status': dict_utils.id_name_dict, 'created_by': dict_utils.adviser_dict_with_team, } _DETAIL_FIELD_MAPPINGS = { 'uk_region_locations': _get_many_to_many_list, 'promoters': _get_company_list, 'required_checks_conducted': dict_utils.id_name_dict, 'required_checks_conducted_by': dict_utils.adviser_dict_with_team, 'lead_dit_relationship_manager': dict_utils.adviser_dict_with_team, 'other_dit_contacts': _get_adviser_list, 'asset_classes': _get_many_to_many_list, 'opportunity_value_type': dict_utils.id_name_dict, 'construction_risks': _get_many_to_many_list, 'investment_projects': _get_investment_project_list, 'sources_of_funding': _get_many_to_many_list, 'reasons_for_abandonment': _get_many_to_many_list, } _REQUIREMENT_FIELD_MAPPINGS = { 'investment_types': _get_many_to_many_list, 'estimated_return_rate': dict_utils.id_name_dict, 'time_horizons': _get_many_to_many_list, } MAPPINGS = { **_MAIN_FIELD_MAPPINGS, **_DETAIL_FIELD_MAPPINGS, **_REQUIREMENT_FIELD_MAPPINGS, }
class Contact(BaseSearchModel): """OpenSearch representation of Contact model.""" id = Keyword() address_1 = Text() address_2 = Text() address_town = fields.NormalizedKeyword() address_county = fields.NormalizedKeyword() address_postcode = Text() address_country = fields.id_name_field() address_area = fields.id_name_field() address_same_as_company = Boolean() adviser = fields.contact_or_adviser_field() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() company = fields.company_field() company_sector = fields.sector_field() company_uk_region = fields.id_name_field() created_by = fields.contact_or_adviser_field(include_dit_team=True) created_on = Date() email = fields.NormalizedKeyword() first_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) job_title = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) last_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) modified_on = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) name_with_title = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) notes = fields.EnglishText() primary = Boolean() full_telephone_number = Keyword() title = fields.id_name_field() MAPPINGS = { 'adviser': dict_utils.contact_or_adviser_dict, 'archived_by': dict_utils.contact_or_adviser_dict, 'company': dict_utils.company_dict, 'created_by': dict_utils.adviser_dict_with_team, 'title': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'address_1': contact_dict_utils.computed_address_field('address_1'), 'address_2': contact_dict_utils.computed_address_field('address_2'), 'address_town': contact_dict_utils.computed_address_field('address_town'), 'address_county': contact_dict_utils.computed_address_field('address_county'), 'address_postcode': contact_dict_utils.computed_address_field('address_postcode'), 'address_country': contact_dict_utils.computed_address_field('address_country'), 'address_area': contact_dict_utils.computed_address_field('address_area'), 'company_sector': dict_utils.computed_nested_sector_dict('company.sector'), 'company_uk_region': dict_utils.computed_nested_id_name_dict('company.uk_region'), } SEARCH_FIELDS = ( 'id', 'name', 'name.trigram', 'name_with_title', 'name_with_title.trigram', 'email', 'company.name', 'company.name.trigram', 'job_title', 'job_title.trigram', 'full_telephone_number', )
class Event(BaseESModel): """Elasticsearch representation of Event model.""" id = Keyword() address_1 = Text() address_2 = Text() address_town = fields.SortableCaseInsensitiveKeywordText() address_county = fields.SortableCaseInsensitiveKeywordText() address_postcode = Text(copy_to='address_postcode_trigram') address_postcode_trigram = fields.TrigramText() address_country = fields.nested_id_name_partial_field('address_country') created_on = Date() disabled_on = Date() end_date = Date() event_type = fields.nested_id_name_field() lead_team = fields.nested_id_name_field() location_type = fields.nested_id_name_field() modified_on = Date() name = fields.SortableText(copy_to=['name_keyword', 'name_trigram']) name_keyword = fields.SortableCaseInsensitiveKeywordText() name_trigram = fields.TrigramText() notes = fields.EnglishText() organiser = fields.nested_contact_or_adviser_field('organiser') related_programmes = fields.nested_id_name_partial_field('related_programmes') service = fields.nested_id_name_field() start_date = Date() teams = fields.nested_id_name_partial_field('teams') uk_region = fields.nested_id_name_partial_field('uk_region') MAPPINGS = { 'id': str, 'address_country': dict_utils.id_name_dict, 'event_type': dict_utils.id_name_dict, 'lead_team': dict_utils.id_name_dict, 'location_type': dict_utils.id_name_dict, 'organiser': dict_utils.contact_or_adviser_dict, 'related_programmes': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'service': dict_utils.id_name_dict, 'teams': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'uk_region': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = {} SEARCH_FIELDS = ( 'name', 'name_trigram', 'address_country.name_trigram', 'address_postcode_trigram', 'uk_region.name_trigram', 'organiser.name_trigram', 'teams.name', 'teams.name_trigram', 'related_programmes.name', 'related_programmes.name_trigram', ) class Meta: """Default document meta data.""" doc_type = 'event'
class Event(BaseESModel): """Elasticsearch representation of Event model.""" id = Keyword() address_1 = Text() address_2 = Text() address_town = fields.NormalizedKeyword() address_county = fields.NormalizedKeyword() address_postcode = fields.TextWithTrigram() address_country = fields.id_name_partial_field() created_on = Date() disabled_on = Date() end_date = Date() event_type = fields.id_name_field() lead_team = fields.id_name_field() location_type = fields.id_name_field() modified_on = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) notes = fields.EnglishText() organiser = fields.contact_or_adviser_field() related_programmes = fields.id_name_partial_field() service = fields.id_name_field() start_date = Date() teams = fields.id_name_partial_field() uk_region = fields.id_name_partial_field() MAPPINGS = { 'address_country': dict_utils.id_name_dict, 'event_type': dict_utils.id_name_dict, 'lead_team': dict_utils.id_name_dict, 'location_type': dict_utils.id_name_dict, 'organiser': dict_utils.contact_or_adviser_dict, 'related_programmes': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'service': dict_utils.id_name_dict, 'teams': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'uk_region': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = {} SEARCH_FIELDS = ( 'id', 'name', 'name.trigram', 'address_country.name.trigram', 'address_postcode.trigram', 'uk_region.name.trigram', 'organiser.name.trigram', 'teams.name', 'teams.name.trigram', 'related_programmes.name', 'related_programmes.name.trigram', ) class Meta: """Default document meta data.""" doc_type = DEFAULT_MAPPING_TYPE class Index: doc_type = DEFAULT_MAPPING_TYPE
class Company(BaseESModel): """Elasticsearch representation of Company model.""" id = Keyword() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() business_type = fields.id_name_field() company_number = fields.NormalizedKeyword() created_on = Date() description = fields.EnglishText() employee_range = fields.id_name_field() export_experience_category = fields.id_name_field() export_to_countries = fields.id_name_field() future_interest_countries = fields.id_name_field() global_headquarters = fields.id_name_field() headquarter_type = fields.id_name_field() modified_on = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) reference_code = fields.NormalizedKeyword() sector = fields.sector_field() address = fields.address_field() registered_address = fields.address_field() one_list_group_global_account_manager = _adviser_field_with_indexed_id() trading_names = fields.TextWithTrigram() turnover_range = fields.id_name_field() uk_region = fields.id_name_field() uk_based = Boolean() uk_address_postcode = fields.PostcodeKeyword() uk_registered_address_postcode = fields.PostcodeKeyword() vat_number = Keyword(index=False) duns_number = Keyword() website = Text() suggest = Completion(contexts=[ { 'name': 'country', 'type': 'category', }, ], ) latest_interaction_date = Date() COMPUTED_MAPPINGS = { 'suggest': get_suggestions, 'address': partial(dict_utils.address_dict, prefix='address'), 'registered_address': partial(dict_utils.address_dict, prefix='registered_address'), 'one_list_group_global_account_manager': dict_utils.computed_field_function( 'get_one_list_group_global_account_manager', dict_utils.contact_or_adviser_dict, ), 'latest_interaction_date': lambda obj: obj.latest_interaction_date, 'uk_address_postcode': lambda obj: obj.address_postcode if obj.uk_based else '', 'uk_registered_address_postcode': lambda obj: obj.registered_address_postcode if obj.uk_based else '', } MAPPINGS = { 'archived_by': dict_utils.contact_or_adviser_dict, 'business_type': dict_utils.id_name_dict, 'employee_range': dict_utils.id_name_dict, 'export_experience_category': dict_utils.id_name_dict, 'export_to_countries': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'future_interest_countries': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'global_headquarters': dict_utils.id_name_dict, 'headquarter_type': dict_utils.id_name_dict, 'sector': dict_utils.sector_dict, 'turnover_range': dict_utils.id_name_dict, 'uk_based': bool, 'uk_region': dict_utils.id_name_dict, } SEARCH_FIELDS = ( 'id', 'name', # to find 2-letter words 'name.trigram', 'company_number', 'trading_names', # to find 2-letter words 'trading_names.trigram', 'reference_code', 'address.country.name.trigram', 'address.postcode.trigram', 'registered_address.country.name.trigram', 'registered_address.postcode.trigram', ) class Meta: """Default document meta data.""" doc_type = DOC_TYPE class Index: doc_type = DOC_TYPE
class Company(BaseSearchModel): """ OpenSearch representation of Company model. """ id = Keyword() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() business_type = fields.id_name_field() company_number = fields.NormalizedKeyword() created_on = Date() description = fields.EnglishText() employee_range = fields.id_name_field() export_experience_category = fields.id_name_field() export_to_countries = fields.id_name_field() future_interest_countries = fields.id_name_field() global_headquarters = fields.id_name_field() headquarter_type = fields.id_name_field() modified_on = Date() name = Text( fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) reference_code = fields.NormalizedKeyword() sector = fields.sector_field() address = fields.address_field() registered_address = fields.address_field() one_list_group_global_account_manager = _adviser_field_with_indexed_id() trading_names = fields.TextWithTrigram() turnover_range = fields.id_name_field() uk_region = fields.id_name_field() uk_based = Boolean() uk_address_postcode = fields.PostcodeKeyword() uk_registered_address_postcode = fields.PostcodeKeyword() vat_number = Keyword(index=False) duns_number = Keyword() website = Text() latest_interaction_date = Date() export_segment = Text() export_sub_segment = Text() COMPUTED_MAPPINGS = { 'address': partial(dict_utils.address_dict, prefix='address'), 'registered_address': partial(dict_utils.address_dict, prefix='registered_address'), 'one_list_group_global_account_manager': dict_utils.computed_field_function( 'get_one_list_group_global_account_manager', dict_utils.contact_or_adviser_dict, ), 'export_to_countries': lambda obj: [ dict_utils.id_name_dict(o.country) for o in obj.export_countries.all() if o.status == CompanyExportCountry.Status.CURRENTLY_EXPORTING ], 'future_interest_countries': lambda obj: [ dict_utils.id_name_dict(o.country) for o in obj.export_countries.all() if o.status == CompanyExportCountry.Status.FUTURE_INTEREST ], 'latest_interaction_date': lambda obj: obj.latest_interaction_date, 'uk_address_postcode': lambda obj: obj.address_postcode if obj.uk_based else '', 'uk_registered_address_postcode': lambda obj: obj.registered_address_postcode if obj.uk_based else '', } MAPPINGS = { 'archived_by': dict_utils.contact_or_adviser_dict, 'business_type': dict_utils.id_name_dict, 'employee_range': dict_utils.id_name_dict, 'export_experience_category': dict_utils.id_name_dict, 'global_headquarters': dict_utils.id_name_dict, 'headquarter_type': dict_utils.id_name_dict, 'sector': dict_utils.sector_dict, 'turnover_range': dict_utils.id_name_dict, 'uk_based': bool, 'uk_region': dict_utils.id_name_dict, } SEARCH_FIELDS = ( 'id', 'name', # to find 2-letter words 'name.trigram', 'company_number', 'trading_names', # to find 2-letter words 'trading_names.trigram', 'reference_code', 'sector.name', 'address.line_1.trigram', 'address.line_2.trigram', 'address.town.trigram', 'address.county.trigram', 'address.area.name.trigram', 'address.postcode', 'address.country.name.trigram', 'registered_address.line_1.trigram', 'registered_address.line_2.trigram', 'registered_address.town.trigram', 'registered_address.county.trigram', 'registered_address.area.name.trigram', 'registered_address.postcode', 'registered_address.country.name.trigram', )
class Company(BaseESModel): """Elasticsearch representation of Company model.""" id = Keyword() archived = Boolean() archived_by = fields.nested_contact_or_adviser_field('archived_by') archived_on = Date() archived_reason = Text() business_type = fields.nested_id_name_field() classification = fields.nested_id_name_field() companies_house_data = fields.nested_ch_company_field() company_number = fields.SortableCaseInsensitiveKeywordText() contacts = fields.nested_contact_or_adviser_field('contacts') created_on = Date() description = fields.EnglishText() employee_range = fields.nested_id_name_field() export_experience_category = fields.nested_id_name_field() export_to_countries = fields.nested_id_name_field() future_interest_countries = fields.nested_id_name_field() global_headquarters = fields.nested_id_name_field() headquarter_type = fields.nested_id_name_field() modified_on = Date() name = fields.SortableText(copy_to=['name_keyword', 'name_trigram']) name_keyword = fields.SortableCaseInsensitiveKeywordText() name_trigram = fields.TrigramText() one_list_account_owner = fields.nested_contact_or_adviser_field('one_list_account_owner') reference_code = fields.SortableCaseInsensitiveKeywordText() registered_address_1 = Text() registered_address_2 = Text() registered_address_town = fields.SortableCaseInsensitiveKeywordText() registered_address_county = Text() registered_address_country = fields.nested_id_name_partial_field( 'registered_address_country', ) registered_address_postcode = Text( copy_to=[ 'registered_address_postcode_trigram', ], ) registered_address_postcode_trigram = fields.TrigramText() sector = fields.nested_sector_field() trading_address_1 = Text() trading_address_2 = Text() trading_address_town = fields.SortableCaseInsensitiveKeywordText() trading_address_county = Text() trading_address_postcode = Text( copy_to=['trading_address_postcode_trigram'], ) trading_address_postcode_trigram = fields.TrigramText() trading_address_country = fields.nested_id_name_partial_field( 'trading_address_country', ) trading_name = fields.SortableText( copy_to=[ 'trading_name_keyword', 'trading_name_trigram', ], ) trading_name_keyword = fields.SortableCaseInsensitiveKeywordText() trading_name_trigram = fields.TrigramText() turnover_range = fields.nested_id_name_field() uk_region = fields.nested_id_name_field() uk_based = Boolean() vat_number = Keyword(index=False) website = Text() COMPUTED_MAPPINGS = { 'trading_name': attrgetter('alias'), } MAPPINGS = { 'id': str, 'archived_by': dict_utils.contact_or_adviser_dict, 'business_type': dict_utils.id_name_dict, 'classification': dict_utils.id_name_dict, 'companies_house_data': dict_utils.ch_company_dict, 'contacts': lambda col: [dict_utils.contact_or_adviser_dict(c) for c in col.all()], 'employee_range': dict_utils.id_name_dict, 'export_experience_category': dict_utils.id_name_dict, 'export_to_countries': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'future_interest_countries': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'global_headquarters': dict_utils.id_name_dict, 'headquarter_type': dict_utils.id_name_dict, 'one_list_account_owner': dict_utils.contact_or_adviser_dict, 'registered_address_country': dict_utils.id_name_dict, 'sector': dict_utils.sector_dict, 'trading_address_country': dict_utils.id_name_dict, 'turnover_range': dict_utils.id_name_dict, 'uk_based': bool, 'uk_region': dict_utils.id_name_dict, } SEARCH_FIELDS = ( 'name', 'name_trigram', 'company_number', 'trading_name', 'trading_name_trigram', 'reference_code', 'registered_address_country.name_trigram', 'registered_address_postcode_trigram', 'trading_address_country.name_trigram', 'trading_address_postcode_trigram', 'uk_region.name_trigram', ) class Meta: """Default document meta data.""" doc_type = 'company'
class Contact(BaseESModel): """Elasticsearch representation of Contact model.""" id = Keyword() address_1 = Text() address_2 = Text() address_town = fields.NormalizedKeyword() address_county = fields.NormalizedKeyword() address_postcode = Text() address_country = fields.id_name_field() address_same_as_company = Boolean() adviser = fields.contact_or_adviser_field() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() company = fields.company_field() company_sector = fields.sector_field() company_uk_region = fields.id_name_field() created_by = fields.contact_or_adviser_field(include_dit_team=True) created_on = Date() email = fields.NormalizedKeyword() email_alternative = Text() first_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) job_title = fields.NormalizedKeyword() last_name = Text(fields={ 'keyword': fields.NormalizedKeyword(), }, ) modified_on = Date() name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) notes = fields.EnglishText() primary = Boolean() telephone_alternative = Text() telephone_countrycode = Keyword() telephone_number = Keyword() title = fields.id_name_field() MAPPINGS = { 'adviser': dict_utils.contact_or_adviser_dict, 'archived_by': dict_utils.contact_or_adviser_dict, 'company': dict_utils.company_dict, 'created_by': dict_utils.adviser_dict_with_team, 'title': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'address_1': contact_dict_utils.computed_address_field('address_1'), 'address_2': contact_dict_utils.computed_address_field('address_2'), 'address_town': contact_dict_utils.computed_address_field('address_town'), 'address_county': contact_dict_utils.computed_address_field('address_county'), 'address_postcode': contact_dict_utils.computed_address_field('address_postcode'), 'address_country': contact_dict_utils.computed_address_field('address_country'), 'company_sector': dict_utils.computed_nested_sector_dict('company.sector'), 'company_uk_region': dict_utils.computed_nested_id_name_dict('company.uk_region'), } SEARCH_FIELDS = ( 'id', 'name', 'name.trigram', 'email', 'email_alternative', 'company.name', 'company.name.trigram', ) class Meta: """Default document meta data.""" doc_type = DEFAULT_MAPPING_TYPE class Index: doc_type = DEFAULT_MAPPING_TYPE
class Contact(BaseESModel): """Elasticsearch representation of Contact model.""" id = Keyword() accepts_dit_email_marketing = Boolean() address_1 = Text() address_2 = Text() address_town = fields.SortableCaseInsensitiveKeywordText() address_county = fields.SortableCaseInsensitiveKeywordText() address_postcode = Text() address_country = fields.nested_id_name_field() address_same_as_company = Boolean() adviser = fields.nested_contact_or_adviser_field('adviser') archived = Boolean() archived_by = fields.nested_contact_or_adviser_field('archived_by') archived_on = Date() archived_reason = Text() company = fields.nested_company_field('company') company_sector = fields.nested_sector_field() company_uk_region = fields.nested_id_name_field() created_by = fields.nested_contact_or_adviser_field('created_by', include_dit_team=True) created_on = Date() email = fields.SortableCaseInsensitiveKeywordText() email_alternative = Text() first_name = fields.SortableText( copy_to=[ 'name', 'name_keyword', 'name_trigram', ], ) job_title = fields.SortableCaseInsensitiveKeywordText() last_name = fields.SortableText( copy_to=[ 'name', 'name_keyword', 'name_trigram', ], ) modified_on = Date() name = fields.SortableText() name_keyword = fields.SortableCaseInsensitiveKeywordText() # field is being aggregated name_trigram = fields.TrigramText() notes = fields.EnglishText() primary = Boolean() telephone_alternative = Text() telephone_countrycode = Keyword() telephone_number = Keyword() title = fields.nested_id_name_field() MAPPINGS = { 'id': str, 'adviser': dict_utils.contact_or_adviser_dict, 'archived_by': dict_utils.contact_or_adviser_dict, 'company': dict_utils.company_dict, 'created_by': dict_utils.adviser_dict_with_team, 'title': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'address_1': contact_dict_utils.computed_address_field('address_1'), 'address_2': contact_dict_utils.computed_address_field('address_2'), 'address_town': contact_dict_utils.computed_address_field('address_town'), 'address_county': contact_dict_utils.computed_address_field('address_county'), 'address_postcode': contact_dict_utils.computed_address_field('address_postcode'), 'address_country': contact_dict_utils.computed_address_field('address_country'), 'company_sector': dict_utils.computed_nested_sector_dict('company.sector'), 'company_uk_region': dict_utils.computed_nested_id_name_dict('company.uk_region'), } SEARCH_FIELDS = ( 'name', 'name_trigram', 'email', 'email_alternative', 'company.name', 'company.name_trigram', ) class Meta: """Default document meta data.""" doc_type = 'contact'
class InvestmentProject(BaseESModel): """Elasticsearch representation of InvestmentProject.""" id = Keyword() actual_land_date = Date() actual_uk_regions = fields.id_name_field() address_1 = Text() address_2 = Text() address_town = fields.NormalizedKeyword() address_postcode = Text() approved_commitment_to_invest = Boolean() approved_fdi = Boolean() approved_good_value = Boolean() approved_high_value = Boolean() approved_landed = Boolean() approved_non_fdi = Boolean() allow_blank_estimated_land_date = Boolean(index=False) allow_blank_possible_uk_regions = Boolean(index=False) anonymous_description = fields.EnglishText() archived = Boolean() archived_by = fields.contact_or_adviser_field() archived_on = Date() archived_reason = Text() associated_non_fdi_r_and_d_project = _related_investment_project_field() average_salary = fields.id_name_field() business_activities = fields.id_name_field() client_cannot_provide_foreign_investment = Boolean() client_cannot_provide_total_investment = Boolean() client_contacts = fields.contact_or_adviser_field() client_relationship_manager = fields.contact_or_adviser_field( include_dit_team=True) client_requirements = Text(index=False) comments = fields.EnglishText() country_investment_originates_from = fields.id_name_field() country_lost_to = Object(properties={ 'id': Keyword(index=False), 'name': Text(index=False), }, ) created_on = Date() created_by = fields.contact_or_adviser_field(include_dit_team=True) date_abandoned = Date() date_lost = Date() delivery_partners = fields.id_name_field() description = fields.EnglishText() estimated_land_date = Date() export_revenue = Boolean() fdi_type = fields.id_name_field() fdi_value = fields.id_name_field() foreign_equity_investment = Double() government_assistance = Boolean() intermediate_company = fields.id_name_field() investor_company = fields.id_name_partial_field() investor_company_country = fields.id_name_field() investment_type = fields.id_name_field() investor_type = fields.id_name_field() level_of_involvement = fields.id_name_field() likelihood_to_land = fields.id_name_field() project_assurance_adviser = fields.contact_or_adviser_field( include_dit_team=True) project_manager = fields.contact_or_adviser_field(include_dit_team=True) name = Text(fields={ 'keyword': fields.NormalizedKeyword(), 'trigram': fields.TrigramText(), }, ) new_tech_to_uk = Boolean() non_fdi_r_and_d_budget = Boolean() number_new_jobs = Integer() number_safeguarded_jobs = Long() modified_on = Date() project_arrived_in_triage_on = Date() project_code = fields.NormalizedKeyword(fields={ 'trigram': fields.TrigramText(), }, ) proposal_deadline = Date() other_business_activity = Text(index=False) quotable_as_public_case_study = Boolean() r_and_d_budget = Boolean() reason_abandoned = Text(index=False) reason_delayed = Text(index=False) reason_lost = Text(index=False) referral_source_activity = fields.id_name_field() referral_source_activity_event = fields.NormalizedKeyword() referral_source_activity_marketing = fields.id_name_field() referral_source_activity_website = fields.id_name_field() referral_source_adviser = Object(properties={ 'id': Keyword(index=False), 'first_name': Text(index=False), 'last_name': Text(index=False), 'name': Text(index=False), }, ) sector = fields.sector_field() site_decided = Boolean() some_new_jobs = Boolean() specific_programme = fields.id_name_field() stage = fields.id_name_field() status = fields.NormalizedKeyword() team_members = fields.contact_or_adviser_field(include_dit_team=True) total_investment = Double() uk_company = fields.id_name_partial_field() uk_company_decided = Boolean() uk_region_locations = fields.id_name_field() will_new_jobs_last_two_years = Boolean() level_of_involvement_simplified = Keyword() gross_value_added = Double() MAPPINGS = { 'actual_uk_regions': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'archived_by': dict_utils.contact_or_adviser_dict, 'associated_non_fdi_r_and_d_project': dict_utils.investment_project_dict, 'average_salary': dict_utils.id_name_dict, 'business_activities': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'client_contacts': lambda col: [dict_utils.contact_or_adviser_dict(c) for c in col.all()], 'client_relationship_manager': dict_utils.adviser_dict_with_team, 'country_lost_to': dict_utils.id_name_dict, 'country_investment_originates_from': dict_utils.id_name_dict, 'created_by': dict_utils.adviser_dict_with_team, 'delivery_partners': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'fdi_type': dict_utils.id_name_dict, 'fdi_value': dict_utils.id_name_dict, 'intermediate_company': dict_utils.id_name_dict, 'investment_type': dict_utils.id_name_dict, 'investor_company': dict_utils.id_name_dict, 'investor_company_country': dict_utils.id_name_dict, 'investor_type': dict_utils.id_name_dict, 'level_of_involvement': dict_utils.id_name_dict, 'likelihood_to_land': dict_utils.id_name_dict, 'project_assurance_adviser': dict_utils.adviser_dict_with_team, 'project_code': str, 'project_manager': dict_utils.adviser_dict_with_team, 'referral_source_activity': dict_utils.id_name_dict, 'referral_source_activity_marketing': dict_utils.id_name_dict, 'referral_source_activity_website': dict_utils.id_name_dict, 'referral_source_adviser': dict_utils.contact_or_adviser_dict, 'sector': dict_utils.sector_dict, 'specific_programme': dict_utils.id_name_dict, 'stage': dict_utils.id_name_dict, 'team_members': lambda col: [ dict_utils.contact_or_adviser_dict(c.adviser, include_dit_team=True) for c in col.all() ], 'uk_company': dict_utils.id_name_dict, 'uk_region_locations': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], } SEARCH_FIELDS = ( 'id', 'name', 'name.trigram', 'uk_company.name', 'uk_company.name.trigram', 'investor_company.name', 'investor_company.name.trigram', 'project_code.trigram', ) class Meta: """Default document meta data.""" doc_type = DOC_TYPE class Index: doc_type = DOC_TYPE
class Order(BaseESModel): """Elasticsearch representation of Order model.""" id = Keyword() reference = fields.SortableCaseInsensitiveKeywordText( copy_to=['reference_trigram']) reference_trigram = fields.TrigramText() status = fields.SortableCaseInsensitiveKeywordText() company = fields.nested_company_field('company') contact = fields.nested_contact_or_adviser_field('contact') created_by = fields.nested_contact_or_adviser_field('created_by', include_dit_team=True) created_on = Date() modified_on = Date() primary_market = fields.nested_id_name_field() sector = fields.nested_sector_field() uk_region = fields.nested_id_name_field() description = fields.EnglishText() contacts_not_to_approach = Text() further_info = Text() existing_agents = Text(index=False) delivery_date = Date() service_types = fields.nested_id_name_field() contact_email = fields.SortableCaseInsensitiveKeywordText() contact_phone = Keyword() subscribers = fields.nested_contact_or_adviser_field('subscribers', include_dit_team=True) assignees = fields.nested_contact_or_adviser_field('assignees', include_dit_team=True) po_number = Keyword(index=False) discount_value = Integer(index=False) vat_status = Keyword(index=False) vat_number = Keyword(index=False) vat_verified = Boolean(index=False) net_cost = Integer(index=False) subtotal_cost_string = Keyword() subtotal_cost = Integer(copy_to=['subtotal_cost_string']) vat_cost = Integer(index=False) total_cost_string = Keyword() total_cost = Integer(copy_to=['total_cost_string']) payment_due_date = Date() paid_on = Date() completed_by = fields.nested_contact_or_adviser_field('completed_by') completed_on = Date() cancelled_by = fields.nested_contact_or_adviser_field('cancelled_by') cancelled_on = Date() cancellation_reason = fields.nested_id_name_field() billing_company_name = Text() billing_contact_name = Text() billing_email = fields.SortableCaseInsensitiveKeywordText() billing_phone = fields.SortableCaseInsensitiveKeywordText() billing_address_1 = Text() billing_address_2 = Text() billing_address_town = fields.SortableCaseInsensitiveKeywordText() billing_address_county = fields.SortableCaseInsensitiveKeywordText() billing_address_postcode = Text() billing_address_country = fields.nested_id_name_field() MAPPINGS = { 'id': str, 'company': dict_utils.company_dict, 'contact': dict_utils.contact_or_adviser_dict, 'created_by': dict_utils.adviser_dict_with_team, 'primary_market': dict_utils.id_name_dict, 'sector': dict_utils.sector_dict, 'uk_region': dict_utils.id_name_dict, 'service_types': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'subscribers': lambda col: [ dict_utils.contact_or_adviser_dict(c.adviser, include_dit_team=True) for c in col.all() ], 'assignees': lambda col: [ dict_utils.contact_or_adviser_dict(c.adviser, include_dit_team=True) for c in col.all() ], 'billing_address_country': dict_utils.id_name_dict, 'completed_by': dict_utils.contact_or_adviser_dict, 'cancelled_by': dict_utils.contact_or_adviser_dict, 'cancellation_reason': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'payment_due_date': lambda x: x.invoice.payment_due_date if x.invoice else None, } SEARCH_FIELDS = ( 'reference_trigram', 'company.name', 'company.name_trigram', 'contact.name', 'contact.name_trigram', 'total_cost_string', 'subtotal_cost_string', ) class Meta: """Default document meta data.""" doc_type = 'order'
class Order(BaseSearchModel): """OpenSearch representation of Order model.""" id = Keyword() reference = fields.NormalizedKeyword( fields={ 'trigram': fields.TrigramText(), }, ) status = fields.NormalizedKeyword() company = fields.company_field() contact = fields.contact_or_adviser_field() created_by = fields.contact_or_adviser_field(include_dit_team=True) created_on = Date() modified_on = Date() primary_market = fields.id_name_field() sector = fields.sector_field() uk_region = fields.id_name_field() description = fields.EnglishText() contacts_not_to_approach = Text() further_info = Text() existing_agents = Text(index=False) delivery_date = Date() service_types = fields.id_name_field() contact_email = fields.NormalizedKeyword() contact_phone = Keyword() subscribers = fields.contact_or_adviser_field(include_dit_team=True) assignees = fields.contact_or_adviser_field(include_dit_team=True) po_number = Keyword(index=False) discount_value = Integer(index=False) vat_status = Keyword(index=False) vat_number = Keyword(index=False) vat_verified = Boolean(index=False) net_cost = Integer(index=False) subtotal_cost = Integer( fields={ 'keyword': Keyword(), }, ) vat_cost = Integer(index=False) total_cost = Integer( fields={ 'keyword': Keyword(), }, ) payment_due_date = Date() paid_on = Date() completed_by = fields.contact_or_adviser_field() completed_on = Date() cancelled_by = fields.contact_or_adviser_field() cancelled_on = Date() cancellation_reason = fields.id_name_field() billing_company_name = Text() billing_contact_name = Text() billing_email = fields.NormalizedKeyword() billing_phone = fields.NormalizedKeyword() billing_address_1 = Text() billing_address_2 = Text() billing_address_town = fields.NormalizedKeyword() billing_address_county = fields.NormalizedKeyword() billing_address_postcode = Text() billing_address_country = fields.id_name_field() MAPPINGS = { 'company': dict_utils.company_dict, 'contact': dict_utils.contact_or_adviser_dict, 'created_by': dict_utils.adviser_dict_with_team, 'primary_market': dict_utils.id_name_dict, 'sector': dict_utils.sector_dict, 'uk_region': dict_utils.id_name_dict, 'service_types': lambda col: [dict_utils.id_name_dict(c) for c in col.all()], 'subscribers': lambda col: [ dict_utils.contact_or_adviser_dict(c.adviser, include_dit_team=True) for c in col.all() ], 'assignees': lambda col: [ dict_utils.contact_or_adviser_dict(c.adviser, include_dit_team=True) for c in col.all() ], 'billing_address_country': dict_utils.id_name_dict, 'completed_by': dict_utils.contact_or_adviser_dict, 'cancelled_by': dict_utils.contact_or_adviser_dict, 'cancellation_reason': dict_utils.id_name_dict, } COMPUTED_MAPPINGS = { 'payment_due_date': lambda x: x.invoice.payment_due_date if x.invoice else None, } SEARCH_FIELDS = ( 'id', 'reference.trigram', 'company.name', 'company.name.trigram', 'contact.name', 'contact.name.trigram', 'total_cost.keyword', 'subtotal_cost.keyword', 'sector.name', 'uk_region.name', )