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
Example #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
Example #3
0
    def _generate_weekly_statements(cls, current_time: datetime):
        """Generate weekly statements for all accounts with settings to generate weekly."""
        statement_settings = StatementSettingsModel.find_accounts_settings_by_frequency(
            get_previous_day(current_time), StatementFrequency.WEEKLY)
        current_app.logger.debug(
            f'Found {len(statement_settings)} accounts to generate WEEKLY statements'
        )
        search_filter = {
            'weekFilter': {
                'index': 1  # previous week
            }
        }

        cls._create_statement_records(current_time, search_filter,
                                      statement_settings)
Example #4
0
 def _generate_daily_statements(cls, current_time: datetime):
     """Generate daily statements for all accounts with settings to generate daily."""
     statement_settings = StatementSettingsModel.find_accounts_settings_by_frequency(
         current_time, StatementFrequency.DAILY)
     current_app.logger.debug(
         f'Found {len(statement_settings)} accounts to generate DAILY statements'
     )
     previous_day = get_previous_day(current_time)
     search_filter = {
         'dateFilter': {
             'startDate': previous_day.strftime('%m/%d/%Y'),
             'endDate': previous_day.strftime('%m/%d/%Y')
         }
     }
     cls._create_statement_records(previous_day, search_filter,
                                   statement_settings)
Example #5
0
    def _generate_monthly_statements(cls, current_time: datetime):
        """Generate monthly statements for all accounts with settings to generate monthly."""
        statement_settings = StatementSettingsModel.find_accounts_settings_by_frequency(
            get_previous_day(current_time), StatementFrequency.MONTHLY)
        current_app.logger.debug(
            f'Found {len(statement_settings)} accounts to generate MONTHLY statements'
        )
        last_month, last_month_year = get_previous_month_and_year()
        search_filter = {
            'monthFilter': {
                'month': last_month,
                'year': last_month_year
            }
        }

        cls._create_statement_records(current_time, search_filter,
                                      statement_settings)