コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
713 ビュー

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 .


アバター
破棄
最善の回答

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!

アバター
破棄
著作者

It worked fine. Thanks!

最善の回答

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.

アバター
破棄
著作者

It worked fine. Thanks!

関連投稿 返信 ビュー 活動
2
6月 25
2940
0
9月 19
3234
4
2月 25
2308
3
11月 24
29947
1
8月 24
1959