Add logging to all transactions

This commit is contained in:
Tanner Collin 2022-08-23 20:36:03 +00:00
parent 14933b2405
commit 226008a0c2
3 changed files with 41 additions and 8 deletions

View File

@ -467,3 +467,18 @@ def custom_exception_handler(exc, context):
if response is not None:
logging.warning('Response: %s', json.dumps(exc.detail))
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)

View File

@ -137,12 +137,15 @@ def create_unmatched_member_tx(data):
data.get('memo', 'none'),
)
return transactions.create(
tx = transactions.create(
**build_tx(data),
report_memo=report_memo,
report_type='Unmatched Member',
)
utils.log_transaction(tx)
return tx
def create_member_dues_tx(data, member, num_months, deal):
transactions = models.Transaction.objects
@ -172,6 +175,7 @@ def create_member_dues_tx(data, member, num_months, deal):
user=user,
)
utils.tally_membership_months(member)
utils.log_transaction(tx)
return tx
def create_unmatched_purchase_tx(data, member):
@ -186,13 +190,16 @@ def create_unmatched_purchase_tx(data, member):
data.get('memo', 'none'),
)
return transactions.create(
tx = transactions.create(
**build_tx(data),
report_memo=report_memo,
report_type='Unmatched Purchase',
user=user,
)
utils.log_transaction(tx)
return tx
def create_member_training_tx(data, member, training):
transactions = models.Transaction.objects
@ -206,13 +213,16 @@ def create_member_training_tx(data, member, training):
str(training.id),
)
return transactions.create(
tx = transactions.create(
**build_tx(data),
category='OnAcct',
memo=memo,
user=user,
)
utils.log_transaction(tx)
return tx
def check_training(data, training_id, amount):
trainings = models.Training.objects
@ -264,7 +274,7 @@ def create_category_tx(data, member, custom_json, amount):
note,
)
return transactions.create(
tx = transactions.create(
**build_tx(data),
category=category,
memo=memo,
@ -272,6 +282,9 @@ def create_category_tx(data, member, custom_json, amount):
protocoin=protocoin,
)
utils.log_transaction(tx)
return tx
def process_paypal_ipn(data):
'''

View File

@ -476,11 +476,13 @@ class TransactionViewSet(Base, List, Create, Retrieve, Update):
)
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()
def perform_update(self, serializer):
tx = serializer.save()
utils.log_transaction(tx)
self.retally_membership()
self.train_paypal_hint(tx)
@ -1099,7 +1101,7 @@ class ProtocoinViewSet(Base):
destination_member.id,
)
models.Transaction.objects.create(
tx = models.Transaction.objects.create(
user=source_user,
protocoin=source_delta,
amount=0,
@ -1109,8 +1111,9 @@ class ProtocoinViewSet(Base):
info_source='System',
memo=memo,
)
utils.log_transaction(tx)
models.Transaction.objects.create(
tx = models.Transaction.objects.create(
user=destination_user,
protocoin=destination_delta,
amount=0,
@ -1120,6 +1123,7 @@ class ProtocoinViewSet(Base):
info_source='System',
memo=memo,
)
utils.log_transaction(tx)
return Response(200)
@ -1189,7 +1193,7 @@ class ProtocoinViewSet(Base):
number,
)
models.Transaction.objects.create(
tx = models.Transaction.objects.create(
user=source_user,
protocoin=source_delta,
amount=0,
@ -1199,6 +1203,7 @@ class ProtocoinViewSet(Base):
info_source='System',
memo=memo,
)
utils.log_transaction(tx)
return Response(200)