Beispiel #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(),
                  })