vuestorefront-community / odoo

https://docs.vuestorefront.io/odoo/
MIT License
66 stars 26 forks source link

How can I add "image" field to the graph API? #37

Closed caalvinz closed 1 year ago

caalvinz commented 2 years ago

What is your question / Please describe your issue

I want to list the categories with image on the front end. The current graph API doesn't return image field.

I tried expend the fields on the file "schemas/objects.py" with the following codes:

# line 198
class Category(OdooObjectType):
    # ....
    image = graphene.String()
    small_image = graphene.String()
    thumbnail = graphene.String()

    def resolve_id(self, info):
        return self.id or None

    def resolve_image(self, info):
        if self.image_1920:
            return '/web/image/category.image/{}/image_1920'.format(self.id)
        return None

    def resolve_small_image(self, info):
        if self.image_1920:
            return '/web/image/{}/{}/image_128'.format(self._name, self.id)
        return None

    def resolve_thumbnail(self, info):
        if self.image_1920:
            return '/web/image/{}/{}/image_512'.format(self._name, self.id)
        return None

And upgraded the module on odoo. The new fields didn't show up on the API.

image

Is there anybody can help? Thanks.

What version of odoo integration are you using?

15.0

Code of Conduct

odranoelBR commented 1 year ago

Please @caalvinz report on https://github.com/odoogap/vuestorefront We really don't use category images by default, but for sure, it's doable / customisable.

After return them in the api, we must update query our create a custom query. Tks