Features: 1) Simplify save method by removing validation logic tied to config.

Fixes: 1) Remove unused import for `constance.config`.

Extra: 1) Minor cleanup in `save` method for improved readability.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-11-12 13:14:53 +03:00
parent 3a5fa3c72b
commit d91a979e25

View file

@ -1,6 +1,5 @@
from datetime import datetime, time from datetime import datetime, time
from constance import config
from django.conf import settings from django.conf import settings
from django.contrib.postgres.indexes import GinIndex from django.contrib.postgres.indexes import GinIndex
from django.db.models import ( from django.db.models import (
@ -48,17 +47,10 @@ class Transaction(NiceModel):
) )
def save(self, **kwargs): def save(self, **kwargs):
if self.amount != 0.0 and ( if len(str(self.amount).split(".")[1]) > 2:
(config.PAYMENT_GATEWAY_MINIMUM <= self.amount <= config.PAYMENT_GATEWAY_MAXIMUM)
or (config.PAYMENT_GATEWAY_MINIMUM == 0 and config.PAYMENT_GATEWAY_MAXIMUM == 0)
):
if len(str(self.amount).split(".")[1]) > 2:
self.amount = round(self.amount, 2) self.amount = round(self.amount, 2)
super().save(**kwargs) super().save(**kwargs)
return self return self
raise ValueError(
_(f"transaction amount must fit into {config.PAYMENT_GATEWAY_MINIMUM}-{config.PAYMENT_GATEWAY_MAXIMUM}")
)
class Meta: class Meta:
verbose_name = _("transaction") verbose_name = _("transaction")