Odoo V13 Community
I am having issues trying to create a new contact when a web controller is called outside of Odoo. I am not sure what I am doing wrong.
Here is the web controller in Odoo:
class DuxSoup(http.Controller):
@http.route('/dux-soup/dux-soup/', auth='none', type="json", methods=["POST"], csrf=False)
def index(self, **kw):
data = json.loads(request.httprequest.data)
request.env["res.partner"].sudo().create(data)
Here is the python script which calls the Odoo endpoint:
import requests
url = "http://localhost:8069/dux-soup/dux-soup/"
objects = {"params": {"name": "value"}}
request = requests.post(url, json=objects)
print(request.text)
Here is the error which is returned in the python script:
{
"jsonrpc":"2.0",
"id":null,
"error":{
"code":200,
"message":"Odoo Server Error",
"data":{
"name":"builtins.KeyError",
"debug":"Traceback (most recent call last):\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\http.py\", line 624, in _handle_exception\n return super(JsonRequest, self)._handle_exception(exception)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\http.py\", line 310, in _handle_exception\n raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\tools\\pycompat.py\", line 14, in reraise\n raise value\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\http.py\", line 669, in dispatch\n result = self._call_function(**self.params)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\http.py\", line 350, in _call_function\n return checked_call(self.db, *args, **kwargs)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\service\\model.py\", line 94, in wrapper\n return f(dbname, *args, **kwargs)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\http.py\", line 339, in checked_call\n result = self.endpoint(*a, **kw)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\http.py\", line 915, in __call__\n return self.method(*args, **kw)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\http.py\", line 515, in response_wrap\n response = f(*args, **kw)\n File \"c:\\program files (x86)\\odoo 13.0\\addons\\dux-soup\\controllers\\controllers.py\", line 12, in index\n request.env[\"res.partner\"].sudo().create(data)\n File \"<decorator-gen-120>\", line 2, in create\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\api.py\", line 335, in _model_create_multi\n return create(self, [arg])\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\addons\\partner_autocomplete\\models\\res_partner.py\", line 183, in create\n partners = super(ResPartner, self).create(vals_list)\n File \"<decorator-gen-82>\", line 2, in create\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\api.py\", line 336, in _model_create_multi\n return create(self, arg)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\addons\\base\\models\\res_partner.py\", line 548, in create\n partners = super(Partner, self).create(vals_list)\n File \"<decorator-gen-109>\", line 2, in create\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\api.py\", line 336, in _model_create_multi\n return create(self, arg)\n File \"C:\\Program Files (x86)\\Odoo 13.0\\server\\odoo\\addons\\mail\\models\\mail_thread.py\", line 262, in create\n default_followers = self.env['mail.followers']._add_default_followers(self._name, [], self.env.user.partner_id.ids, customer_ids=[])[0][0]\nKeyError: 0\n",
"message":"0",
"arguments":[
0
],
"exception_type":"internal_error",
"context":{
}
}
}
}
Any help on this issue would be greatly appreciated as I really cannot get to the bottom of this.
Thanks,