Ejemplo n.º 1
0
 def find_affiliations_by_org_id(org_id):
     """Return business affiliations for the org."""
     data = []
     affiliation_models = AffiliationModel.find_affiliations_by_org_id(
         org_id)
     for affiliation_model in affiliation_models:
         affiliation = EntityService(affiliation_model.entity).as_dict()
         data.append(affiliation)
     return data
Ejemplo n.º 2
0
    def find_affiliated_entities_by_org_id(org_id, token_info: Dict = None):
        """Given an org_id, this will return the entities affiliated with it."""
        current_app.logger.debug('<find_affiliations_by_org_id for org_id {}'.format(org_id))
        if not org_id:
            raise BusinessException(Error.DATA_NOT_FOUND, None)

        org = OrgService.find_by_org_id(org_id, token_info=token_info, allowed_roles=ALL_ALLOWED_ROLES)
        if org is None:
            raise BusinessException(Error.DATA_NOT_FOUND, None)

        data = []
        affiliation_models = AffiliationModel.find_affiliations_by_org_id(org_id)
        if affiliation_models is None:
            raise BusinessException(Error.DATA_NOT_FOUND, None)

        for affiliation_model in affiliation_models:
            affiliation = EntityService(affiliation_model.entity).as_dict()
            data.append(affiliation)

        # 3806 : Filter out the NR affiliation if there is IA affiliation for the same NR.
        # Dict with key as NR number and value as name
        nr_number_name_dict = {d['business_identifier']: d['name']
                               for d in data if d['corp_type']['code'] == CorpType.NR.value}
        # Create a list of all temporary business names
        tmp_business_list = [d['name'] for d in data if d['corp_type']['code'] == CorpType.TMP.value]

        # NR Numbers
        nr_numbers = nr_number_name_dict.keys()

        filtered_affiliations: list = []
        for entity in data:
            if entity['corp_type']['code'] == CorpType.NR.value:
                # If there is a TMP affiliation present for the NR, do not show NR
                if not entity['business_identifier'] in tmp_business_list:
                    filtered_affiliations.append(entity)

            elif entity['corp_type']['code'] == CorpType.TMP.value:

                # If affiliation is not for a named company IA, and not a Numbered company
                # (name and businessIdentifier same)
                # --> Its a Temp affiliation with incorporation complete.
                # In this case, a TMP affiliation will be there but the name will be BC...
                if entity['name'] in nr_numbers or entity['name'] == entity['business_identifier']:
                    # If temp affiliation is for an NR, change the name to NR's name
                    if entity['name'] in nr_numbers:
                        entity['name'] = nr_number_name_dict[entity['name']]

                    filtered_affiliations.append(entity)
            else:
                filtered_affiliations.append(entity)

        current_app.logger.debug('>find_affiliations_by_org_id')
        return filtered_affiliations
Ejemplo n.º 3
0
    def find_affiliated_entities_by_org_id(org_id):
        """Given an org_id, this will return the entities affiliated with it."""
        current_app.logger.debug(
            '<find_affiliations_by_org_id for org_id {}'.format(org_id))
        if not org_id:
            raise BusinessException(Error.DATA_NOT_FOUND, None)

        org = OrgService.find_by_org_id(org_id)
        if org is None:
            raise BusinessException(Error.DATA_NOT_FOUND, None)

        data = []
        affiliation_models = AffiliationModel.find_affiliations_by_org_id(
            org_id)
        if affiliation_models is None:
            raise BusinessException(Error.DATA_NOT_FOUND, None)

        for affiliation_model in affiliation_models:
            if affiliation_model:
                data.append(EntityService(affiliation_model.entity).as_dict())
        current_app.logger.debug('>find_affiliations_by_org_id')

        return data