Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3200 มุมมอง

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']
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
พ.ย. 22
2121
delete the value of the taxes_id field แก้ไขแล้ว
1
ต.ค. 22
2800
1
มิ.ย. 25
1690
3
ก.ค. 25
3318
1
พ.ค. 25
1456