diff --git a/apiserver/apiserver/api/utils.py b/apiserver/apiserver/api/utils.py index deffe25..6c9c72d 100644 --- a/apiserver/apiserver/api/utils.py +++ b/apiserver/apiserver/api/utils.py @@ -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) diff --git a/apiserver/apiserver/api/utils_paypal.py b/apiserver/apiserver/api/utils_paypal.py index a2d0af8..ddd9cf1 100644 --- a/apiserver/apiserver/api/utils_paypal.py +++ b/apiserver/apiserver/api/utils_paypal.py @@ -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): ''' diff --git a/apiserver/apiserver/api/views.py b/apiserver/apiserver/api/views.py index 0fc447a..518d3e8 100644 --- a/apiserver/apiserver/api/views.py +++ b/apiserver/apiserver/api/views.py @@ -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)