Skip to Content
Menú
This question has been flagged
2 Respostes
550 Vistes

Hello!

I am trying to create my first custom app in Odoo. The app name is 'fabrica3' with a model below:

class MRPWorkorder(models.Model):​
​_name = 'fabrica3.mrpworkorder'
​_inherit = 'mrp.workorder'

​employee = fields.Many2one('hr.employee')
​name = fields.Char(compute='_get_name', store=True)

But when I try to activate this app I receive the message

TypeError: Many2many fields fabrica3.mrpworkorder.blocked_by_workorder_ids and mrp.workorder.blocked_by_workorder_ids use the same table and columns

But I dont use the field blocked_by_workorder_id.

I am using v18.

Can anyone help me .


Avatar
Descartar
Best Answer

Hello,

Use only _inherit,

  • Remove the _name attribute and just extend the existing model. This is the most common approach when you just want to add fields to an existing model.

    When you use both _name and _inherit, Odoo creates a new model that tries to use the same table names as the original model.

  • Many2many fields automatically generate table names based on the model names, causing conflicts.

    Hope this helps!

Avatar
Descartar
Autor

It worked fine. Thanks!

Best Answer

Hi,


Remove _name = 'fabrica3.mrpworkorder' from your model

Keep only _inherit = 'mrp.workorder'

This way, you're extending the existing mrp.workorder model

The error happens because defining a new model with _name reuses internal Many2many fields incorrectly

Only use _name if you're creating a completely new model (not needed here)

After removing _name, your model will load without the Many2many field conflict



Hope it helps.

Avatar
Descartar
Autor

It worked fine. Thanks!

Related Posts Respostes Vistes Activitat
2
de juny 25
2801
0
de set. 19
3147
4
de febr. 25
2050
3
de nov. 24
29649
1
d’ag. 24
1870