0
votes

I have created Sale Order with some line items.

  1. Create many SO with at lest 3 lines with non-admin user (But manager level user)
  2. Next day, tried to delete first line of the SO with non-admin user
  3. Once press Save, it gives error.
User #7 deleted sale.order.line records with IDs: [367]
ERROR db_name odoo.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 947, in __get__
    value = record.env.cache.get(record, self)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 960, in get
    value = self._data[field][record.id][key]
KeyError: (<odoo.sql_db.Cursor object at 0x7f44b8cc20b8>, 7)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 646, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 307, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 683, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 332, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 927, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/http.py", line 512, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 930, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/usr/lib/python3/dist-ackages/odoo/addons/web/controllers/main.py" line 922, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 689, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 680, in call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/odoo/addons/sale/sale.py", line 1285, in write
    result = super(SaleOrder, self).write(vals)
  File "/usr/lib/python3/dist-packages/odoo/addons/mail/models/mail_thread.py", line 277, in write
    result = super(MailThread, self).write(values)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3008, in write
    self._write(old_vals)
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 3223, in _write
    self.recompute()
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4801, in recompute
    vals = {n: rec[n] for n in ns}
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4801, in <dictcomp>
    vals = {n: rec[n] for n in ns}
  File "/usr/lib/python3/dist-packages/odoo/models.py", line 4659, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/usr/lib/python3/dist-packages/odoo/fields.py", line 954, in __get__
    value = record.env.cache.get(record, self)
  File "/usr/lib/python3/dist-packages/odoo/api.py", line 960, in get
    value = self._data[field][record.id][key]
KeyError: (<odoo.sql_db.Cursor object at 0x7f44b8cc20b8>, 7)

Please suggest the solution as the other non admin user should be able to edit the order line items. They can not ask all the time the Administrator to do so.

1
Initially check rights weather this user is rights to delete. If yes then try to delete by cancelling SO.Keval Mehta
Do you have customization installed? If so, there probably was made a mistake. I don't know of such errors in Odoo core codebase. It is obviously no access problem.CZoellner
Yes there are some custom module installed but I checked everything correct the user created has also right to create, edit, delete. The problem is only for to delete the first line item. Does odoo v11 have any sequence relation ? I found an issue raised in GitHub github.com/odoo/odoo/issues/23354Lekha

1 Answers

0
votes

You can solve it with the following code.

@api.multi
def unlink(self):
    if 'unlink_so_line' in self.env.context:
        return super(sale_order_line, self).unlink()
    else:
        self.env.context = dict(self.env.context)
        self.env.context.update({'unlink_so_line': True})
        return super(sale_order_line, self).sudo().unlink()

When you only unlink with sudo(), the unlink goes into a look, and you will get an error message that the maximum recursion depth is exceeded.