Add logging to all transactions
This commit is contained in:
parent
14933b2405
commit
226008a0c2
|
@ -467,3 +467,18 @@ def custom_exception_handler(exc, context):
|
||||||
if response is not None:
|
if response is not None:
|
||||||
logging.warning('Response: %s', json.dumps(exc.detail))
|
logging.warning('Response: %s', json.dumps(exc.detail))
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
def log_transaction(tx):
|
||||||
|
msg = 'Transaction log | {} | {} | {} | {} | {} | {} | {} | {} | {}'.format(
|
||||||
|
tx.id,
|
||||||
|
tx.user.username,
|
||||||
|
tx.user.member.id,
|
||||||
|
tx.account_type,
|
||||||
|
tx.amount,
|
||||||
|
tx.protocoin,
|
||||||
|
tx.category,
|
||||||
|
tx.reference_number,
|
||||||
|
tx.memo,
|
||||||
|
)
|
||||||
|
|
||||||
|
logging.info(msg)
|
||||||
|
|
|
@ -137,12 +137,15 @@ def create_unmatched_member_tx(data):
|
||||||
data.get('memo', 'none'),
|
data.get('memo', 'none'),
|
||||||
)
|
)
|
||||||
|
|
||||||
return transactions.create(
|
tx = transactions.create(
|
||||||
**build_tx(data),
|
**build_tx(data),
|
||||||
report_memo=report_memo,
|
report_memo=report_memo,
|
||||||
report_type='Unmatched Member',
|
report_type='Unmatched Member',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
utils.log_transaction(tx)
|
||||||
|
return tx
|
||||||
|
|
||||||
def create_member_dues_tx(data, member, num_months, deal):
|
def create_member_dues_tx(data, member, num_months, deal):
|
||||||
transactions = models.Transaction.objects
|
transactions = models.Transaction.objects
|
||||||
|
|
||||||
|
@ -172,6 +175,7 @@ def create_member_dues_tx(data, member, num_months, deal):
|
||||||
user=user,
|
user=user,
|
||||||
)
|
)
|
||||||
utils.tally_membership_months(member)
|
utils.tally_membership_months(member)
|
||||||
|
utils.log_transaction(tx)
|
||||||
return tx
|
return tx
|
||||||
|
|
||||||
def create_unmatched_purchase_tx(data, member):
|
def create_unmatched_purchase_tx(data, member):
|
||||||
|
@ -186,13 +190,16 @@ def create_unmatched_purchase_tx(data, member):
|
||||||
data.get('memo', 'none'),
|
data.get('memo', 'none'),
|
||||||
)
|
)
|
||||||
|
|
||||||
return transactions.create(
|
tx = transactions.create(
|
||||||
**build_tx(data),
|
**build_tx(data),
|
||||||
report_memo=report_memo,
|
report_memo=report_memo,
|
||||||
report_type='Unmatched Purchase',
|
report_type='Unmatched Purchase',
|
||||||
user=user,
|
user=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
utils.log_transaction(tx)
|
||||||
|
return tx
|
||||||
|
|
||||||
def create_member_training_tx(data, member, training):
|
def create_member_training_tx(data, member, training):
|
||||||
transactions = models.Transaction.objects
|
transactions = models.Transaction.objects
|
||||||
|
|
||||||
|
@ -206,13 +213,16 @@ def create_member_training_tx(data, member, training):
|
||||||
str(training.id),
|
str(training.id),
|
||||||
)
|
)
|
||||||
|
|
||||||
return transactions.create(
|
tx = transactions.create(
|
||||||
**build_tx(data),
|
**build_tx(data),
|
||||||
category='OnAcct',
|
category='OnAcct',
|
||||||
memo=memo,
|
memo=memo,
|
||||||
user=user,
|
user=user,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
utils.log_transaction(tx)
|
||||||
|
return tx
|
||||||
|
|
||||||
def check_training(data, training_id, amount):
|
def check_training(data, training_id, amount):
|
||||||
trainings = models.Training.objects
|
trainings = models.Training.objects
|
||||||
|
|
||||||
|
@ -264,7 +274,7 @@ def create_category_tx(data, member, custom_json, amount):
|
||||||
note,
|
note,
|
||||||
)
|
)
|
||||||
|
|
||||||
return transactions.create(
|
tx = transactions.create(
|
||||||
**build_tx(data),
|
**build_tx(data),
|
||||||
category=category,
|
category=category,
|
||||||
memo=memo,
|
memo=memo,
|
||||||
|
@ -272,6 +282,9 @@ def create_category_tx(data, member, custom_json, amount):
|
||||||
protocoin=protocoin,
|
protocoin=protocoin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
utils.log_transaction(tx)
|
||||||
|
return tx
|
||||||
|
|
||||||
|
|
||||||
def process_paypal_ipn(data):
|
def process_paypal_ipn(data):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -476,11 +476,13 @@ class TransactionViewSet(Base, List, Create, Retrieve, Update):
|
||||||
)
|
)
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
def perform_create(self, serializer):
|
||||||
serializer.save(recorder=self.request.user)
|
tx = serializer.save(recorder=self.request.user)
|
||||||
|
utils.log_transaction(tx)
|
||||||
self.retally_membership()
|
self.retally_membership()
|
||||||
|
|
||||||
def perform_update(self, serializer):
|
def perform_update(self, serializer):
|
||||||
tx = serializer.save()
|
tx = serializer.save()
|
||||||
|
utils.log_transaction(tx)
|
||||||
self.retally_membership()
|
self.retally_membership()
|
||||||
self.train_paypal_hint(tx)
|
self.train_paypal_hint(tx)
|
||||||
|
|
||||||
|
@ -1099,7 +1101,7 @@ class ProtocoinViewSet(Base):
|
||||||
destination_member.id,
|
destination_member.id,
|
||||||
)
|
)
|
||||||
|
|
||||||
models.Transaction.objects.create(
|
tx = models.Transaction.objects.create(
|
||||||
user=source_user,
|
user=source_user,
|
||||||
protocoin=source_delta,
|
protocoin=source_delta,
|
||||||
amount=0,
|
amount=0,
|
||||||
|
@ -1109,8 +1111,9 @@ class ProtocoinViewSet(Base):
|
||||||
info_source='System',
|
info_source='System',
|
||||||
memo=memo,
|
memo=memo,
|
||||||
)
|
)
|
||||||
|
utils.log_transaction(tx)
|
||||||
|
|
||||||
models.Transaction.objects.create(
|
tx = models.Transaction.objects.create(
|
||||||
user=destination_user,
|
user=destination_user,
|
||||||
protocoin=destination_delta,
|
protocoin=destination_delta,
|
||||||
amount=0,
|
amount=0,
|
||||||
|
@ -1120,6 +1123,7 @@ class ProtocoinViewSet(Base):
|
||||||
info_source='System',
|
info_source='System',
|
||||||
memo=memo,
|
memo=memo,
|
||||||
)
|
)
|
||||||
|
utils.log_transaction(tx)
|
||||||
|
|
||||||
return Response(200)
|
return Response(200)
|
||||||
|
|
||||||
|
@ -1189,7 +1193,7 @@ class ProtocoinViewSet(Base):
|
||||||
number,
|
number,
|
||||||
)
|
)
|
||||||
|
|
||||||
models.Transaction.objects.create(
|
tx = models.Transaction.objects.create(
|
||||||
user=source_user,
|
user=source_user,
|
||||||
protocoin=source_delta,
|
protocoin=source_delta,
|
||||||
amount=0,
|
amount=0,
|
||||||
|
@ -1199,6 +1203,7 @@ class ProtocoinViewSet(Base):
|
||||||
info_source='System',
|
info_source='System',
|
||||||
memo=memo,
|
memo=memo,
|
||||||
)
|
)
|
||||||
|
utils.log_transaction(tx)
|
||||||
|
|
||||||
return Response(200)
|
return Response(200)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user