Features: 1) Add feedback field to OrderProduct type; 2) Introduce resolution logic for feedback in OrderProduct; 3) Extend allowed statuses for feedback creation to include FAILED;

Fixes: 1) Reorder imports in `core/utils` and `core/utils/seo_builders` sections; 2) Correct misplaced `Boolean` import in `object_types.py`;

Extra: 1) Update GraphQL schema descriptions for new and existing fields; 2) Minor reformatting of imports for consistency.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-09-18 14:26:56 +03:00
parent dea219f974
commit 17a2b01894
2 changed files with 11 additions and 6 deletions

View file

@ -7,6 +7,7 @@ from django.db.models.functions import Length
from django.utils.translation import gettext_lazy as _
from graphene import (
UUID,
Boolean,
Field,
Float,
InputObjectType,
@ -16,7 +17,6 @@ from graphene import (
ObjectType,
String,
relay,
Boolean,
)
from graphene.types.generic import GenericScalar
from graphene_django import DjangoObjectType
@ -44,15 +44,15 @@ from core.models import (
Vendor,
Wishlist,
)
from core.utils import graphene_current_lang, graphene_abs
from core.utils import graphene_abs, graphene_current_lang
from core.utils.seo_builders import (
org_schema,
breadcrumb_schema,
brand_schema,
website_schema,
breadcrumb_schema,
category_schema,
item_list_schema,
org_schema,
product_schema,
website_schema,
)
from payments.graphene.object_types import TransactionType
from payments.models import Transaction
@ -397,6 +397,7 @@ class OrderProductType(DjangoObjectType):
attributes = GenericScalar(description=_("attributes"))
notifications = GenericScalar(description=_("notifications"))
download_url = String(description=_("download url for this order product if applicable"))
feedback = Field(lambda: FeedbackType, description=_("feedback"))
class Meta:
model = OrderProduct
@ -409,10 +410,14 @@ class OrderProductType(DjangoObjectType):
"comments",
"attributes",
"notifications",
"feedback",
)
filter_fields = ["uuid"]
description = _("order products")
def resolve_feedback(self: OrderProduct, _info):
return self.feedback
def resolve_attributes(self, _info):
return camelize(self.attributes)

View file

@ -1953,7 +1953,7 @@ class OrderProduct(ExportModelOperationsMixin("order_product"), NiceModel): # t
self.feedback.delete()
return None
if action == "add" and not self.feedback:
if self.order.status not in ["MOMENTAL", "PENDING"]:
if self.order.status not in ["MOMENTAL", "PENDING", "FAILED"]:
return Feedback.objects.create(rating=rating, comment=comment, order_product=self)
else:
raise ValueError(_("you cannot feedback an order which is not received"))