コード例 #1
0
    def round_account_balances(self, msg_json):
        """
        Iterates through all active accounts, except the savings account
        and rounds the account's balance down to either x.00 or x.50, depending
        on the _ROUNDING_FACTOR

        Parameters
        ----------
        msg_json    : dict, HTTP request body from Callback

        """
        category = msg_json['NotificationUrl']['category']
        logger.info(f'Received Callback - {category}')

        accounts = util.get_active_accounts()
        savings_IBAN = util.get_iban(self.savings_account)
        for acc in accounts:
            if util.get_iban(acc) != savings_IBAN:
                self._round_balance(acc)
コード例 #2
0
ファイル: budget.py プロジェクト: PJUllrich/bunq-better-bot
    def _get_budget_accounts(self, accounts):
        """
        Iterates through a list of MonetaryAccountBank objects and selects
        those whose IBAN matches an IBAN in self.IBANs

        Parameters
        ----------
        accounts : list[MonetaryAccountBank]
            All accounts of a user

        Returns
        -------
        list[MonetaryAccountBank]
            All accounts whose IBAN is in self.IBANs
        """

        return [acc for acc in accounts if get_iban(acc) in self.IBANs]
コード例 #3
0
ファイル: budget.py プロジェクト: PJUllrich/bunq-better-bot
    def _get_to_foreign(self, payments, accounts_own):
        """
        Selects payments that were done to accounts that are not among the
        own accounts, thus payments going to 'foreign' accounts.

        Parameters
        ----------
        payments        : list[Payment]
        accounts_own    : list[MonetaryAccountBank]

        Returns
        -------
        list[Payment]
            The filtered list of payments
        """

        IBANs_own = [get_iban(acc) for acc in accounts_own]
        payments_filtered = [p for p in payments if
                             self._is_to_foreign(p, IBANs_own)]
        return payments_filtered
コード例 #4
0
    def _create_payment_request_map(self, account_to, amount):
        """Creates a request map for an IBAN -> IBAN transaction with a
        given (absolute) amount (in EUR)
        """
        request_map = {
            generated.Payment.FIELD_AMOUNT: object_.Amount(
                abs(amount),
                'EUR'
            ),
            generated.Payment.FIELD_COUNTERPARTY_ALIAS: object_.Pointer(
                'IBAN',
                util.get_iban(account_to)
            ),
            generated.Payment.FIELD_DESCRIPTION:
                self._SAVING_PAYMENT_DESCRIPTION,
        }

        request_map[generated.Payment.FIELD_COUNTERPARTY_ALIAS].name = \
            util.get_attr_from_alias(account_to, 'name', 'IBAN')

        return request_map
コード例 #5
0
    def _round_balance(self, account):
        # TODO: Check the result from make_payment for success
        """Calculates the amount that needs to be transferred to the savings
        account in order to round the account's balance to either x.00 or
        x.50, depending on the _ROUNDING_FACTOR

        Creates a request map with data to which account which amount should
        be transferred.

        Sends this request map to the make_payment function and logs the result

        """
        amount_to_save = self._get_amount_to_save(account)
        if amount_to_save > 0:
            request_map = self._create_payment_request_map(self.savings_account,
                                                           amount_to_save)
            res = util.make_payment(account, request_map)
            logger.debug(f'Payment made. Response: {res}')

            IBAN_from = util.get_iban(account)
            logger.info(f'Transferred {amount_to_save:.2f} Euro from '
                        f'{IBAN_from} to {util.get_iban(self.savings_account)}')
        else:
            logger.info('Amount to save was 0.00. Doing nothing.')
コード例 #6
0
 def get_iban(account):
     return util.get_iban(account)