From 495039e6a0df1b16ebb9460a4cd1da4028907712 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 18 Apr 2023 08:58:36 +0100 Subject: [PATCH] Implement overriding owner name with requisition field --- core/clients/aggregator.py | 6 ++++++ core/forms.py | 2 ++ core/lib/schemas/nordigen_s.py | 2 +- core/migrations/0036_requisition_owner_name.py | 18 ++++++++++++++++++ core/models.py | 2 ++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 core/migrations/0036_requisition_owner_name.py diff --git a/core/clients/aggregator.py b/core/clients/aggregator.py index d08daa1..c8927fc 100644 --- a/core/clients/aggregator.py +++ b/core/clients/aggregator.py @@ -22,6 +22,12 @@ class AggregatorClient(ABC): for bank, accounts in account_infos.items(): # Iterate the accounts for index, account in enumerate(list(accounts)): + if account["ownerName"] is None: + requisition = self.instance.get_requisition( + account["requisition_id"] + ) + if requisition is not None: + account["ownerName"] = requisition.owner_name if "account_number" not in account: account_infos[bank][index]["account_number"] = {} fields = ["sort_code", "number", "iban"] diff --git a/core/forms.py b/core/forms.py index d2f2d0c..10ab1a3 100644 --- a/core/forms.py +++ b/core/forms.py @@ -234,12 +234,14 @@ class RequisitionForm(RestrictedFormMixin, ModelForm): model = Requisition fields = ( "payment_details", + "owner_name", "transaction_source", "payees", ) help_texts = { "payment_details": "Shown once a user opens a trade.", + "owner_name": "Owner name to send with payment details if not provided by aggregator.", "transaction_source": "Whether to check pending or booked transactions.", "payees": "The wallet addresses to send profit concerning this requisition to.", } diff --git a/core/lib/schemas/nordigen_s.py b/core/lib/schemas/nordigen_s.py index 983b9f7..a6914e4 100644 --- a/core/lib/schemas/nordigen_s.py +++ b/core/lib/schemas/nordigen_s.py @@ -119,7 +119,7 @@ RequisitionSchema = { class AccountDetailsNested(MyModel): resourceId: str currency: str - ownerName: str + ownerName: str | None cashAccountType: str | None status: str | None maskedPan: str | None diff --git a/core/migrations/0036_requisition_owner_name.py b/core/migrations/0036_requisition_owner_name.py new file mode 100644 index 0000000..39ab20b --- /dev/null +++ b/core/migrations/0036_requisition_owner_name.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-04-18 07:54 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0035_ad_require_feedback_score'), + ] + + operations = [ + migrations.AddField( + model_name='requisition', + name='owner_name', + field=models.CharField(blank=True, max_length=255, null=True), + ), + ] diff --git a/core/models.py b/core/models.py index 4db155a..f8b63f5 100644 --- a/core/models.py +++ b/core/models.py @@ -604,6 +604,8 @@ class Requisition(models.Model): requisition_id = models.CharField(max_length=255) payment_details = models.TextField(null=True, blank=True) + owner_name = models.CharField(max_length=255, null=True, blank=True) + transaction_source = models.CharField( max_length=255, choices=TRANSACTION_SOURCE_CHOICES, default="booked" )