Example #1
0
def process(business: Business, filing: Filing):
    """Render the change_of_directors onto the business model objects."""
    new_directors = filing['changeOfDirectors'].get('directors')

    for new_director in new_directors:
        if 'appointed' in new_director['actions']:
            # create address
            address = create_address(new_director['deliveryAddress'],
                                     Address.DELIVERY)

            # add new director to the list
            business.directors.append(
                Director(first_name=new_director['officer'].get(
                    'firstName', '').upper(),
                         middle_initial=new_director['officer'].get(
                             'middleInitial', '').upper(),
                         last_name=new_director['officer'].get('lastName',
                                                               '').upper(),
                         title=new_director.get('title', '').upper(),
                         appointment_date=new_director.get('appointmentDate'),
                         cessation_date=new_director.get('cessationDate'),
                         delivery_address=address))

        if any([action != 'appointed' for action in new_director['actions']]):
            # get name of director in json for comparison *
            new_director_name = \
                new_director['officer'].get('firstName') + new_director['officer'].get('middleInitial') + \
                new_director['officer'].get('lastName') \
                if 'nameChanged' not in new_director['actions'] \
                else new_director['officer'].get('prevFirstName') + \
                new_director['officer'].get('prevMiddleInitial') + new_director['officer'].get('prevLastName')
            if not new_director_name:
                logger.error('Could not resolve director name from json %s.',
                             new_director)
                raise QueueException

            for director in business.directors:
                # get name of director in database for comparison *
                director_name = director.first_name + director.middle_initial + director.last_name
                if director_name.upper() == new_director_name.upper():
                    update_director(director, new_director)
                    break
Example #2
0
def process(business: Business, filing: Dict):  # pylint: disable=too-many-branches;
    """Render the change_of_directors onto the business model objects."""
    new_directors = filing['changeOfDirectors'].get('directors')
    new_director_names = []

    for new_director in new_directors:  # pylint: disable=too-many-nested-blocks;
        # Applies only for filings coming from colin.
        if filing.get('colinId'):
            director_found = False
            current_new_director_name = \
                new_director['officer'].get('firstName') + new_director['officer'].get('middleInitial', '') + \
                new_director['officer'].get('lastName')
            new_director_names.append(current_new_director_name.upper())

            for director in business.directors:
                existing_director_name = director.first_name + director.middle_initial + director.last_name
                if existing_director_name.upper() == current_new_director_name.upper():
                    # Creates a new director record in Lear if a matching ceased director exists in Lear
                    # and the colin json contains the same director record with cessation date null.
                    if director.cessation_date is not None and new_director.get('cessationDate') is None:
                        director_found = False
                    else:
                        director_found = True
                        if new_director.get('cessationDate'):
                            new_director['actions'] = ['ceased']
                        else:
                            # For force updating address always as of now.
                            new_director['actions'] = ['modified']
                    break
            if not director_found:
                new_director['actions'] = ['appointed']

        if 'appointed' in new_director['actions']:
            # create address
            address = create_address(new_director['deliveryAddress'], Address.DELIVERY)

            director_to_add = Director(first_name=new_director['officer'].get('firstName', '').upper(),
                                       middle_initial=new_director['officer'].get('middleInitial', '').upper(),
                                       last_name=new_director['officer'].get('lastName', '').upper(),
                                       title=new_director.get('title', '').upper(),
                                       appointment_date=new_director.get('appointmentDate'),
                                       cessation_date=new_director.get('cessationDate'),
                                       delivery_address=address)

            # if 'mailingAddress' in new_director and len(new_director['mailingAddress']): <- fails lint
            # if new_director.get('mailingAddress', None): <- slightly more pythonic
            with suppress(KeyError):  # <- since we're only going to do this if the key exists, it's easier to read
                mailing_address = create_address(new_director['mailingAddress'], Address.MAILING)
                director_to_add.mailing_address = mailing_address

            # add new director to the list
            business.directors.append(director_to_add)

        if any([action != 'appointed' for action in new_director['actions']]):
            # get name of director in json for comparison *
            new_director_name = \
                new_director['officer'].get('firstName') + new_director['officer'].get('middleInitial', '') + \
                new_director['officer'].get('lastName') \
                if 'nameChanged' not in new_director['actions'] \
                else new_director['officer'].get('prevFirstName') + \
                new_director['officer'].get('prevMiddleInitial') + new_director['officer'].get('prevLastName')
            if not new_director_name:
                logger.error('Could not resolve director name from json %s.', new_director)
                raise QueueException

            for director in business.directors:
                # get name of director in database for comparison *
                director_name = director.first_name + director.middle_initial + director.last_name
                # Update only an active director
                if director_name.upper() == new_director_name.upper() and director.cessation_date is None:
                    update_director(director, new_director)
                    break

    if filing.get('colinId'):
        for director in business.directors:
            # get name of director in database for comparison *
            director_name = director.first_name + director.middle_initial + director.last_name
            if director_name.upper() not in new_director_names:
                director.cessation_date = datetime.utcnow()
