Beispiel #1
0
 def add_transaction(request_data):
     sender_account_identifier = request_data.get('sender_account_number')
     sender_account = AccountView.get_account_with_identifier(
         sender_account_identifier)
     reciever_account_identifier = request_data.get(
         'reciever_account_number')
     reciever_account = AccountView.get_account_with_identifier(
         reciever_account_identifier)
     account_transaction_type = request_data.get('account_transaction_type')
     amount = Decimal(request_data.get('amount'))
     details = request_data.get('details')
     if AccountTransactionView.validate_transaction(sender_account, amount):
         new = AccountTransaction(
             sender_account_id=sender_account.id,
             reciever_account_id=reciever_account.id,
             account_transaction_type=account_transaction_type,
             amount=amount,
             details=details)
         new.save()
         response = {
             'amount': new.get_amount_as_string(),
             'sender': sender_account_identifier,
             'reciever': reciever_account_identifier,
             'number': new.identifier
         }
     else:
         response = {'message': 'Problem creating transaction'}
     return response
Beispiel #2
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(),
                  })
Beispiel #3
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
Beispiel #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)
Beispiel #5
0
  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()
Beispiel #6
0
  def get(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()
    transactions_query = AccountTransaction.query(ancestor=account_key)
    transactions_query = transactions_query.order(AccountTransaction.transaction_time)
    transactions = transactions_query.fetch(1000)

    balance = account.opening_balance
    # Start off with the opening balance as a transaction.
    processed_transactions = [{
      'date': account.getFormattedOpenDate(),
      'type': 'Opening Balance',
      'memo': '',
      'amount': '%.2f' % (account.opening_balance / 1000000.0),
      'balance': '%.2f' % (balance / 1000000.0),
    }]
    for transaction in transactions:
      if transaction.transaction_type == 'withdrawal':
        balance -= transaction.amount
      else:
        balance += transaction.amount

      memo = transaction.memo
      if memo == None:
          memo = ''
      processed_transactions.append({
        'date': util.formatShortDate(transaction.transaction_local_date),
        'type': transaction.transaction_type,
        'memo': memo,
        'amount': '%.2f' % (transaction.amount / 1000000.0),
        'balance': '%.2f' % (balance / 1000000.0),
      })
    processed_transactions.reverse()

    template_values = {
      'current_user': users.get_current_user(),
      'account': account,
      'transactions': processed_transactions,
      'url': users.create_logout_url('/'),
      'url_linktext': 'Logout',
    }

    self.response.out.write(template.render(
        getTemplatePath('transaction_list.html'), template_values))
Beispiel #7
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')