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

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 ?


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

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']


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

you can do this

class StockPicking(models.Model):
_name = 'stock.picking'
​_inherit = ['stock.picking', 'portal.mixin']
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 11 22
2057
1
thg 10 22
2777
1
thg 6 25
1573
3
thg 7 25
3229
1
thg 5 25
1378