payment modeli yaratildi
This commit is contained in:
1
core/apps/payment/models/__init__.py
Normal file
1
core/apps/payment/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .payment import * # noqa
|
||||
69
core/apps/payment/models/payment.py
Normal file
69
core/apps/payment/models/payment.py
Normal file
@@ -0,0 +1,69 @@
|
||||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_core.models import AbstractBaseModel
|
||||
from model_bakery import baker
|
||||
|
||||
from core.apps.payment.enums.payment import PaymentMethod, PaymentStatus
|
||||
|
||||
|
||||
class PaymentModel(AbstractBaseModel):
|
||||
valuation = models.ForeignKey(
|
||||
"evaluation.ValuationModel",
|
||||
on_delete=models.CASCADE,
|
||||
related_name="payments",
|
||||
verbose_name=_("valuation"),
|
||||
)
|
||||
payer = models.ForeignKey(
|
||||
"accounts.User",
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="payments",
|
||||
verbose_name=_("payer"),
|
||||
)
|
||||
amount = models.DecimalField(
|
||||
verbose_name=_("amount"),
|
||||
max_digits=15,
|
||||
decimal_places=2,
|
||||
)
|
||||
payment_method = models.CharField(
|
||||
verbose_name=_("payment method"),
|
||||
max_length=50,
|
||||
choices=PaymentMethod.choices,
|
||||
default=PaymentMethod.CASH,
|
||||
)
|
||||
status = models.CharField(
|
||||
verbose_name=_("status"),
|
||||
max_length=50,
|
||||
choices=PaymentStatus.choices,
|
||||
default=PaymentStatus.PENDING,
|
||||
)
|
||||
transaction_id = models.CharField(
|
||||
verbose_name=_("transaction ID"),
|
||||
max_length=255,
|
||||
blank=True,
|
||||
null=True,
|
||||
unique=True,
|
||||
)
|
||||
paid_at = models.DateTimeField(
|
||||
verbose_name=_("paid at"),
|
||||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
note = models.TextField(
|
||||
verbose_name=_("note"),
|
||||
blank=True,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Payment #{self.pk} — {self.amount} ({self.get_status_display()})"
|
||||
|
||||
@classmethod
|
||||
def _baker(cls):
|
||||
return baker.make(cls)
|
||||
|
||||
class Meta:
|
||||
db_table = "Payment"
|
||||
verbose_name = _("Payment")
|
||||
verbose_name_plural = _("Payments")
|
||||
ordering = ["-created_at"]
|
||||
Reference in New Issue
Block a user