예제 #1
0
def test_statements_for_empty_results(session):
    """Test dailiy statement generation works.

    Steps:
    1) Create a payment for day before yesterday
    2) Mark the account settings as DAILY settlement starting yesterday
    3) Generate statement and assert that the statement does not contains payment records
    """
    day_before_yday = get_previous_day(datetime.now()) - timedelta(days=1)
    bcol_account = factory_premium_payment_account()
    invoice = factory_invoice(payment_account=bcol_account,
                              created_on=day_before_yday)
    inv_ref = factory_invoice_reference(invoice_id=invoice.id)
    factory_statement_settings(pay_account_id=bcol_account.id,
                               from_date=day_before_yday,
                               frequency='DAILY')
    factory_payment(completed_on=day_before_yday,
                    invoice_number=inv_ref.invoice_number)

    StatementTask.generate_statements()

    statements = Statement.find_all_statements_for_account(
        auth_account_id=bcol_account.auth_account_id, page=1, limit=100)
    assert statements is not None
    invoices = StatementInvoices.find_all_invoices_for_statement(
        statements[0][0].id)
    assert len(invoices) == 0
예제 #2
0
def test_statements(session):
    """Test dailiy statement generation works.

    Steps:
    1) Create a payment for yesterday
    2) Mark the account settings as DAILY settlement starting yesterday
    3) Generate statement and assert that the statement contains payment records
    """
    previous_day = get_previous_day(datetime.now())
    bcol_account = factory_premium_payment_account()
    payment = factory_payment(created_on=previous_day)
    invoice = factory_invoice(payment=payment, payment_account=bcol_account)
    factory_invoice_reference(invoice_id=invoice.id)
    factory_statement_settings(pay_account_id=bcol_account.account_id,
                               from_date=previous_day,
                               frequency='DAILY')
    StatementJob.generate_statements()

    pay_account = PaymentAccount.find_by_id(bcol_account.account_id)

    statements = Statement.find_all_statements_for_account(
        auth_account_id=pay_account.auth_account_id, page=1, limit=100)
    assert statements is not None
    invoices = StatementInvoices.find_all_invoices_for_statement(
        statements[0][0].id)
    assert invoices is not None
    assert invoices[0].id == invoice.id
예제 #3
0
    def get_statement_report(statement_id: str,
                             content_type: str,
                             template_name='statement_report',
                             **kwargs):
        """Generate statement report."""
        current_app.logger.debug(f'<get_statement_report {statement_id}')
        report_name: str = 'bcregistry-statements'

        statement_dao: StatementModel = StatementModel.find_by_id(statement_id)

        statement_svc = Statement()
        statement_svc._dao = statement_dao  # pylint: disable=protected-access

        from_date_string: str = statement_svc.from_date.strftime(
            DT_SHORT_FORMAT)
        to_date_string: str = statement_svc.to_date.strftime(DT_SHORT_FORMAT)

        extension: str = 'pdf' if content_type == ContentType.PDF.value else 'csv'

        if statement_svc.frequency == StatementFrequency.DAILY.value:
            report_name = f'{report_name}-{from_date_string}.{extension}'
        else:
            report_name = f'{report_name}-{from_date_string}-to-{to_date_string}.{extension}'

        statement_purchases = StatementModel.find_all_payments_and_invoices_for_statement(
            statement_id)

        result_items: dict = PaymentService.create_payment_report_details(
            purchases=statement_purchases, data=None)
        statement = statement_svc.asdict()
        statement['from_date'] = from_date_string
        statement['to_date'] = to_date_string

        report_response = PaymentService.generate_payment_report(
            content_type,
            report_name,
            result_items,
            template_name,
            auth=kwargs.get('auth', None),
            statement=statement)
        current_app.logger.debug('>get_statement_report')

        return report_response, report_name
예제 #4
0
def factory_statement(frequency: str = 'WEEKLY',
                      payment_account_id: str = None,
                      from_date: datetime = datetime.now(),
                      to_date: datetime = datetime.now(),
                      statement_settings_id: str = None,
                      created_on: datetime = datetime.now()):
    """Return Factory."""
    return Statement(frequency=frequency,
                     statement_settings_id=statement_settings_id,
                     payment_account_id=payment_account_id,
                     from_date=from_date,
                     to_date=to_date,
                     created_on=created_on).save()
예제 #5
0
    def find_by_account_id(auth_account_id: str, page: int, limit: int):
        """Find statements by account id."""
        current_app.logger.debug(f'<search_purchase_history {auth_account_id}')
        statements, total = StatementModel.find_all_statements_for_account(
            auth_account_id, page, limit)

        statements_schema = StatementModelSchema()
        data = {
            'total': total,
            'page': page,
            'limit': limit,
            'items': statements_schema.dump(statements, many=True)
        }
        current_app.logger.debug('>statements_find_by_account_id')
        return data