예제 #1
0
def update_parties(business: Business,
                   parties_structure: Dict) -> Optional[List]:
    """Manage the party and party roles for a business.

    Assumption: The structure has already been validated, upon submission.

    Other errors are recorded and will be managed out of band.
    """
    if not business:
        # if nothing is passed in, we don't care and it's not an error
        return None

    err = []

    if parties_structure:
        try:
            delete_parties(business)
        except:  # noqa:E722 pylint: disable=bare-except; catch all exceptions
            err.append({
                'error_code':
                'FILER_UNABLE_TO_DELETE_PARTY_ROLES',
                'error_message':
                f"Filer: unable to delete party roles for :'{business.identifier}'"
            })
            return err

        try:
            for party_info in parties_structure:
                party = create_party(business_id=business.id,
                                     party_info=party_info,
                                     create=False)
                for role_type in party_info.get('roles'):
                    role = {
                        'roleType': role_type.get('roleType'),
                        'appointmentDate':
                        role_type.get('appointmentDate', None),
                        'cessationDate': role_type.get('cessationDate', None)
                    }
                    party_role = create_role(party=party, role_info=role)
                    business.party_roles.append(party_role)
        except KeyError:
            err.append({
                'error_code':
                'FILER_UNABLE_TO_SAVE_PARTIES',
                'error_message':
                f"Filer: unable to save new parties for :'{business.identifier}'"
            })
    return err
예제 #2
0
async def test_process_combined_filing(app, session, mocker):
    """Assert that an AR filling can be applied to the model correctly."""
    # mock out the email sender and event publishing
    mocker.patch('entity_filer.worker.publish_email_message',
                 return_value=None)
    mocker.patch('entity_filer.worker.publish_event', return_value=None)

    # vars
    payment_id = str(random.SystemRandom().getrandbits(0x58))
    identifier = 'CP1234567'
    business = create_business(identifier, legal_type='CP')
    agm_date = datetime.date.fromisoformat(
        COMBINED_FILING['filing']['annualReport'].get(
            'annualGeneralMeetingDate'))
    ar_date = datetime.date.fromisoformat(
        COMBINED_FILING['filing']['annualReport'].get('annualReportDate'))
    new_delivery_address = COMBINED_FILING['filing']['changeOfAddress'][
        'offices']['registeredOffice'][
            'deliveryAddress']  # noqa: E501; line too long by 1 char
    new_mailing_address = COMBINED_FILING['filing']['changeOfAddress'][
        'offices']['registeredOffice']['mailingAddress']
    end_date = datetime.datetime.utcnow().date()
    # prep director for no change
    filing_data = copy.deepcopy(COMBINED_FILING)
    directors = filing_data['filing']['changeOfDirectors']['directors']
    director_party1 = create_party(business.id, directors[0])
    role1 = {
        'roleType': 'director',
        'appointmentDate': directors[0].get('appointmentDate'),
        'cessationDate': directors[0].get('cessationDate')
    }
    director1 = create_role(party=director_party1, role_info=role1)
    # prep director for name change
    director_party2_dict = directors[1]
    director_party2_dict['officer']['firstName'] = director_party2_dict[
        'officer']['prevFirstName']
    director_party2_dict['officer']['middleInitial'] = director_party2_dict[
        'officer']['prevMiddleInitial']
    director_party2_dict['officer']['lastName'] = director_party2_dict[
        'officer']['prevLastName']
    director_party2 = create_party(business.id, director_party2_dict)
    role2 = {
        'roleType': 'Director',
        'appointmentDate': director_party2_dict.get('appointmentDate'),
        'cessationDate': director_party2_dict.get('cessationDate')
    }
    director2 = create_role(party=director_party2, role_info=role2)
    # prep director for cease
    director_party3 = create_party(business.id, directors[2])
    role3 = {
        'roleType': 'director',
        'appointmentDate': directors[3].get('appointmentDate'),
        'cessationDate': directors[3].get('cessationDate')
    }
    director3 = create_role(party=director_party3, role_info=role3)
    # prep director for address change
    director_party4_dict = directors[3]
    director_party4_dict['deliveryAddress'][
        'streetAddress'] = 'should get changed'
    director_party4 = create_party(business.id, director_party4_dict)
    role4 = {
        'roleType': 'director',
        'appointmentDate': director_party4_dict.get('appointmentDate'),
        'cessationDate': director_party4_dict.get('cessationDate')
    }
    director4 = create_role(party=director_party4, role_info=role4)

    # list of active/ceased directors in test filing
    ceased_directors, active_directors = active_ceased_lists(COMBINED_FILING)

    # setup
    business.party_roles.append(director1)
    business.party_roles.append(director2)
    business.party_roles.append(director3)
    business.party_roles.append(director4)
    business.save()
    director_ceased_id = director3.id
    # check that adding the directors during setup was successful
    directors = PartyRole.get_parties_by_role(
        business.id, PartyRole.RoleTypes.DIRECTOR.value)
    assert len(directors) == 4
    business_id = business.id
    filing_id = (create_filing(payment_id, COMBINED_FILING, business.id)).id
    filing_msg = {'filing': {'id': filing_id}}

    # TEST
    await process_filing(filing_msg, app)

    # Get modified data
    filing = Filing.find_by_id(filing_id)
    business = Business.find_by_internal_id(business_id)

    # check it out
    assert filing.transaction_id
    assert filing.business_id == business_id
    assert filing.status == Filing.Status.COMPLETED.value
    assert datetime.datetime.date(business.last_agm_date) == agm_date
    assert datetime.datetime.date(business.last_ar_date) == ar_date

    # check address filing
    delivery_address = business.delivery_address.one_or_none().json
    compare_addresses(delivery_address, new_delivery_address)
    mailing_address = business.mailing_address.one_or_none().json
    compare_addresses(mailing_address, new_mailing_address)

    # check director filing
    directors = PartyRole.get_active_directors(business.id, end_date)
    check_directors(business, directors, director_ceased_id, ceased_directors,
                    active_directors)
