More debug output.

This commit is contained in:
s3lph 2018-09-09 03:17:20 +02:00
parent 2161ff79d9
commit 37498f9ab7

View file

@ -4,7 +4,8 @@ from typing import List, Optional, Any, Type
import crypt
from hmac import compare_digest
from datetime import datetime, timedelta
from datetime import datetime
import logging
from matemat.db.primitives import User, Product, ReceiptPreference, Receipt,\
Transaction, Consumption, Deposit, Modification
@ -577,9 +578,11 @@ class MatematDatabase(object):
user.balance = old_balance + amount
def check_receipt_due(self, user: User) -> bool:
logger = logging.getLogger('matemat.db.facage.check_receipt_due')
if not isinstance(user.receipt_pref, ReceiptPreference):
raise TypeError()
if user.receipt_pref == ReceiptPreference.NONE or user.email is None:
logger.debug('Receipt preference None or no e-mail.')
return False
with self.db.transaction() as c:
c.execute('''
@ -589,8 +592,12 @@ class MatematDatabase(object):
ON r.user_id = u.user_id
WHERE u.user_id = :user_id
''', [user.id])
last_receipt: datetime = datetime.fromtimestamp(c.fetchone()[0])
next_receipt_due: datetime = user.receipt_pref.next_receipt_due(last_receipt)
logger.debug('Last receipt: %s.', last_receipt)
logger.debug('Next receipt: %s.', next_receipt_due)
logger.debug('Now: %s.', datetime.utcnow())
return datetime.utcnow() > next_receipt_due