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

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 .


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

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!

Ảnh đại diện
Huỷ bỏ
Tác giả

It worked fine. Thanks!

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

It worked fine. Thanks!

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 6 25
2940
0
thg 9 19
3234
4
thg 2 25
2308
3
thg 11 24
29947
1
thg 8 24
1959