Added initial data puller functions.
This commit is contained in:
parent
37f805ebe1
commit
f73fac4324
@ -105,4 +105,4 @@ class Connection(AbstractConnectionClient):
|
|||||||
auth_token, start_date, end_date)
|
auth_token, start_date, end_date)
|
||||||
except plaid.errors.PlaidError as e:
|
except plaid.errors.PlaidError as e:
|
||||||
return format_error(e)
|
return format_error(e)
|
||||||
return transactions_resp
|
return transactions_resp.get("transactions")
|
||||||
|
|||||||
@ -1,4 +1,32 @@
|
|||||||
from qrtr_account.models import Transaction
|
from qrtr_account.models import Transaction, Bank, Account
|
||||||
from connection.models import Connection
|
from connection.models import Connection
|
||||||
|
|
||||||
|
|
||||||
|
def get_and_save_transactions(connection, start_date=None, end_date=None):
|
||||||
|
client = connection.connect()
|
||||||
|
transactions = client.get_transactions(start_date=start_date,
|
||||||
|
end_date=end_date)
|
||||||
|
for trns in transactions:
|
||||||
|
Transaction.objects.update_or_create(
|
||||||
|
trans_id=trns.get("transaction_id"),
|
||||||
|
defaults={"authorized_date": trns.get("authorized_date"),
|
||||||
|
"trans_id": trns.get("transaction_id"),
|
||||||
|
"details": trns,
|
||||||
|
"bank": Bank.objects.get(acc_id=trns.get("account_id")),
|
||||||
|
"name": trns.get("name")})
|
||||||
|
return True
|
||||||
|
|
||||||
|
def pull_transactions(account_ids=[], exclude_ids=[], start_date=None,
|
||||||
|
end_date=None):
|
||||||
|
if account_ids:
|
||||||
|
accounts = Account.objects.filter(pk__in=account_ids).exclude(pk__in=exclude_ids)
|
||||||
|
else:
|
||||||
|
accounts = Account.objects.exclude(pk__in=exclude_ids)
|
||||||
|
|
||||||
|
for account in accounts:
|
||||||
|
connections = account.connection_set.all()
|
||||||
|
for connection in connections:
|
||||||
|
get_and_save_transactions(connection,
|
||||||
|
start_date=start_date, end_date=end_date)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -112,15 +112,19 @@ class Rule(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Transaction(models.Model):
|
class Transaction(models.Model):
|
||||||
datetime = models.DateTimeField()
|
authorized_date = models.DateField(null=True)
|
||||||
Bank = models.ForeignKey(Bank, on_delete=models.CASCADE,
|
bank = models.ForeignKey(Bank, on_delete=models.CASCADE,
|
||||||
related_name='transactions')
|
related_name='transactions')
|
||||||
|
name = models.CharField(max_length=255)
|
||||||
details = models.JSONField()
|
details = models.JSONField()
|
||||||
Slice = models.ForeignKey(Slice, on_delete=models.SET_NULL, null=True)
|
Slice = models.ForeignKey(Slice, on_delete=models.SET_NULL, null=True)
|
||||||
|
trans_id = models.CharField(max_length=255)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def qid(self):
|
def qid(self):
|
||||||
return f"T{self.pk}"
|
return f"T{self.pk}"
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.Bank} - {self.datetime}"
|
return f"{self.bank} - {self.authorized_date} - {self.name} - {self.details.get('amount')}"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user