コード例 #1
0
    def find_by_account_id(auth_account_id: str):
        """Find statements by account id."""
        current_app.logger.debug(f'<find_by_account_id {auth_account_id}')
        statements_settings = StatementSettingsModel.find_latest_settings(
            auth_account_id)
        if statements_settings is None:
            return None
        all_settings = []

        # iterate and find the next start date to all frequencies
        for freq in StatementFrequency:
            max_frequency = StatementSettings._find_longest_frequency(
                statements_settings.frequency, freq.value)
            last_date = StatementSettings._get_end_of(max_frequency)
            all_settings.append({
                'frequency': freq.name,
                'start_date': last_date + timedelta(days=1)
            })

        statements_settings_schema = StatementSettingsModelSchema()
        settings_details = {
            'current_frequency':
            statements_settings_schema.dump(statements_settings),
            'frequencies':
            all_settings
        }

        current_app.logger.debug('>statements_find_by_account_id')
        return settings_details
コード例 #2
0
 def find_by_account_id(auth_account_id: str):
     """Find statements by account id."""
     current_app.logger.debug(f'<find_by_account_id {auth_account_id}')
     statements_settings = StatementSettingsModel.find_latest_settings(
         auth_account_id)
     statements_settings_schema = StatementSettingsModelSchema()
     current_app.logger.debug('>statements_find_by_account_id')
     return statements_settings_schema.dump(statements_settings)
コード例 #3
0
    def update_statement_settings(auth_account_id: str, frequency: str):
        """Update statements by account id.

        rather than checking frequency changes by individual if , it just applies the following logic.
        find the maximum frequency of current one and new one ;and calculate the date which it will keep on going.

        """
        statements_settings_schema = StatementSettingsModelSchema()
        today = datetime.today()
        current_statements_settings = StatementSettingsModel.find_active_settings(
            auth_account_id, today)
        payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
            auth_account_id)
        if current_statements_settings is None:
            # no frequency yet.first time accessing the statement settings.so create a new record
            statements_settings = StatementSettingsModel(
                frequency=frequency, payment_account_id=payment_account.id)
            statements_settings.save()
            return statements_settings_schema.dump(statements_settings)

        # check if the latest one is the active one.. if not , inactivate the latest one.
        # this handles the case of quickly changing of frequencies..
        # changed from daily to monthly but then changed back to weekly..
        # the monthly didn't get applied ,but even before that its being changed to weekly
        future_statements_settings = StatementSettingsModel.find_latest_settings(
            auth_account_id)
        if future_statements_settings is not None and current_statements_settings.id != future_statements_settings.id:
            future_statements_settings.to_date = today
            future_statements_settings.save()

        max_frequency = StatementSettings._find_longest_frequency(
            current_statements_settings.frequency, frequency)
        last_date = StatementSettings._get_end_of(max_frequency)
        current_statements_settings.to_date = last_date
        current_statements_settings.save()

        new_statements_settings = StatementSettingsModel(
            frequency=frequency,
            payment_account_id=payment_account.id,
            from_date=last_date + timedelta(days=1))

        new_statements_settings.save()
        return statements_settings_schema.dump(new_statements_settings)