diff --git a/app/urls.py b/app/urls.py index 1ae2369..d61ca73 100644 --- a/app/urls.py +++ b/app/urls.py @@ -110,6 +110,11 @@ urlpatterns = [ banks.BanksCurrencies.as_view(), name="currencies", ), + path( + "banks//req///", + banks.BanksRequisitionUpdate.as_view(), + name="requisition_update", + ), # Bank balances path( "banks//balances/", diff --git a/core/clients/aggregator.py b/core/clients/aggregator.py index 3e1c14e..4ad7788 100644 --- a/core/clients/aggregator.py +++ b/core/clients/aggregator.py @@ -19,6 +19,7 @@ class AggregatorClient(ABC): # #if account["account_id"] in self.banks # } # For each bank + print("ACCOUNT INFOS", account_infos) for bank, accounts in account_infos.items(): # Iterate the accounts for index, account in enumerate(list(accounts)): @@ -50,6 +51,8 @@ class AggregatorClient(ABC): self.instance.currencies = currencies self.instance.save() + print("INSTANCE ACCOUNT INFO", self.instance.account_info) + async def process_transactions(self, account_id, transactions): if not transactions: return False diff --git a/core/clients/platform.py b/core/clients/platform.py index c7eb0ca..604bfe4 100644 --- a/core/clients/platform.py +++ b/core/clients/platform.py @@ -1104,6 +1104,12 @@ class LocalPlatformClient(ABC): currency_account_info_map[currency]["recipient"] = account[ "ownerName" ] + currency_account_info_map[currency]["aggregator_id"] = account[ + "aggregator_id" + ] + currency_account_info_map[currency]["requisition_id"] = account[ + "requisition_id" + ] return (list(currency_account_info_map.keys()), currency_account_info_map) def get_matching_account_details(self, currency, ad): @@ -1200,12 +1206,21 @@ class LocalPlatformClient(ABC): if not payment_details: return False if real: - payment = ad.payment_details_real + aggregator_id = payment_details["aggregator_id"] + requisition_id = payment_details["requisition_id"] + req = self.instance.get_requisition(aggregator_id, requisition_id) + if req: + payment = req.payment_details + else: + payment = ad.payment_details_real else: payment = ad.payment_details payment_text = "" for field, value in payment_details.items(): + if field in ["aggregator_id", "requisition_id"]: + # Don't send these to the user + continue formatted_name = field.replace("_", " ") formatted_name = formatted_name.capitalize() payment_text += f"* {formatted_name}: **{value}**" diff --git a/core/forms.py b/core/forms.py index af07158..8822bbe 100644 --- a/core/forms.py +++ b/core/forms.py @@ -11,6 +11,7 @@ from .models import ( NotificationSettings, Platform, Provider, + Requisition, User, ) @@ -205,3 +206,17 @@ class AdForm(RestrictedFormMixin, ModelForm): help_text=Meta.help_texts["aggregators"], required=True, ) + + +class RequisitionForm(RestrictedFormMixin, ModelForm): + class Meta: + model = Requisition + fields = ( + "payment_details", + "transaction_source", + ) + + help_texts = { + "payment_details": "Shown once a user opens a trade.", + "transaction_source": "Whether to check pending or booked transactions.", + } diff --git a/core/lib/schemas/nordigen_s.py b/core/lib/schemas/nordigen_s.py index ceb2d2f..983b9f7 100644 --- a/core/lib/schemas/nordigen_s.py +++ b/core/lib/schemas/nordigen_s.py @@ -171,7 +171,7 @@ class TransactionsCurrencyExchange(MyModel): class TXAccount(MyModel): - iban: str + iban: str | None bban: str | None @@ -191,6 +191,7 @@ class TransactionsNested(MyModel): proprietaryBankTransactionCode: str | None internalTransactionId: str | None currencyExchange: TransactionsCurrencyExchange | None + merchantCategoryCode: str | None class TransactionsBookedPending(MyModel): diff --git a/core/migrations/0025_requisition.py b/core/migrations/0025_requisition.py new file mode 100644 index 0000000..431ab1b --- /dev/null +++ b/core/migrations/0025_requisition.py @@ -0,0 +1,26 @@ +# Generated by Django 4.1.7 on 2023-03-15 10:14 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0024_ad_send_reference'), + ] + + operations = [ + migrations.CreateModel( + name='Requisition', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('requisition_id', models.CharField(max_length=255)), + ('payment_details', models.TextField()), + ('transaction_source', models.CharField(choices=[('booked', 'Booked'), ('pending', 'Pending')], max_length=255)), + ('aggregator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.aggregator')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/core/migrations/0026_alter_requisition_transaction_source.py b/core/migrations/0026_alter_requisition_transaction_source.py new file mode 100644 index 0000000..f941aaf --- /dev/null +++ b/core/migrations/0026_alter_requisition_transaction_source.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-03-15 10:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0025_requisition'), + ] + + operations = [ + migrations.AlterField( + model_name='requisition', + name='transaction_source', + field=models.CharField(choices=[('booked', 'Booked'), ('pending', 'Pending')], default='booked', max_length=255), + ), + ] diff --git a/core/migrations/0027_alter_requisition_payment_details.py b/core/migrations/0027_alter_requisition_payment_details.py new file mode 100644 index 0000000..51d7443 --- /dev/null +++ b/core/migrations/0027_alter_requisition_payment_details.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-03-15 10:18 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('core', '0026_alter_requisition_transaction_source'), + ] + + operations = [ + migrations.AlterField( + model_name='requisition', + name='payment_details', + field=models.TextField(blank=True, null=True), + ), + ] diff --git a/core/models.py b/core/models.py index ce04f20..ccdb32b 100644 --- a/core/models.py +++ b/core/models.py @@ -363,6 +363,16 @@ class Platform(models.Model): return aggregators + def get_requisition(self, aggregator_id, requisition_id): + """ + Get a Requisition object with the provided values. + """ + requisition = Requisition.objects.filter( + aggregator_id=aggregator_id, + requisition_id=requisition_id, + ).first() + return requisition + class Asset(models.Model): code = models.CharField(max_length=64) @@ -493,12 +503,13 @@ class Requisition(models.Model): A requisition for an Aggregator """ + user = models.ForeignKey(User, on_delete=models.CASCADE) aggregator = models.ForeignKey(Aggregator, on_delete=models.CASCADE) requisition_id = models.CharField(max_length=255) - payment_details = models.TextField() + payment_details = models.TextField(null=True, blank=True) transaction_source = models.CharField( - max_length=255, choices=TRANSACTION_SOURCE_CHOICES + max_length=255, choices=TRANSACTION_SOURCE_CHOICES, default="booked" ) # throughput = models.FloatField(default=0) diff --git a/core/templates/partials/banks-currencies-list.html b/core/templates/partials/banks-currencies-list.html index a417e85..8d54e8a 100644 --- a/core/templates/partials/banks-currencies-list.html +++ b/core/templates/partials/banks-currencies-list.html @@ -7,7 +7,18 @@ {# cache 600 objects_banks_currencies request.user.id object_list type last #} {% for bank, accounts in object_list.items %} -

{{ bank.0 }} {{ bank.1 }}

+

{{ bank.0 }} {{ bank.1 }} + + + + + +