OCA / odoorpc

Python module to pilot your Odoo servers through JSON-RPC.
http://pythonhosted.org/OdooRPC/
GNU Lesser General Public License v3.0
234 stars 124 forks source link

When looking up stocks per location, an RPCError is thrown #51

Closed ginogervasio closed 4 years ago

ginogervasio commented 4 years ago

I get this error when I try to browse the stock.quant model on Odoo 13:

odoorpc.error.RPCError: Invalid field 'name' on model 'stock.quant'

I traced it to line 361 of models.py in the _init_values function. I noticed that the name field of stock.quant is of type odoorpc.fields.Text while others like product.product or res.partner have a name field of type odoorpc.fields.Char.

Since I needed it for a demo, I added a type check in my local machine that skips the name field in the _init_values function if it is an instance of odoorpc.fields.Text but I know this is not pythonic:

def _init_values(self, context=None):
        """Retrieve field values from the server.
        May be used to restore the original values in the purpose to cancel
        all changes made.
        """
        if context is None:
            context = self.env.context
        # Get basic fields (no relational ones)
        basic_fields = []
        for field_name in self._columns:
            if(field_name == 'name' and isinstance(self._columns['name'],
                odoorpc.fields.Text)):
                continue
            field = self._columns[field_name]
            if not getattr(field, 'relation', False):
                basic_fields.append(field_name)
        # Fetch values from the server
        if self.ids:
            rows = self.__class__.read(
                self.ids, basic_fields, context=context, load='_classic_write')
            ids_fetched = set()
            for row in rows:
                ids_fetched.add(row['id'])
                for field_name in row:
                    if field_name == 'id':
                        continue
                    self._values[field_name][row['id']] = row[field_name]
            ids_in_error = set(self.ids) - ids_fetched
            if ids_in_error:
                raise ValueError(
                    "There is no '{model}' record with IDs {ids}.".format(
                        model=self._name, ids=list(ids_in_error)))
        # No ID: fields filled with default values
        else:
            default_get = self.__class__.default_get(
                list(self._columns), context=context)
            for field_name in self._columns:
                self._values[field_name][None] = default_get.get(
                    field_name, False)
JulienCochuyt commented 4 years ago

Same error here when attempting to browse mail.message on Odoo 13.

sebalix commented 4 years ago

Hello there. I found why this issue is raised, I badly written this part of the code: https://github.com/OCA/odoorpc/blob/master/odoorpc/env.py#L338-L342 It should be display_name instead of name. I checked and it was already like that in Odoo 8.0: https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L522 I will fix it soon.

sebalix commented 4 years ago

@ginogervasio @JulienCochuyt try to update OdooRPC from the master branch, the fix has been merged. The release will come later.

JulienCochuyt commented 4 years ago

@sebalix, thanks for the fix. I can confirm the issue can no longer be reproduced on our side when using the latest master. Would you yet have a schedule for the next release to be pushed to PyPi?