Example #3
0
def process(business: Business, filing: Dict):  # pylint: disable=too-many-branches;
    """Render the change_of_directors onto the business model objects."""
    new_directors = filing['changeOfDirectors'].get('directors')
    new_director_names = []

    for new_director in new_directors:  # pylint: disable=too-many-nested-blocks;
        # Applies only for filings coming from colin.
        if filing.get('colinIds'):
            director_found = False
            current_new_director_name = \
                new_director['officer'].get('firstName') + new_director['officer'].get('middleInitial', '') + \
                new_director['officer'].get('lastName')
            new_director_names.append(current_new_director_name.upper())

            for director in PartyRole.get_parties_by_role(
                    business.id, PartyRole.RoleTypes.DIRECTOR.value):
                existing_director_name = \
                    director.party.first_name + director.party.middle_initial + director.party.last_name
                if existing_director_name.upper(
                ) == current_new_director_name.upper():
                    # Creates a new director record in Lear if a matching ceased director exists in Lear
                    # and the colin json contains the same director record with cessation date null.
                    if director.cessation_date is not None and new_director.get(
                            'cessationDate') is None:
                        director_found = False
                    else:
                        director_found = True
                        if new_director.get('cessationDate'):
                            new_director['actions'] = ['ceased']
                        else:
                            # For force updating address always as of now.
                            new_director['actions'] = ['modified']
                    break
            if not director_found:
                new_director['actions'] = ['appointed']

        if 'appointed' in new_director['actions']:

            # add new diretor party role to the business
            party = create_party(party_info=new_director)
            role = {
                'roleType': 'Director',
                'appointmentDate': new_director.get('appointmentDate'),
                'cessationDate': new_director.get('cessationDate')
            }
            new_director_role = create_role(party=party, role_info=role)
            business.party_roles.append(new_director_role)

        if any([action != 'appointed' for action in new_director['actions']]):
            # get name of director in json for comparison *
            new_director_name = \
                new_director['officer'].get('firstName') + new_director['officer'].get('middleInitial', '') + \
                new_director['officer'].get('lastName') \
                if 'nameChanged' not in new_director['actions'] \
                else new_director['officer'].get('prevFirstName') + \
                new_director['officer'].get('prevMiddleInitial') + new_director['officer'].get('prevLastName')
            if not new_director_name:
                logger.error('Could not resolve director name from json %s.',
                             new_director)
                raise QueueException

            for director in PartyRole.get_parties_by_role(
                    business.id, PartyRole.RoleTypes.DIRECTOR.value):
                # get name of director in database for comparison *
                director_name = director.party.first_name + director.party.middle_initial + director.party.last_name
                # Update only an active director
                if director_name.upper() == new_director_name.upper(
                ) and director.cessation_date is None:
                    update_director(director=director, new_info=new_director)
                    break

    if filing.get('colinIds'):
        for director in PartyRole.get_parties_by_role(
                business.id, PartyRole.RoleTypes.DIRECTOR.value):
            # get name of director in database for comparison *
            director_name = director.first_name + director.middle_initial + director.last_name
            if director_name.upper(
            ) not in new_director_names and director.cessation_date is None:
                director.cessation_date = datetime.utcnow()