From 7cc22aa0a1addf5c49be1804283121a7a21faf0a Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Sun, 14 Jul 2024 18:12:14 +0200 Subject: [PATCH] WIP: Changes to payment models --- .pre-commit-config.yaml | 2 +- src/accounting/models.py | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fc9fe36..8e7157d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3.12 + python: python3 exclude: ^.*\b(migrations)\b.*$ repos: - repo: https://github.com/pre-commit/pre-commit-hooks diff --git a/src/accounting/models.py b/src/accounting/models.py index 9db46eb..f529a0c 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -98,19 +98,23 @@ class Payment(CreatedModifiedAbstract): description = models.CharField(max_length=1024, verbose_name=_("description")) - stripe_charge_id = models.CharField(max_length=255, null=True, blank=True) + payment_type = models.ForeignKey("PaymentType", on_delete=models.PROTECT) + external_transaction_id = models.CharField(max_length=255, null=True, blank=True) + + # stripe_charge_id = models.CharField(max_length=255, null=True, blank=True) @property def display_id(self): return str(self.id).zfill(6) @classmethod - def from_order(cls, order): + def from_order(cls, order, payment_type): return cls.objects.create( order=order, user=order.user, amount=order.total, description=order.description, + payment_type=payment_type, ) def __str__(self) -> str: @@ -119,3 +123,18 @@ class Payment(CreatedModifiedAbstract): class Meta: verbose_name = _("payment") verbose_name_plural = _("payments") + + +class PaymentType(CreatedModifiedAbstract): + """Types of payments available in the system: + - bank transfer + - card payment (specific provider) + """ + + name = models.CharField(max_length=1024, verbose_name=_("description")) + description = models.TextField(max_length=2048, null=True, blank=True) + + enabled = models.BooleanField(default=True) + + def __str__(self) -> str: + return f"{self.name}"