From 954e02385c54e4f3f1a0bd4670a39d95f07caa5d Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Sat, 26 Jul 2025 14:48:21 +0300 Subject: [PATCH] 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; --- core/graphene/object_types.py | 4 ++++ core/graphene/schema.py | 1 - core/models.py | 4 ++++ core/serializers/simple.py | 4 ++++ core/viewsets.py | 1 - 5 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/graphene/object_types.py b/core/graphene/object_types.py index 23ff8cd9..28f0fb42 100644 --- a/core/graphene/object_types.py +++ b/core/graphene/object_types.py @@ -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")) diff --git a/core/graphene/schema.py b/core/graphene/schema.py index 046f695d..f7f6eab8 100644 --- a/core/graphene/schema.py +++ b/core/graphene/schema.py @@ -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") diff --git a/core/models.py b/core/models.py index 3ca35c92..cd16dd9b 100644 --- a/core/models.py +++ b/core/models.py @@ -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] """ diff --git a/core/serializers/simple.py b/core/serializers/simple.py index 072f3792..6c7a2f30 100644 --- a/core/serializers/simple.py +++ b/core/serializers/simple.py @@ -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: diff --git a/core/viewsets.py b/core/viewsets.py index 2db093ae..aafad707 100644 --- a/core/viewsets.py +++ b/core/viewsets.py @@ -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, )