feat: expose public offers with location data

This commit is contained in:
Ruslan Bakiev
2025-12-08 18:36:32 +07:00
parent 3ae39251c8
commit fd05838c4d
2 changed files with 48 additions and 0 deletions

View File

@@ -39,6 +39,10 @@ class OfferLineType(DjangoObjectType):
class OfferType(DjangoObjectType):
lines = graphene.List(OfferLineType)
location_latitude = graphene.Float()
location_longitude = graphene.Float()
location_country = graphene.String()
location_country_code = graphene.String()
class Meta:
model = Offer
@@ -103,6 +107,22 @@ class PublicQuery(graphene.ObjectType):
queryset = queryset.filter(lines__product_uuid=product_uuid).distinct()
if category_name:
queryset = queryset.filter(lines__category_name__icontains=category_name).distinct()
# Enrich offers with location metadata from Odoo logistics nodes
nodes_map = {}
try:
odoo_service = OdooService()
nodes = odoo_service.get_logistics_nodes()
nodes_map = {str(node.get('uuid')): node for node in nodes}
except Exception:
nodes_map = {}
for offer in queryset:
node = nodes_map.get(str(offer.location_uuid)) if offer.location_uuid else None
if node:
offer.location_latitude = node.get('latitude')
offer.location_longitude = node.get('longitude')
offer.location_country = node.get('country')
offer.location_country_code = node.get('country_code')
return queryset
def resolve_get_offer(self, info, uuid):

View File

@@ -0,0 +1,28 @@
query GetOffers($status: String, $productUuid: String, $locationUuid: String, $categoryName: String) {
getOffers(status: $status, productUuid: $productUuid, locationUuid: $locationUuid, categoryName: $categoryName) {
uuid
teamUuid
title
description
status
locationUuid
locationName
locationCountry
locationCountryCode
locationLatitude
locationLongitude
validUntil
createdAt
updatedAt
lines {
uuid
productUuid
productName
categoryName
quantity
unit
pricePerUnit
currency
}
}
}