Add getAvailableProducts query for offers with active status
All checks were successful
Build Docker Image / build (push) Successful in 1m50s
All checks were successful
Build Docker Image / build (push) Successful in 1m50s
This commit is contained in:
@@ -38,6 +38,10 @@ class OfferType(DjangoObjectType):
|
|||||||
class PublicQuery(graphene.ObjectType):
|
class PublicQuery(graphene.ObjectType):
|
||||||
"""Public schema - no authentication required"""
|
"""Public schema - no authentication required"""
|
||||||
get_products = graphene.List(Product)
|
get_products = graphene.List(Product)
|
||||||
|
get_available_products = graphene.List(
|
||||||
|
Product,
|
||||||
|
description="Get products that have active offers"
|
||||||
|
)
|
||||||
get_supplier_profiles = graphene.List(
|
get_supplier_profiles = graphene.List(
|
||||||
SupplierProfileType,
|
SupplierProfileType,
|
||||||
country=graphene.String(),
|
country=graphene.String(),
|
||||||
@@ -74,6 +78,27 @@ class PublicQuery(graphene.ObjectType):
|
|||||||
products_data = odoo_service.get_products()
|
products_data = odoo_service.get_products()
|
||||||
return [Product(**product) for product in products_data]
|
return [Product(**product) for product in products_data]
|
||||||
|
|
||||||
|
def resolve_get_available_products(self, info):
|
||||||
|
"""Get only products that have active offers."""
|
||||||
|
# Get unique product UUIDs from active offers
|
||||||
|
product_uuids = set(
|
||||||
|
Offer.objects.filter(status='active')
|
||||||
|
.values_list('product_uuid', flat=True)
|
||||||
|
.distinct()
|
||||||
|
)
|
||||||
|
|
||||||
|
if not product_uuids:
|
||||||
|
return []
|
||||||
|
|
||||||
|
# Get all products from Odoo and filter by those with offers
|
||||||
|
odoo_service = OdooService()
|
||||||
|
products_data = odoo_service.get_products()
|
||||||
|
return [
|
||||||
|
Product(**product)
|
||||||
|
for product in products_data
|
||||||
|
if product.get('uuid') in product_uuids
|
||||||
|
]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_supplier_profiles_queryset(country=None, is_verified=None):
|
def _get_supplier_profiles_queryset(country=None, is_verified=None):
|
||||||
queryset = SupplierProfile.objects.filter(is_active=True)
|
queryset = SupplierProfile.objects.filter(is_active=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user