use timezone aware datetime
This commit is contained in:
@@ -3,6 +3,7 @@ from apps.transactions.models import Transaction
|
||||
from apps.rates.models import ExchangeRate
|
||||
from decimal import Decimal
|
||||
import datetime
|
||||
from django.utils import timezone
|
||||
|
||||
class Calc:
|
||||
def ShowDiffRate(self, DayDiff, CurrentRate, Crypto, Fiat):
|
||||
@@ -135,7 +136,8 @@ class Calc:
|
||||
amount_within_past_year = 0
|
||||
with connection.cursor() as cursor:
|
||||
sql = """SELECT SUM(crypto_amount) as amount FROM `transaction` WHERE transaction_type='B' and crypto_currency=%s and owner_id=%s and date_valid>%s"""
|
||||
cursor.execute(sql, [crypto, userid, datetime.datetime.now() - datetime.timedelta(days=365)])
|
||||
date_valid = timezone.make_aware(datetime.datetime.now() - datetime.timedelta(days=365), timezone=timezone.get_current_timezone())
|
||||
cursor.execute(sql, [crypto, userid, date_valid])
|
||||
bought = cursor.fetchone()
|
||||
out["bought_recently"] = None
|
||||
if bought[0]:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from django import forms
|
||||
import sys
|
||||
import datetime
|
||||
from django.utils import timezone
|
||||
from apps.transactions.models import Transaction
|
||||
from apps.rates.models import ExchangeRate
|
||||
|
||||
@@ -19,7 +20,8 @@ class TransactionForm(forms.ModelForm):
|
||||
|
||||
# do not run this code in initial migration, because the database has not been built yet
|
||||
if not "migrate" in sys.argv:
|
||||
exchangerates = ExchangeRate.objects.filter(datetime_valid__gt = datetime.datetime.today() - datetime.timedelta(days=7))
|
||||
datetime_valid = timezone.make_aware(datetime.datetime.today() - datetime.timedelta(days=7), timezone=timezone.get_current_timezone())
|
||||
exchangerates = ExchangeRate.objects.filter(datetime_valid__gt = datetime_valid)
|
||||
crypto_currencies = [(x, x) for x in sorted({ex.crypto_currency for ex in exchangerates})]
|
||||
fiat_currencies = [(x, x) for x in sorted({ex.fiat_currency for ex in exchangerates})]
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ from apps.transactions.forms import ImportForm
|
||||
from apps.transactions.models import Transaction
|
||||
from apps.transactions.importbtcde import ImportBtcDe
|
||||
import datetime
|
||||
from django.utils import timezone
|
||||
import socket
|
||||
import xlwt
|
||||
from django.http import HttpResponse
|
||||
@@ -67,8 +68,9 @@ def show(request):
|
||||
tr.fiat_total += float(tr.fiat_amount)
|
||||
if tr.fiat_fee:
|
||||
tr.fiat_total += float(tr.fiat_fee)
|
||||
tax_limit_day = timezone.make_aware(datetime.datetime.now() - datetime.timedelta(days=1*365), timezone=timezone.get_current_timezone())
|
||||
return render(request,"show.html",{'transactions':transactions,
|
||||
'tax_limit_day': datetime.datetime.now() - datetime.timedelta(days=1*365),
|
||||
'tax_limit_day': tax_limit_day,
|
||||
'crypto': crypto})
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user