def get(self): accounts_query = SavingsAccount.query() accounts = accounts_query.fetch(100) for account in accounts: today = util.getTodayForTimezone(account.timezone_name) yesterday = today + timedelta(days=-1) # The transaction time must be in UTC, but that really means it can't have a tzinfo. yesterday_transaction_time = datetime( yesterday.year, yesterday.month, yesterday.day, 23, 59, 59, 999999, pytz.timezone(account.timezone_name)).astimezone(pytz.UTC).replace(tzinfo=None) logging.info('Transaction time is %s', yesterday_transaction_time) should_schedule_interest_payment = False if account.interest_compound_frequency == 'weekly': days_between = yesterday - account.getOpenDate() if days_between.days > 0 and days_between.days % 7 == 0: should_schedule_interest_payment = True else: logging.info('Not the right day to schedule weekly interest payment for %s', account.child_first_name) else: if yesterday > account.open_datetime and yesterday.day == account.open_datetime.day: should_schedule_interest_payment = True else: logging.info('Not the right day to schedule monthly interest payment for %s', account.child_first_name) if should_schedule_interest_payment: logging.info('It is the right day to pay interest for %s', account.child_first_name) if not AccountTransaction.hasInterestForDate(account, transaction_date=yesterday): interest_amount = int(account.calculateBalance(max_time=yesterday_transaction_time) * (account.interest_rate / 100)) interest_transaction = AccountTransaction(parent=account.key) interest_transaction.savings_account = account.key interest_transaction.transaction_type = 'interest' interest_transaction.amount = interest_amount interest_transaction.transaction_time = yesterday_transaction_time interest_transaction.transaction_local_date = yesterday interest_transaction.put() task = taskqueue.add( url='/send_transaction_email', params={ 'account': account.key.urlsafe(), 'transaction': interest_transaction.key.urlsafe(), }) logging.info('Interest payment %0.2f processed for %s', (interest_amount / 1000000.0), account.child_first_name) else: logging.info('Interest payment already processed for %s', account.child_first_name)
def get(self): self.response.headers['Content-Type'] = 'text/plain' if not users.get_current_user(): self.redirect(users.create_login_url(self.request.uri)) t_query = AccountTransaction.query() for t in t_query: self.response.out.write('Transaction: %s\n' % t.key) if not t.key.parent(): self.response.out.write('No parent for this transaction, making a copy\n') t2 = AccountTransaction(parent=t.savings_account) t2.savings_account = t.savings_account t2.transaction_type = t.transaction_type t2.transaction_time = t.transaction_time t2.transaction_local_date = t.transaction_local_date t2.amount = t.amount t2.memo = t.memo t2.put() self.response.out.write(' New transaction key: %s\n' % t2.key) self.response.out.write(' Deleting %s\n' % t.key) t.key.delete()