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

Hello everyone,

In Odoo 12 we can directly access company model data on field definition like for instance:

my_field = fields.Char('Test field', default=lambda self: self.env.user.company_id.my_field)

This way we have access to desired values set on company model.

What about if I want to directly access values on "ir_config_parameters" (not on the res_company model) from field definition?

Something like:

my_field = fields.Char(default=lambda self: direct_access_to_ir_config_parameters_here)

Thank you all in advance

Best regards

PM

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

Hello paulo,

you can do like:


def get_my_field_value(self):
config = self.env['ir.config_parameter']
return config.sudo().get_param("key_to_fetch_value")

my_field = fields.Char('Test field', default=get_my_field_value)


For more detail just check this link: https://odoo-development.readthedocs.io/en/latest/dev/py/res.config.settings.html

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

Hello Paulo,

You need to define the same field in "res.company" model which defines in "res.config.settings" model like this.

https://github.com/odoo/odoo/blob/13.0/addons/account/models/company.py#L56


And you need to make a field related to res company's field. It should be defined in "res.config.settings" like this.

https://github.com/odoo/odoo/blob/13.0/addons/account/models/res_config_settings.py#L13


Also update the functions get_values() and set_values() according to this field.

Now you can use the same approach for accessing "ir_config_parameters" values like this.

https://github.com/odoo/odoo/blob/13.0/addons/account/models/account_move.py#L4138


Feel free to ask in case of any query.


Thanks,

Aman Prakash,

Webkul Software Private Limited

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

Thank you @Aman Prakash,

You're answer is correct and I have not asked correctly. What I wanted to do, is to use a direct access method to values on "ir_config_paramenters" on field definition as I have done with "default=lambda...".

The value I want to access is not on res_company.

Anyway I have edited my question

Thank you very much

PM

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 4 25
3671
0
thg 3 24
1406
0
thg 10 22
2586
0
thg 9 22
1782
1
thg 7 22
5453