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:
parent
dea219f974
commit
17a2b01894
2 changed files with 11 additions and 6 deletions
|
|
@ -7,6 +7,7 @@ from django.db.models.functions import Length
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from graphene import (
|
from graphene import (
|
||||||
UUID,
|
UUID,
|
||||||
|
Boolean,
|
||||||
Field,
|
Field,
|
||||||
Float,
|
Float,
|
||||||
InputObjectType,
|
InputObjectType,
|
||||||
|
|
@ -16,7 +17,6 @@ from graphene import (
|
||||||
ObjectType,
|
ObjectType,
|
||||||
String,
|
String,
|
||||||
relay,
|
relay,
|
||||||
Boolean,
|
|
||||||
)
|
)
|
||||||
from graphene.types.generic import GenericScalar
|
from graphene.types.generic import GenericScalar
|
||||||
from graphene_django import DjangoObjectType
|
from graphene_django import DjangoObjectType
|
||||||
|
|
@ -44,15 +44,15 @@ from core.models import (
|
||||||
Vendor,
|
Vendor,
|
||||||
Wishlist,
|
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 (
|
from core.utils.seo_builders import (
|
||||||
org_schema,
|
|
||||||
breadcrumb_schema,
|
|
||||||
brand_schema,
|
brand_schema,
|
||||||
website_schema,
|
breadcrumb_schema,
|
||||||
category_schema,
|
category_schema,
|
||||||
item_list_schema,
|
item_list_schema,
|
||||||
|
org_schema,
|
||||||
product_schema,
|
product_schema,
|
||||||
|
website_schema,
|
||||||
)
|
)
|
||||||
from payments.graphene.object_types import TransactionType
|
from payments.graphene.object_types import TransactionType
|
||||||
from payments.models import Transaction
|
from payments.models import Transaction
|
||||||
|
|
@ -397,6 +397,7 @@ class OrderProductType(DjangoObjectType):
|
||||||
attributes = GenericScalar(description=_("attributes"))
|
attributes = GenericScalar(description=_("attributes"))
|
||||||
notifications = GenericScalar(description=_("notifications"))
|
notifications = GenericScalar(description=_("notifications"))
|
||||||
download_url = String(description=_("download url for this order product if applicable"))
|
download_url = String(description=_("download url for this order product if applicable"))
|
||||||
|
feedback = Field(lambda: FeedbackType, description=_("feedback"))
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = OrderProduct
|
model = OrderProduct
|
||||||
|
|
@ -409,10 +410,14 @@ class OrderProductType(DjangoObjectType):
|
||||||
"comments",
|
"comments",
|
||||||
"attributes",
|
"attributes",
|
||||||
"notifications",
|
"notifications",
|
||||||
|
"feedback",
|
||||||
)
|
)
|
||||||
filter_fields = ["uuid"]
|
filter_fields = ["uuid"]
|
||||||
description = _("order products")
|
description = _("order products")
|
||||||
|
|
||||||
|
def resolve_feedback(self: OrderProduct, _info):
|
||||||
|
return self.feedback
|
||||||
|
|
||||||
def resolve_attributes(self, _info):
|
def resolve_attributes(self, _info):
|
||||||
return camelize(self.attributes)
|
return camelize(self.attributes)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1953,7 +1953,7 @@ class OrderProduct(ExportModelOperationsMixin("order_product"), NiceModel): # t
|
||||||
self.feedback.delete()
|
self.feedback.delete()
|
||||||
return None
|
return None
|
||||||
if action == "add" and not self.feedback:
|
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)
|
return Feedback.objects.create(rating=rating, comment=comment, order_product=self)
|
||||||
else:
|
else:
|
||||||
raise ValueError(_("you cannot feedback an order which is not received"))
|
raise ValueError(_("you cannot feedback an order which is not received"))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue