def get(self): if not users.get_current_user(): self.redirect(users.create_login_url(self.request.uri)) accounts_query = SavingsAccount.query() accounts_query.order(SavingsAccount.child_first_name) accounts_query.filter(SavingsAccount.parent_user == users.get_current_user()) accounts = accounts_query.fetch(100) accounts_left = [] accounts_right = [] account_num = 0 for account in accounts: account_num += 1 if account_num % 2 != 0: accounts_left.append(account) else: accounts_right.append(account) template_values = { 'current_user': users.get_current_user(), 'accounts_left': accounts_left, 'accounts_right': accounts_right, 'url': users.create_logout_url('/'), 'url_linktext': 'Logout', } self.response.out.write(template.render( getTemplatePath('account_list.html'), template_values))
def get(self): accounts_query = SavingsAccount.query() accounts = accounts_query.fetch(100) for account in accounts: today = util.getTodayForTimezone(account.timezone_name) should_schedule_allowance_payment = False if account.allowance_frequency == 'weekly': days_between = today - account.allowance_start_date if days_between.days >= 0 and days_between.days % 7 == 0: should_schedule_allowance_payment = True else: logging.info("Not the right day to schedule weekly allowance for %s", account.child_first_name) else: # Monthly # TODO(jgessner): Deal with a Feb 29 start date. if today.day == allowance_start_date.day: should_schedule_allowance_payment = True else: logging.info("Not the right day to schedule monthly allowance for %s", account.child_first_name) logging.info('Should i schedule the %s allowance of %s starting %s for %s? %s' % (account.allowance_frequency, account.getAllowanceAmountForPrinting(), account.allowance_start_date, account.child_first_name, should_schedule_allowance_payment)) if should_schedule_allowance_payment: if not AccountTransaction.hasAllowanceForDate(account, transaction_date=today): transaction = AccountTransaction(parent=account.key) transaction.savings_account = account.key transaction.transaction_type = 'allowance' transaction.transaction_local_date = today transaction.amount = account.allowance_amount transaction.put() task = taskqueue.add( url='/send_transaction_email', params={ 'account': account.key.urlsafe(), 'transaction': transaction.key.urlsafe(), })
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 post(self): if not users.get_current_user(): self.redirect(users.create_login_url(self.request.uri)) account = SavingsAccount() account.parent_user = users.get_current_user() account.child_first_name = self.request.get('child_first_name') account.child_email = self.request.get('child_email') # TODO(jgessner): make this a best fit instead of a blind resize if self.request.get("child_image"): account.child_image = images.resize(self.request.get("child_image"), 200, 200) account.currency = self.request.get('currency') account.interest_rate = float(self.request.get('interest_rate')) account.interest_compound_frequency = self.request.get('interest_compound_frequency') # TODO(jgessner): make a constant for the micros value account.opening_balance = int(float(self.request.get('opening_balance')) * 1000000) account.allowance_amount = int(float(self.request.get('allowance_amount')) * 1000000) account.allowance_frequency = self.request.get('allowance_frequency') account.allowance_start_date = util.parseShortDate(self.request.get('allowance_start_date')) account.timezone_name = self.request.get('account_timezone') account.put() self.redirect('/accounts')