From a87cb31d7e5aa9679491dd6de20b81b0e9e0d9ad Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Tue, 21 Oct 2025 12:25:24 +0300 Subject: [PATCH] Features: 1) Add `Gateway` model with fields for UUID, activation status, currency details, limits, and integration variables; 2) Add `gateway` foreign key to `Transaction` model; 3) Introduce `is_static_page` field to `Post` model to differentiate static pages; 4) Add `integration_path` field to `Vendor` model. Fixes: 1) Correct import order in `payments.admin`. Extra: 1) Update `productimage.priority` field in `core` app with default value and help text; 2) Include `integration_path` in `Vendor` admin additional fields. --- blog/migrations/0007_post_is_static_page.py | 22 +++ core/admin.py | 1 + ...ration_path_alter_productimage_priority.py | 33 ++++ payments/admin.py | 2 +- .../0005_gateway_transaction_gateway.py | 156 ++++++++++++++++++ 5 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 blog/migrations/0007_post_is_static_page.py create mode 100644 core/migrations/0048_vendor_integration_path_alter_productimage_priority.py create mode 100644 payments/migrations/0005_gateway_transaction_gateway.py diff --git a/blog/migrations/0007_post_is_static_page.py b/blog/migrations/0007_post_is_static_page.py new file mode 100644 index 00000000..2f3a971e --- /dev/null +++ b/blog/migrations/0007_post_is_static_page.py @@ -0,0 +1,22 @@ +# Generated by Django 5.2 on 2025-10-21 09:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("blog", "0006_post_meta_description_post_meta_description_ar_ar_and_more"), + ] + + operations = [ + migrations.AddField( + model_name="post", + name="is_static_page", + field=models.BooleanField( + default=False, + help_text="is this a post for a page with static URL (e.g. `/help/delivery`)?", + verbose_name="is static page", + ), + ), + ] diff --git a/core/admin.py b/core/admin.py index 8a1c0326..209ab8e8 100644 --- a/core/admin.py +++ b/core/admin.py @@ -518,6 +518,7 @@ class VendorAdmin(FieldsetsMixin, ActivationActionsMixin, ModelAdmin): # type: "users", ] additional_fields = [ + "integration_path", "last_processing_response", "b2b_auth_token", ] diff --git a/core/migrations/0048_vendor_integration_path_alter_productimage_priority.py b/core/migrations/0048_vendor_integration_path_alter_productimage_priority.py new file mode 100644 index 00000000..4b7d4719 --- /dev/null +++ b/core/migrations/0048_vendor_integration_path_alter_productimage_priority.py @@ -0,0 +1,33 @@ +# Generated by Django 5.2 on 2025-10-21 09:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("core", "0047_alter_attribute_unique_together"), + ] + + operations = [ + migrations.AddField( + model_name="vendor", + name="integration_path", + field=models.CharField( + blank=True, + help_text="vendor's integration file path", + max_length=255, + null=True, + verbose_name="integration path", + ), + ), + migrations.AlterField( + model_name="productimage", + name="priority", + field=models.PositiveIntegerField( + default=1, + help_text="determines the order in which images are displayed", + verbose_name="display priority", + ), + ), + ] diff --git a/payments/admin.py b/payments/admin.py index 1f9e4c9c..a557b458 100644 --- a/payments/admin.py +++ b/payments/admin.py @@ -5,7 +5,7 @@ from django.http import HttpRequest from django.utils.translation import gettext_lazy as _ from core.admin import ActivationActionsMixin -from payments.forms import TransactionForm, GatewayForm +from payments.forms import GatewayForm, TransactionForm from payments.models import Balance, Transaction diff --git a/payments/migrations/0005_gateway_transaction_gateway.py b/payments/migrations/0005_gateway_transaction_gateway.py new file mode 100644 index 00000000..59d38dac --- /dev/null +++ b/payments/migrations/0005_gateway_transaction_gateway.py @@ -0,0 +1,156 @@ +# Generated by Django 5.2 on 2025-10-21 09:24 + +import django.db.models.deletion +import django_extensions.db.fields +import uuid +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("payments", "0004_alter_transaction_payment_method"), + ] + + operations = [ + migrations.CreateModel( + name="Gateway", + fields=[ + ( + "uuid", + models.UUIDField( + default=uuid.uuid4, + editable=False, + help_text="unique id is used to surely identify any database object", + primary_key=True, + serialize=False, + verbose_name="unique id", + ), + ), + ( + "is_active", + models.BooleanField( + default=True, + help_text="if set to false, this object can't be seen by users without needed permission", + verbose_name="is active", + ), + ), + ( + "created", + django_extensions.db.fields.CreationDateTimeField( + auto_now_add=True, + help_text="when the object first appeared on the database", + verbose_name="created", + ), + ), + ( + "modified", + django_extensions.db.fields.ModificationDateTimeField( + auto_now=True, + help_text="when the object was last modified", + verbose_name="modified", + ), + ), + ("name", models.CharField(max_length=20, verbose_name="name")), + ( + "default_currency", + models.CharField( + choices=[ + ("AED", "د.إ"), + ("BRL", "R$"), + ("CNY", "¥"), + ("CZK", "Kč"), + ("DKK", "kr"), + ("EUR", "€"), + ("GBP", "£"), + ("IDR", "Rp"), + ("ILS", "₪"), + ("INR", "₹"), + ("IRR", "﷼"), + ("JPY", "¥"), + ("KRW", "₩"), + ("KZT", "₸"), + ("NOK", "kr"), + ("PLN", "zł"), + ("RON", "lei"), + ("RUB", "₽"), + ("SEK", "kr"), + ("THB", "฿"), + ("TRY", "₺"), + ("USD", "$"), + ("VND", "₫"), + ], + max_length=4, + verbose_name="default currency", + ), + ), + ( + "currencies", + models.CharField( + help_text="comma separated list of currencies supported by this gateway, choose from AED, BRL, CNY, CZK, DKK, EUR, GBP, IDR, ILS, INR, IRR, JPY, KRW, KZT, NOK, PLN, RON, RUB, SEK, THB, TRY, USD, VND", + max_length=255, + verbose_name="currencies", + ), + ), + ( + "integration_path", + models.CharField(blank=True, max_length=255, null=True), + ), + ( + "minimum_transaction_amount", + models.FloatField( + default=0, verbose_name="minimum transaction amount" + ), + ), + ( + "maximum_transaction_amount", + models.FloatField( + default=0, verbose_name="maximum transaction amount" + ), + ), + ( + "daily_limit", + models.PositiveIntegerField( + default=0, + help_text="daily sum limit of transactions' amounts. 0 means no limit", + verbose_name="daily limit", + ), + ), + ( + "monthly_limit", + models.PositiveIntegerField( + default=0, + help_text="monthly sum limit of transactions' amounts. 0 means no limit", + verbose_name="monthly limit", + ), + ), + ( + "priority", + models.PositiveIntegerField( + default=10, unique=True, verbose_name="priority" + ), + ), + ( + "integration_variables", + models.JSONField( + default=dict, verbose_name="integration variables" + ), + ), + ], + options={ + "verbose_name": "payment gateway", + "verbose_name_plural": "payment gateways", + }, + ), + migrations.AddField( + model_name="transaction", + name="gateway", + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="transactions", + to="payments.gateway", + ), + ), + ]