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

I'm trying to create a fields in res.partner(odoo16) but the error occurs
the code:

from odoo import fields, models, api, _

class ResPartner(models.Model):
_name="res.partner"
_inherit = "res.partner"
x=fields.Char("my field name")

the error:
psycopg2.errors.UndefinedColumn: column res_partner.x does not exist

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

Hi,

You can refer the following blog.

https://www.cybrosys.com/blog/how-to-add-custom-fields-to-existing-views-in-odoo-16

Also when we add a new field to res.partner,we need do the immediate upgrade of the custom module open your custom module from the apps list restart server, do immediate upgrade of custom module.

In odoo.sh env you can use odoo-bin -u custom module in the sh shell

Regards

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

Hello Asmaa,

In Odoo, the 'inherit' keyword is used to inherit an existing view or model and make changes to it. The '_name' variable is used to specify the name of the model. 

However, when inheriting an existing view or model, Odoo already knows the name of the model or view being inherited, so there is no need to specify it again using the '_name' variable.

Instead, you can simply use the 'inherit' keyword followed by the name of the view or model you wish to inherit, and then make the necessary changes to it. This approach makes the code simpler and easier to read. Refer below example. 

from odoo import fields, models, api, _

class ResPartner(models.Model):
_inherit = "res.partner"
 
x=fields.Char("my field name"

I hope this helps you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

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

Hi,

Remove the name attribute you have given and restart the service and upgrade your module.

class ResPartner(models.Model):
_inherit = "res.partner"

your_field = fields.Char("my field name")


Thanks

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 23
2662
3
thg 5 24
2068
2
thg 4 24
1799
2
thg 1 24
3349
1
thg 11 23
1464