Exemplo n.º 1
0
    def construct_task_list(business):
        """Return a task list object."""
        tasks = []
        order = 1
        todo_start_year = 2019  # If no filings exist in legal API db this year will be used as the start year.

        pending_filings = Filing.get_filings_by_status(business.id, [Filing.Status.DRAFT.value,
                                                                     Filing.Status.PENDING.value,
                                                                     Filing.Status.ERROR.value])
        for filing in pending_filings:
            task = {'task': filing.json, 'order': order, 'enabled': True}
            tasks.append(task)
            order += 1

        annual_report_filings = Filing.get_filings_by_type(business.id, 'annualReport')
        if annual_report_filings:
            last_filing = annual_report_filings[0].filing_json
            todo_start_year = datetime.strptime(last_filing['filing']['annualReport']['annualGeneralMeetingDate'],
                                                '%Y-%m-%d').year + 1

        if todo_start_year <= datetime.now().year:
            for todo_year in range(todo_start_year, datetime.now().year+1):
                enabled = not pending_filings and todo_year == todo_start_year
                tasks.append(TaskListResource.create_todo(business, todo_year, order, enabled))
                order += 1

        return tasks
Exemplo n.º 2
0
    def construct_task_list(business):
        """
        Return all current pending tasks to do.

        First retrieves filings that are either drafts, or incomplete,
        then populate AR filings that have not been started for
        years that are due.

        Rules for AR filings:
            - Co-ops must file one AR per year. The next AR date must be AFTER the most recent
              AGM date. The calendar year of the filing is the first contiguous year following
              the last AGM date

            - Corporations must file one AR per year, on or after the anniversary of the founding date
        """
        tasks = []
        order = 1
        check_agm = validations.annual_report.requires_agm(business)
        # If no filings exist in legal API db this year will be used as the start year.
        todo_start_date = (datetime(
            2019, 1,
            1)).date() if check_agm else business.next_anniversary.date()

        # Retrieve filings that are either incomplete, or drafts
        pending_filings = Filing.get_filings_by_status(business.id, [
            Filing.Status.DRAFT.value, Filing.Status.PENDING.value,
            Filing.Status.ERROR.value
        ])
        # Create a todo item for each pending filing
        for filing in pending_filings:
            task = {'task': filing.json, 'order': order, 'enabled': True}
            tasks.append(task)
            order += 1

        # Retrieve all previous annual report filings. If there are existing AR filings, determine
        # the latest date of filing
        annual_report_filings = Filing.get_filings_by_type(
            business.id, 'annualReport')
        if annual_report_filings:

            if check_agm:
                last_ar_date = business.last_ar_date
                todo_start_date = (datetime(last_ar_date.year + 1, 1,
                                            1)).date()
            else:
                todo_start_date = business.next_anniversary.date()

        start_year = todo_start_date.year

        while todo_start_date <= datetime.now().date():
            enabled = not pending_filings and todo_start_date.year == start_year
            tasks.append(
                TaskListResource.create_todo(business, todo_start_date.year,
                                             order, enabled))
            todo_start_date += datedelta.YEAR
            order += 1
        return tasks
Exemplo n.º 3
0
    def _save_incorporation_filing(incorporation_body,
                                   client_request,
                                   business_id=None):
        """Create or update an incorporation filing."""
        # Check that there is a JSON filing
        if not incorporation_body:
            return None, {'message': f'No filing json data in body of post for incorporation'}, \
                HTTPStatus.BAD_REQUEST

        temp_corp_num = incorporation_body['filing'][
            'incorporationApplication']['nameRequest']['nrNumber']
        # temp_corp_num = business_id
        # If this is an update to an incorporation filing, a temporary business identifier is passed in
        if business_id:
            business = Business.find_by_identifier(business_id)
            if not business:
                return None, {'message': f'No incorporation filing exists for id {business_id}'}, \
                    HTTPStatus.BAD_REQUEST
        else:
            # Ensure there are no current businesses with the NR/random identifier
            business = Business.find_by_identifier(temp_corp_num)

            if business:
                return None, {'message': f'Incorporation filing for {temp_corp_num} already exists'}, \
                    HTTPStatus.BAD_REQUEST
            # Create an empty business record, to be updated by the filer
            business = Business()
            business.identifier = temp_corp_num
            business.save()

        # Ensure the business identifier matches the NR in the filing
        err = validate(business, incorporation_body)
        if err:
            return None, err.msg, err.code

        filing = Filing.get_filings_by_type(business.id,
                                            'incorporationApplication')

        # There can only be zero or one incorporation filings, if there are none, this is an
        # initial request for incorporation. Create and insert a filing.
        if not filing:
            filing = Filing()
            filing.business_id = business.id
        elif len(filing) > 1:
            return None, {
                'message': 'more than one incorporation filing found for corp'
            }, HTTPStatus.BAD_REQUEST
        else:
            filing = filing[0]
        filing.filing_json = incorporation_body
        filing.save()
        return filing, None, (HTTPStatus.CREATED if
                              (client_request.method
                               == 'POST') else HTTPStatus.ACCEPTED)
