feat: expose public offers with location data
This commit is contained in:
@@ -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):
|
||||
|
||||
28
webapp/graphql/operations/public/exchange/GetOffers.graphql
Normal file
28
webapp/graphql/operations/public/exchange/GetOffers.graphql
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user