Hi !
I basically try to invoke a function from within a Controller that does exactly what I want. But, I can't reach it, neither by importing this controller, nor by using it's route.
To use the function directly, I need an instance of this controller.
To use the route method, I tried using Requests (Python) and a simple get on the route. However, I need the session_id in the headers. And I can't retrieve that info within the Model function, where I am.
I tried with request.session_id, but I got this error:
Traceback (most recent call last):
File "/home/odoo/server/openerp/service/server.py", line 929, in preload_registries
registry = RegistryManager.new(dbname, update_module=update_module)
File "/home/odoo/server/openerp/modules/registry.py", line 370, in new
openerp.modules.load_modules(registry._db, force_demo, status, update_module)
File "/home/odoo/server/openerp/modules/loading.py", line 351, in load_modules
force, status, report, loaded_modules, update_module)
File "/home/odoo/server/openerp/modules/loading.py", line 255, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/home/odoo/server/openerp/modules/loading.py", line 176, in load_module_graph
_load_data(cr, module_name, idref, mode, kind='data')
File "/home/odoo/server/openerp/modules/loading.py", line 118, in _load_data
tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
File "/home/odoo/server/openerp/tools/convert.py", line 901, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
File "/home/odoo/server/openerp/tools/convert.py", line 987, in convert_xml_import
obj.parse(doc.getroot(), mode=mode)
File "/home/odoo/server/openerp/tools/convert.py", line 853, in parse
self._tags[rec.tag](self.cr, rec, n, mode=mode)
File "/home/odoo/server/openerp/tools/convert.py", line 379, in _tag_function
_eval_xml(self,rec, self.pool, cr, uid, self.idref, context=context)
File "/home/odoo/server/openerp/tools/convert.py", line 230, in _eval_xml
res = getattr(model, method)(cr, uid, *args)
File "/home/odoo/server/openerp/api.py", line 241, in wrapper
return old_api(self, *args, **kwargs)
File "/home/odoo/server/openerp/api.py", line 336, in old_api
result = method(recs, *args, **kwargs)
File "/home/odoo/my_addons/vimexcom/models/company.py", line 62, in set_params
headers = {'cookie': 'session_id=%s' % request.session_id}
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 336, in __getattr__
return getattr(self._get_current_object(), name)
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 295, in _get_current_object
return self.__local()
File "/usr/lib/python2.7/dist-packages/werkzeug/local.py", line 131, in _lookup
raise RuntimeError('object unbound')
ParseError: "object unbound" while parsing /home/odoo/my_addons/vimexcom/data/data.xml:10, near
<function model="res.company" name="set_params"/>
Any tips would be appreciated.
Thanks !
hope this will helps: https://learnopenerp.blogspot.com/2020/08/unbound-method-call-controller-function-from-another-controller-odoo.html