Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
3048 Lượt xem

What would be causing this error? The override code does not do anything but print values. When I comment it out, it works fine. Anyone got any clues??

@api.model
def create(self, vals):
print("CREATE....", vals)
super(ResPartner, self).create(vals)


Here is the error:

Traceback (most recent call last):
  File "/opt/odoosrc/16.0/odoo/odoo/models.py", line 5739, in concat
    if arg._name != self._name:
AttributeError: 'NoneType' object has no attribute '_name'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/odoosrc/16.0/odoo/odoo/http.py", line 1584, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/opt/odoosrc/16.0/odoo/odoo/service/model.py", line 134, in retrying
    result = func()
  File "/opt/odoosrc/16.0/odoo/odoo/http.py", line 1611, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/opt/odoosrc/16.0/odoo/odoo/http.py", line 1808, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/opt/odoosrc/16.0/odoo/odoo/addons/base/models/ir_http.py", line 149, in _dispatch
    result = endpoint(**request.params)
  File "/opt/odoosrc/16.0/odoo/odoo/http.py", line 699, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/opt/odoosrc/16.0/odoo/addons/web/controllers/dataset.py", line 42, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoosrc/16.0/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoosrc/16.0/odoo/odoo/api.py", line 459, in call_kw
    result = _call_kw_model_create(method, model, args, kwargs)
  File "/opt/odoosrc/16.0/odoo/odoo/api.py", line 439, in _call_kw_model_create
    result = method(recs, *args, **kwargs)
  File "", line 2, in create
  File "/opt/odoosrc/16.0/odoo/odoo/api.py", line 409, in _model_create_multi
    return create(self, [arg])
  File "/opt/odoosrc/16.0/odoo/addons/account/models/partner.py", line 625, in create
    return super().create(vals_list)
  File "", line 2, in create
  File "/opt/odoosrc/16.0/odoo/odoo/api.py", line 410, in _model_create_multi
    return create(self, arg)
  File "/opt/odoosrc/16.0/odoo/addons/partner_autocomplete/models/res_partner.py", line 163, in create
    partners = super(ResPartner, self).create(vals_list)
  File "", line 2, in create
  File "/opt/odoosrc/16.0/odoo/odoo/api.py", line 390, in _model_create_single
    return self.browse().concat(*(create(self, vals) for vals in arg))
  File "/opt/odoosrc/16.0/odoo/odoo/models.py", line 5743, in concat
    raise TypeError(f"unsupported operand types in: {self} + {arg!r}")
TypeError: unsupported operand types in: res.partner() + None

The above server error caused the following client error:
null


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You can try one of the below codes, and make sure to restart the Odoo service and upgrade your module after "Update App Lists"


Note: Both codes are tested in Odoo 16 and working properly.


from odoo import models, api

class ResPartner(models.Model):
_inherit = 'res.partner'

@api.model
def create(self, vals):
print("CREATE....", vals)
return super().create(vals)

   from odoo import models, api

class ResPartner(models.Model):
_inherit = 'res.partner'

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
print("CREATE..", %vals)
return super().create(vals_list)


   
Ảnh đại diện
Huỷ bỏ
Tác giả

Awesome! that worked!
I still don't understand why the original one did not work but I am very grateful that this one did. Thank you Waleed.

Câu trả lời hay nhất

Hi,

Try this Code snippet

class ResPartnerInherit(models.Model):
_inherit='res.partner'

@api.model
def create(self, vals):
print("CREATE....", vals)
return super(ResPartnerInherit, self).create(vals)

Regards

Ảnh đại diện
Huỷ bỏ
Tác giả

Thank you but same error unfortunately.

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 5 25
1513
1
thg 3 25
1652
MERGING CONTACTS Đã xử lý
1
thg 2 25
3932
Use of external id Đã xử lý
2
thg 2 25
3132
2
thg 2 25
2349