跳至内容
菜单
此问题已终结
2 回复
3156 查看

I want to add 'portal.mixin' to an existing odoo model 'stock.picking' in my custom module


I thought this would do the trick:

class StockPicking(models.Model):    
​_inherit = ['stock.picking', 'portal.mixin']

But i get this stack trace:

Traceback (most recent call last):
  File "/opt/odoo15/odoo/odoo/service/server.py", line 1260, in preload_registries
    registry = Registry.new(dbname, update_module=update_module)
  File "/opt/odoo15/odoo/odoo/modules/registry.py", line 87, in new
    odoo.modules.load_modules(registry, force_demo, status, update_module)
  File "/opt/odoo15/odoo/odoo/modules/loading.py", line 470, in load_modules
    processed_modules += load_marked_modules(cr, graph,
  File "/opt/odoo15/odoo/odoo/modules/loading.py", line 363, in load_marked_modules
    loaded, processed = load_module_graph(
  File "/opt/odoo15/odoo/odoo/modules/loading.py", line 199, in load_module_graph
    registry.init_models(cr, model_names, {'module': package.name}, new_install)
  File "/opt/odoo15/odoo/odoo/modules/registry.py", line 428, in init_models
    model._auto_init()
  File "/opt/odoo15/odoo/odoo/models.py", line 2795, in _auto_init
    raise_on_invalid_object_name(self._name)
  File "/opt/odoo15/odoo/odoo/models.py", line 104, in raise_on_invalid_object_name
    raise ValueError(msg)
ValueError: The _name attribute StockPicking is not valid.

What am I doing wrong ?


形象
丢弃
最佳答案

I think that's because to use mixins you need to define the model not just inheriting. I think you could jus overwrite the already existing module 'stock.picking' with the same name and that'll work, try:

class StockPicking(models.Model):
​_name = 'stock.picking'   
​_inherit = ['stock.picking', 'portal.mixin']


形象
丢弃
最佳答案

you can do this

class StockPicking(models.Model):
_name = 'stock.picking'
​_inherit = ['stock.picking', 'portal.mixin']
形象
丢弃
相关帖文 回复 查看 活动
1
11月 22
2083
1
10月 22
2780
1
6月 25
1605
3
7月 25
3254
1
5月 25
1393