From 91ed79669bc4b6ae29f0833ca66dee0b17b05d5e Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Wed, 1 Oct 2025 16:47:01 +0300 Subject: [PATCH] Features: 1) Enhance `__str__` in `payments.models.Transaction` to handle cases where `balance` is missing. Fixes: 1) Adjust feedback creation logic in `core.models` to ensure it is only allowed when `order.status` is `FINISHED`. Extra: 1) Minor formatting adjustment in `payments.models.Transaction` for improved readability. --- core/models.py | 2 +- payments/models.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/models.py b/core/models.py index 8924c846..9817d7a3 100644 --- a/core/models.py +++ b/core/models.py @@ -1794,7 +1794,7 @@ class OrderProduct(ExportModelOperationsMixin("order_product"), NiceModel): # t if action == "add": if not feedback_exists: - if self.order.status not in ["MOMENTAL", "PENDING", "FAILED"]: + if self.order.status == "FINISHED": return Feedback.objects.create(rating=rating, comment=comment, order_product=self) else: raise ValueError(_("you cannot feedback an order which is not received")) diff --git a/payments/models.py b/payments/models.py index 6678715b..38b4cb16 100644 --- a/payments/models.py +++ b/payments/models.py @@ -22,7 +22,8 @@ class Transaction(NiceModel): process = JSONField(verbose_name=_("processing details"), default=dict) def __str__(self): - return f"{self.balance.user.email} | {self.amount}" + return f"{self.balance.user.email} | {self.amount}" if self.balance else\ + f"{self.order.attributes.get("customer_email")} | {self.amount}" def save(self, **kwargs): if self.amount != 0.0 and (