예제 #1
0
class Interaction(BaseESModel):
    """Elasticsearch representation of Interaction model."""

    id = Keyword()
    company = fields.company_field()
    company_sector = fields.sector_field()
    company_one_list_group_tier = fields.id_unindexed_name_field()
    communication_channel = fields.id_unindexed_name_field()
    contacts = _contact_field()
    created_on = Date()
    date = Date()
    dit_participants = Object(_DITParticipant)
    event = fields.id_name_partial_field()
    investment_project = fields.id_unindexed_name_field()
    investment_project_sector = fields.sector_field()
    is_event = Boolean(index=False)
    grant_amount_offered = Double(index=False)
    kind = Keyword()
    modified_on = Date()
    net_company_receipt = Double(index=False)
    notes = fields.Text(index=False)
    policy_areas = fields.id_unindexed_name_field()
    policy_issue_types = fields.id_unindexed_name_field()
    service = fields.id_unindexed_name_field()
    service_delivery_status = fields.id_unindexed_name_field()
    subject = fields.NormalizedKeyword(
        fields={
            'english': fields.EnglishText(),
        },
    )
    was_policy_feedback_provided = Boolean()
    were_countries_discussed = Boolean()
    export_countries = _export_country_field()

    MAPPINGS = {
        'company': dict_utils.company_dict,
        'communication_channel': dict_utils.id_name_dict,
        'contacts': dict_utils.contact_or_adviser_list_of_dicts,
        'dit_participants': _dit_participant_list,
        'export_countries': _export_countries_list,
        'event': dict_utils.id_name_dict,
        'investment_project': dict_utils.id_name_dict,
        'policy_areas': dict_utils.id_name_list_of_dicts,
        'policy_issue_types': dict_utils.id_name_list_of_dicts,
        'service': dict_utils.id_name_dict,
        'service_delivery_status': dict_utils.id_name_dict,
    }

    COMPUTED_MAPPINGS = {
        'company_sector': dict_utils.computed_nested_sector_dict('company.sector'),
        'company_one_list_group_tier': lambda obj: dict_utils.id_name_dict(
            obj.company.get_one_list_group_tier() if obj.company else None,
        ),
        'investment_project_sector': dict_utils.computed_nested_sector_dict(
            'investment_project.sector',
        ),
        'is_event': attrgetter('is_event'),
    }

    SEARCH_FIELDS = (
        'id',
        'company.name',
        'company.name.trigram',
        'contacts.name',  # to find 2-letter words
        'contacts.name.trigram',
        'event.name',
        'event.name.trigram',
        'subject.english',
        'dit_participants.adviser.name',
        'dit_participants.adviser.name.trigram',
        'dit_participants.team.name',
        'dit_participants.team.name.trigram',
    )

    class Meta:
        """Default document meta data."""

        doc_type = DOC_TYPE

    class Index:
        doc_type = DOC_TYPE
예제 #2
0
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,
    }
예제 #3
0
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',
    )
예제 #4
0
class Order(BaseESModel):
    """Elasticsearch representation of Order model."""

    id = Keyword()
    reference = fields.NormalizedKeyword(copy_to=['reference_trigram'])
    reference_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_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.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_string',
        'subtotal_cost_string',
    )

    class Meta:
        """Default document meta data."""

        doc_type = DOC_TYPE

    class Index:
        doc_type = DOC_TYPE
예제 #5
0
class LargeInvestorProfile(BaseSearchModel):
    """OpenSearch representation of LargeInvestorProfile."""

    id = Keyword()

    investor_company = fields.company_field()
    country_of_origin = fields.country_field()
    asset_classes_of_interest = fields.id_unindexed_name_field()
    created_by = fields.contact_or_adviser_field(include_dit_team=True)

    investor_type = fields.id_unindexed_name_field()
    global_assets_under_management = Long()
    investable_capital = Long()
    required_checks_conducted = fields.id_unindexed_name_field()

    deal_ticket_sizes = fields.id_unindexed_name_field()
    investment_types = fields.id_unindexed_name_field()
    minimum_return_rate = fields.id_unindexed_name_field()
    time_horizons = fields.id_unindexed_name_field()
    restrictions = fields.id_unindexed_name_field()
    construction_risks = fields.id_unindexed_name_field()
    minimum_equity_percentage = fields.id_unindexed_name_field()
    desired_deal_roles = fields.id_unindexed_name_field()

    uk_region_locations = fields.id_unindexed_name_field()
    other_countries_being_considered = fields.country_field()

    investor_description = fields.EnglishText()
    notes_on_locations = fields.EnglishText()

    created_on = Date()
    modified_on = Date()

    _MAIN_FIELD_MAPPINGS = {
        'asset_classes_of_interest': _get_many_to_many_list,
        'country_of_origin': dict_utils.id_name_dict,
        'investor_company': dict_utils.company_dict,
        'created_by': dict_utils.adviser_dict_with_team,
    }

    _DETAIL_FIELD_MAPPINGS = {
        'investor_type': dict_utils.id_name_dict,
        'required_checks_conducted': dict_utils.id_name_dict,
    }

    _REQUIREMENT_FIELD_MAPPINGS = {
        'deal_ticket_sizes': _get_many_to_many_list,
        'investment_types': _get_many_to_many_list,
        'minimum_return_rate': dict_utils.id_name_dict,
        'time_horizons': _get_many_to_many_list,
        'restrictions': _get_many_to_many_list,
        'construction_risks': _get_many_to_many_list,
        'minimum_equity_percentage': dict_utils.id_name_dict,
        'desired_deal_roles': _get_many_to_many_list,
    }

    _LOCATION_FIELD_MAPPINGS = {
        'uk_region_locations': _get_many_to_many_list,
        'other_countries_being_considered': _get_many_to_many_list,
    }

    MAPPINGS = {
        **_MAIN_FIELD_MAPPINGS,
        **_DETAIL_FIELD_MAPPINGS,
        **_REQUIREMENT_FIELD_MAPPINGS,
        **_LOCATION_FIELD_MAPPINGS,
    }
예제 #6
0
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