예제 #3
0
async def test_process_cod_filing(app, session):
    """Assert that an AR filling can be applied to the model correctly."""
    # vars
    payment_id = str(random.SystemRandom().getrandbits(0x58))
    identifier = 'CP1234567'
    business = create_business(identifier)
    end_date = datetime.datetime.utcnow().date()
    # prep director for no change
    filing_data = copy.deepcopy(COD_FILING)
    directors = filing_data['filing']['changeOfDirectors']['directors']
    director_party1 = create_party(business.id, directors[0])
    role1 = {
        'roleType': 'director',
        'appointmentDate': directors[0].get('appointmentDate'),
        'cessationDate': directors[0].get('cessationDate')
    }
    director1 = create_role(party=director_party1, role_info=role1)
    # prep director for name change
    director_party2_dict = directors[1]
    director_party2_dict['officer']['firstName'] = director_party2_dict[
        'officer']['prevFirstName']
    director_party2_dict['officer']['middleInitial'] = director_party2_dict[
        'officer']['prevMiddleInitial']
    director_party2_dict['officer']['lastName'] = director_party2_dict[
        'officer']['prevLastName']
    director_party2 = create_party(business.id, director_party2_dict)
    role2 = {
        'roleType': 'director',
        'appointmentDate': director_party2_dict.get('appointmentDate'),
        'cessationDate': director_party2_dict.get('cessationDate')
    }
    director2 = create_role(party=director_party2, role_info=role2)
    # prep director for cease
    director_party3 = create_party(business.id, directors[2])
    role3 = {
        'roleType': 'director',
        'appointmentDate': directors[3].get('appointmentDate'),
        'cessationDate': directors[3].get('cessationDate')
    }
    director3 = create_role(party=director_party3, role_info=role3)
    # prep director for address change
    director_party4_dict = directors[3]
    director_party4_dict['deliveryAddress'][
        'streetAddress'] = 'should get changed'
    director_party4 = create_party(business.id, director_party4_dict)
    role4 = {
        'roleType': 'director',
        'appointmentDate': director_party4_dict.get('appointmentDate'),
        'cessationDate': director_party4_dict.get('cessationDate')
    }
    director4 = create_role(party=director_party4, role_info=role4)

    # list of active/ceased directors in test filing
    ceased_directors, active_directors = active_ceased_lists(COD_FILING)

    # setup
    business.party_roles.append(director1)
    business.party_roles.append(director2)
    business.party_roles.append(director3)
    business.party_roles.append(director4)
    business.save()
    director_ceased_id = director3.id
    # check that adding the director during setup was successful
    directors = PartyRole.get_parties_by_role(
        business.id, PartyRole.RoleTypes.DIRECTOR.value)
    assert len(directors) == 4
    # create filing
    business_id = business.id
    filing_id = (create_filing(payment_id, COD_FILING, business.id)).id
    filing_msg = {'filing': {'id': filing_id}}

    # TEST
    await process_filing(filing_msg, app)

    # Get modified data
    filing = Filing.find_by_id(filing_id)
    business = Business.find_by_internal_id(business_id)

    # check it out
    assert filing.transaction_id
    assert filing.business_id == business_id
    assert filing.status == Filing.Status.COMPLETED.value

    directors = PartyRole.get_active_directors(business.id, end_date)
    check_directors(business, directors, director_ceased_id, ceased_directors,
                    active_directors)
예제 #4
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(business_id=business.id,
                                 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.party.first_name + director.party.middle_initial + director.party.last_name
            if director_name.upper(
            ) not in new_director_names and director.cessation_date is None:
                director.cessation_date = datetime.utcnow()
예제 #5
0
                        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(business_id=business.id, 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']]):  # pylint: disable=use-a-generator
            # 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') + \