From 37498f9ab709c4c3707e200f370a9219318b86d1 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 9 Sep 2018 03:17:20 +0200 Subject: [PATCH] More debug output. --- matemat/db/facade.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/matemat/db/facade.py b/matemat/db/facade.py index b166a32..d3ff681 100644 --- a/matemat/db/facade.py +++ b/matemat/db/facade.py @@ -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