yezyilomo / odoo-rest-api

Module which expose Odoo as a REST API
MIT License
209 stars 169 forks source link

Wildcard (*) and exclude operators not working #43

Closed intoku closed 4 years ago

intoku commented 4 years ago

Hi, first of thank you for making this awesome plugin!

When listing the the invoices (drafts and completed) on https://mydomain.com/api/account.move

The request with defined parameters query={id, name}, works great, the response is ok. The request with added filter &filter=["id", "=", 15] works - but only for some id's;

And when requesting the wildcard {*}, or {-name} is not working in any combination, also when trying other models.

Here is part of the odoo error log:

` File "/opt/odoo/new_addons/odoo-rest-api/controllers/controllers.py", line 170, in get_model_data data = serializer.data File "/opt/odoo/new_addons/odoo-rest-api/controllers/serializers.py", line 35, in data in self._record File "/opt/odoo/new_addons/odoo-rest-api/controllers/serializers.py", line 34, in for rec File "/opt/odoo/new_addons/odoo-rest-api/controllers/serializers.py", line 145, in serialize flat_field = cls.build_flat_field(rec, field) File "/opt/odoo/new_addons/odoo-rest-api/controllers/serializers.py", line 65, in build_flat_field return {field_name: rec[field_name].decode("utf-8")}

AttributeError: 'list' object has no attribute 'decode' - - -`

intoku commented 4 years ago

Furthermore i tried to erase the .decode("utf-8") from serializers.py. In this case the wildcard selector {*} works and {-name} also works.

I'm not sure if this change is having some other implications on the whole application

yezyilomo commented 4 years ago

That's not {*} or {-name} problem, what causes that is sometimes Odoo declare a field as binary but the way it's stored is not in binary form, .decode("utf-8") you see there is for decoding data stored in binary form(e.g images) so you should not remove it because you will be getting error when actual binary data are encountered, the solution is to check if the field value is really binary before calling .decode("utf-8") on it.