Ejemplo n.º 1
0
  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(),
                  })
Ejemplo n.º 2
0
 def saveNewTransaction(self, account, transaction_type, transaction_amount, memo):
   transaction = AccountTransaction(parent=account.key)
   # TODO(jgessner): remove the extra savings_account field.
   transaction.savings_account = account.key
   transaction.transaction_type = transaction_type
   transaction.amount = int(float(transaction_amount) * 1000000)
   transaction.transaction_local_date = util.getTodayForTimezone(account.timezone_name)
   transaction.memo = memo
   transaction.put()
   return transaction.key
Ejemplo n.º 3
0
  def post(self):
    if not users.get_current_user():
      self.redirect(users.create_login_url(self.request.uri))

    account_key = ndb.Key(urlsafe=self.request.get('account'))
    account = account_key.get()

    transaction = AccountTransaction()
    transaction.savings_account = account.key
    transaction.transaction_type = self.request.get('transaction_type')
    transaction.amount = int(float(self.request.get('amount')) * 1000000)
    transaction.transaction_local_date = util.getTodayForTimezone(account.timezone_name)
    transaction.put()

    self.redirect('/accounts')
Ejemplo n.º 4
0
  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)