Intechnity-com / OdooJsonRpcClient

Odoo Client Json Rpc
MIT License
68 stars 29 forks source link

Odoo 15 SaleOrder Query Error #37

Closed XiSigma closed 2 years ago

XiSigma commented 2 years ago

Trying to get SaleOrders using the following:

var ordersRepository = new OdooRepository<SaleOrderOdooModel>(config);
var firstOrder =  await ordersRepository.Query().Take(1).ToListAsync(); //works fine
var secondOrder =  await ordersRepository.Query().Skip(1).Take(1).ToListAsync(); //works fine
var orders = await ordersRepository.Query().Take(2).ToListAsync(); //returns an error with the stacktrace below
Traceback (most recent call last):
  File "/odoo15/odoo15-server/odoo/api.py", line 886, in get
    return field_cache[record._ids[0]]
KeyError: 231

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/odoo15/odoo15-server/odoo/fields.py", line 1057, in __get__
    value = env.cache.get(record, self)
  File "/odoo15/odoo15-server/odoo/api.py", line 889, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'sale.order(231,).paid_amount'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/odoo15/odoo15-server/odoo/models.py", line 5193, in ensure_one
    _id, = self._ids
ValueError: too many values to unpack (expected 1)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/odoo15/odoo15-server/odoo/http.py", line 1477, in _dispatch_nodb
    result = request.dispatch()
  File "/odoo15/odoo15-server/odoo/http.py", line 688, in dispatch
    result = self._call_function(**self.params)
  File "/odoo15/odoo15-server/odoo/http.py", line 361, in _call_function
    return self.endpoint(*args, **kwargs)
  File "/odoo15/odoo15-server/odoo/http.py", line 917, in __call__
    return self.method(*args, **kw)
  File "/odoo15/odoo15-server/odoo/http.py", line 536, in response_wrap
    response = f(*args, **kw)
  File "/odoo15/odoo15-server/odoo/addons/base/controllers/rpc.py", line 101, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/odoo15/odoo15-server/odoo/http.py", line 142, in dispatch_rpc
    result = dispatch(method, params)
  File "/odoo15/odoo15-server/odoo/service/model.py", line 41, in dispatch
    res = fn(db, uid, *params)
  File "/odoo15/odoo15-server/odoo/service/model.py", line 169, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/odoo15/odoo15-server/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/odoo15/odoo15-server/odoo/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/odoo15/odoo15-server/odoo/service/model.py", line 160, in execute_cr
    result = odoo.api.call_kw(recs, method, args, kw)
  File "/odoo15/odoo15-server/odoo/api.py", line 460, in call_kw
    result = _call_kw_model(method, model, args, kwargs)
  File "/odoo15/odoo15-server/odoo/api.py", line 433, in _call_kw_model
    result = method(recs, *args, **kwargs)
  File "/odoo15/odoo15-server/odoo/models.py", line 5044, in search_read
    result = records.read(fields, **read_kwargs)
  File "/odoo15/odoo15-server/odoo/models.py", line 3227, in read
    return self._read_format(fnames=fields, load=load)
  File "/odoo15/odoo15-server/odoo/models.py", line 3247, in _read_format
    vals[name] = convert(record[name], record, use_name_get)
  File "/odoo15/odoo15-server/odoo/models.py", line 5882, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/odoo15/odoo15-server/odoo/fields.py", line 1106, in __get__
    self.compute_value(recs)
  File "/odoo15/odoo15-server/odoo/fields.py", line 1265, in compute_value
    records._compute_field_value(self)
  File "/odoo15/odoo15-server/addons/sale/models/sale_order.py", line 548, in _compute_field_value
    super()._compute_field_value(field)
  File "/odoo15/odoo15-server/addons/mail/models/mail_thread.py", line 410, in _compute_field_value
    return super()._compute_field_value(field)
  File "/odoo15/odoo15-server/odoo/models.py", line 4256, in _compute_field_value
    getattr(self, field.compute)()
  File "/odoo15/custom/addons/bi_sales_invoice_details/models/sales_invoice.py", line 47, in _compute_amount_paid
    self.paid_amount = float(self.invoiced_amount) - float(self.amount_due)
  File "/odoo15/odoo15-server/odoo/fields.py", line 1050, in __get__
    record.ensure_one()
  File "/odoo15/odoo15-server/odoo/models.py", line 5196, in ensure_one
    raise ValueError("Expected singleton: %s" % self)
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/odoo15/odoo15-server/odoo/http.py", line 644, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/odoo15/odoo15-server/odoo/http.py", line 302, in _handle_exception
    raise exception.with_traceback(None) from new_cause
ValueError: Expected singleton: sale.order(231, 230)

Any idea what might cause this? Thanks

patricoos commented 2 years ago

Hi, Please check in odoo, sale order with id 231, probably something is wrong there => odoo.exceptions.CacheMiss: 'sale.order(231,).paid_amount'

XiSigma commented 2 years ago

Hello @patricoos

var firstOrder = await ordersRepository.Query().Take(1).ToListAsync(); // this gets and 231 and it works fine

the exception only comes up when trying to get more than 1 order, and I made sure the error is not specific to a single order

patricoos commented 2 years ago

I'm not a python specialist, often errors with querying the list is when, one of the records is damaged. Have you tried it in a different environment? There is something about cache in the error message, maybe look for something about it

XiSigma commented 2 years ago

@patricoos Just tested in another environment and it works fine, the cause of this is an addon, thank you for your time

patricoos commented 2 years ago

Try use the select method on querybuilder to choose the properties you want to fetch, maybe that will help you