Closed yajo closed 1 year ago
All attended
Merging, I'll cancel the jobs for now as I'm fixing them. Need to migrate to GH actions too later!
Doctest was failing because of this new close
attribute. I can't figure out why but I fixed it by creating a well defined close
method here: https://github.com/OCA/odoorpc/pull/84/commits/6b10bab1ce1de5d4ab432031bccbc9c241f63dd6
The traceback of the doctest:
Document: ref_odoo
------------------
**********************************************************************
File "../../odoorpc/odoo.py", line ?, in default
Failed example:
Partner = odoo.env['res.partner']
Exception raised:
Traceback (most recent call last):
File "/usr/lib/python3.8/doctest.py", line 1336, in __run
exec(compile(example.source, filename, "single",
File "<doctest default[0]>", line 1, in <module>
Partner = odoo.env['res.partner']
File "/home/salix/dev/OCA/odoorpc/odoorpc/odoo.py", line 197, in env
self._check_logged_user()
File "/home/salix/dev/OCA/odoorpc/odoorpc/odoo.py", line 319, in _check_logged_user
raise error.InternalError("Login required")
odoorpc.error.InternalError: Login required
The simplest possible way to implement an automatic logout with a context manager is to rely on
contextlib.closing
. The only requirement is to have aclose
function. In this case, just an alias forlogout
.With this patch, we're able now to wrap the logged-in odoo instance with that function and get automatic logout.
See the provided test for usage example.