跳至內容
選單
此問題已被標幟
2 回覆
3162 瀏覽次數

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
2091
1
10月 22
2781
1
6月 25
1610
3
7月 25
3257
1
5月 25
1397