Exemplo n.º 4
0
    def construct_task_list(business):  # pylint: disable=too-many-locals; only 2 extra
        """
        Return all current pending tasks to do.

        First retrieves filings that are either drafts, or incomplete,
        then populate AR filings that have not been started for
        years that are due.

        Rules for AR filings:
            - Co-ops must file one AR per year. The next AR date must be AFTER the most recent
              AGM date. The calendar year of the filing is the first contiguous year following
              the last AGM date

            - Corporations must file one AR per year, on or after the anniversary of the founding date
        """
        tasks = []
        order = 1

        # Retrieve filings that are either incomplete, or drafts
        pending_filings = Filing.get_filings_by_status(business.id, [
            Filing.Status.DRAFT.value, Filing.Status.PENDING.value,
            Filing.Status.PENDING_CORRECTION.value, Filing.Status.ERROR.value
        ])
        # Create a todo item for each pending filing
        for filing in pending_filings:
            filing_json = filing.json
            if filing.payment_status_code == 'CREATED' and filing.payment_token:
                # get current pay details from pay-api
                try:
                    headers = {
                        'Authorization':
                        f'Bearer {jwt.get_token_auth_header()}',
                        'Content-Type': 'application/json'
                    }
                    pay_response = requests.get(
                        url=
                        f'{current_app.config.get("PAYMENT_SVC_URL")}/{filing.payment_token}',
                        headers=headers)
                    pay_details = {
                        'isPaymentActionRequired':
                        pay_response.json().get('isPaymentActionRequired',
                                                False),
                        'paymentMethod':
                        pay_response.json().get('paymentMethod', '')
                    }
                    filing_json['filing']['header'].update(pay_details)

                except (exceptions.ConnectionError, exceptions.Timeout) as err:
                    current_app.logger.error(
                        f'Payment connection failure for {business.identifier} task list. ',
                        err)
                    return 'pay_connection_error'

            task = {'task': filing_json, 'order': order, 'enabled': True}
            tasks.append(task)
            order += 1

        # If this is the first calendar year since incorporation, there is no previous ar year.
        next_ar_year = (business.last_ar_year if business.last_ar_year else
                        business.founding_date.year) + 1
        start_date = (business.last_ar_date if business.last_ar_date else
                      business.founding_date).date()

        # Checking for pending ar
        annual_report_filings = Filing.get_filings_by_type(
            business.id, 'annualReport')
        if annual_report_filings:
            # Consider each filing as each year and add to find next ar year
            next_ar_year += len(annual_report_filings)
            start_date = datetime(next_ar_year, 1, 1).date()

        ar_min_date, ar_max_date = validations.annual_report.get_ar_dates(
            business, start_date, next_ar_year)

        start_year = next_ar_year
        while ar_min_date <= datetime.utcnow().date():
            # while next_ar_year <= datetime.utcnow().date():
            enabled = not pending_filings and ar_min_date.year == start_year
            tasks.append(
                TaskListResource.create_todo(business, next_ar_year,
                                             ar_min_date, ar_max_date, order,
                                             enabled))

            # Include all ar's to todo from last ar filing
            next_ar_year += 1
            start_date = datetime(next_ar_year, 1, 1).date()
            ar_min_date, ar_max_date = validations.annual_report.get_ar_dates(
                business, start_date, next_ar_year)
            order += 1
        return tasks
Exemplo n.º 5
0
    def construct_task_list(business):
        """
        Return all current pending tasks to do.

        First retrieves filings that are either drafts, or incomplete,
        then populate AR filings that have not been started for
        years that are due.

        Rules for AR filings:
            - Co-ops must file one AR per year. The next AR date must be AFTER the most recent
              AGM date. The calendar year of the filing is the first contiguous year following
              the last AGM date

            - Corporations must file one AR per year, on or after the anniversary of the founding date
        """
        tasks = []
        order = 1
        check_agm = validations.annual_report.requires_agm(business)

        # If no filings exist in legal API db (set after this line), use the business' next anniversary date
        todo_start_date = business.next_anniversary.date()

        # Retrieve filings that are either incomplete, or drafts
        pending_filings = Filing.get_filings_by_status(business.id, [
            Filing.Status.DRAFT.value, Filing.Status.PENDING.value,
            Filing.Status.PENDING_CORRECTION.value, Filing.Status.ERROR.value
        ])
        # Create a todo item for each pending filing
        for filing in pending_filings:
            task = {'task': filing.json, 'order': order, 'enabled': True}
            tasks.append(task)
            order += 1

        last_ar_date = business.last_ar_date
        if check_agm:
            # If this is a CO-OP, set the start date to the first day of the year, since an AR filing
            # is available as of Jan/01
            if last_ar_date:
                todo_start_date = (datetime(last_ar_date.year + 1, 1,
                                            1)).date()
            else:
                # If this is the first calendar year since incorporation, there is no
                # previous ar date. Use the next anniversary year.
                todo_start_date = (datetime(todo_start_date.year, 1, 1)).date()

        # Retrieve all previous annual report filings. If there are existing AR filings, determine
        # the latest date of filing
        annual_report_filings = Filing.get_filings_by_type(
            business.id, 'annualReport')
        if annual_report_filings:
            # get last AR date from annualReportDate; if not present in json, try annualGeneralMeetingDate and
            # finally filing date
            last_ar_date = \
                annual_report_filings[0].filing_json['filing']['annualReport'].get('annualReportDate', None)
            if not last_ar_date:
                last_ar_date = annual_report_filings[0].filing_json['filing']['annualReport']\
                    .get('annualGeneralMeetingDate', None)
            if not last_ar_date:
                last_ar_date = annual_report_filings[0].filing_date
            last_ar_date = datetime.fromisoformat(last_ar_date)
            if check_agm:
                todo_start_date = (datetime(last_ar_date.year + 1, 1,
                                            1)).date()
            else:
                todo_start_date = (last_ar_date + datedelta.YEAR).date()

        start_year = todo_start_date.year

        while todo_start_date <= datetime.now().date():
            enabled = not pending_filings and todo_start_date.year == start_year
            tasks.append(
                TaskListResource.create_todo(business, todo_start_date.year,
                                             order, enabled))
            todo_start_date += datedelta.YEAR
            order += 1
        return tasks