Skip to Content
Menu
This question has been flagged
2 Replies
503 Views

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
Discard
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
Discard
Author

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
Discard
Author

It worked fine. Thanks!

Related Posts Replies Views Activity
2
Jun 25
2773
0
Sep 19
3120
4
Feb 25
1987
3
Nov 24
29556
1
Aug 24
1823