Features: 1) Add personal_orders_only field to GraphQL schema for Product; 2) Implement personal_orders_only property in Product model; 3) Include personal_orders_only in simple serializer;

Fixes: None;

Extra: 1) Remove redundant `stocks__isnull=False` filter from views and schema queries; 2) Minor formatting adjustments;
This commit is contained in:
Egor Pavlovich Gorbunov 2025-07-26 14:48:21 +03:00
parent decd166126
commit 954e02385c
5 changed files with 12 additions and 2 deletions

View file

@ -378,6 +378,7 @@ class ProductType(DjangoObjectType):
price = Float(description=_("price"))
quantity = Float(description=_("quantity"))
feedbacks_count = Int(description=_("number of feedbacks"))
personal_orders_only = Boolean(description=_("only available for personal orders"))
class Meta:
model = Product
@ -416,6 +417,9 @@ class ProductType(DjangoObjectType):
def resolve_quantity(self: Product, _info) -> int:
return self.quantity or 0
def resolve_personal_orders_only(self: Product, _info) -> bool:
return False or self.personal_orders_only
class AttributeValueType(DjangoObjectType):
value = String(description=_("attribute value"))

View file

@ -155,7 +155,6 @@ class Query(ObjectType):
is_active=True,
brand__is_active=True,
category__is_active=True,
stocks__isnull=False,
stocks__vendor__is_active=True,
)
.select_related("brand", "category")

View file

@ -717,6 +717,10 @@ class Product(ExportModelOperationsMixin("product"), NiceModel): # type: ignore
status__in=["FINISHED", "DELIVERING", "CREATED", "PAYMENT"],
).count()
@property
def personal_orders_only(self) -> bool:
return not self.quantity > 0 and self.price > 0.0
class Attribute(ExportModelOperationsMixin("attribute"), NiceModel): # type: ignore [misc, django-manager-missing]
"""

View file

@ -156,6 +156,7 @@ class ProductSimpleSerializer(ModelSerializer):
price = SerializerMethodField()
quantity = SerializerMethodField()
feedbacks_count = SerializerMethodField()
personal_orders_only = SerializerMethodField()
class Meta:
model = Product
@ -189,6 +190,9 @@ class ProductSimpleSerializer(ModelSerializer):
def get_quantity(self, obj: Product) -> int:
return obj.quantity
def get_personal_orders_only(self, obj: Product) -> bool:
return obj.personal_orders_only
class VendorSimpleSerializer(ModelSerializer):
class Meta:

View file

@ -365,7 +365,6 @@ class ProductViewSet(EvibesViewSet):
is_active=True,
brand__is_active=True,
category__is_active=True,
stocks__isnull=False,
stocks__vendor__is_active=True,
)