콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
3 답글
6043 화면

Generally in object programming there is something called as Global variables which can be accessed without any object and throughout the program. Now with respect to Odoo, i want to know how and where to define a field which then can be accessed in and from all the other modules.

I am thinking defining a field in base module does the thing but i'm not sure of it. Please answer, if anyone knows how to do this or can this even be done?

아바타
취소
베스트 답변

Yes, you are right: fot that purpose you can apply the class 'BaseModel' from the Odoo core (the file 'models.py').

All other Odoo classes (sale.order, product.product, so any) inherit that class. For example, here the columns '_name', '_order', '_sequence' are defined.

You can define your own as well like _my_global_variable = 100. Then, you may use it in any class as self._my_global_variable. Besides, you will be able to re-define it privately for a definite model.

In many cases, however, it is better to use the model 'ir.config.parameter', and apply to it. It will let you change the value through the interface. For an example have a look at the module 'sale', the file 'res_config_settings.py'. Here you can see how to save and retrieve the global settings. In such a way, for instance, odoo base url is kept.

아바타
취소
작성자

Thanks for the info. +1

베스트 답변

Hi,

you can check this class, you can define field over here, this can be accessible everywhere.

 _inherit = 'res.config.settings'

res[field_name] = self.env['ir.config_parameter'].get_param(key_name, '')

Regards,

Silvestar

아바타
취소
작성자

Thank you for the answer but I have a doubt. What's key_name and the other param inside get_param?

This is github link i have done it in version 10.

i have created this module for website functionality and check models file where i added fields.

and i accessing those fields in the controller .

https://github.com/jsilvestar/odoo/blob/10.0/website_smart_street/controllers/main.py#L19-L20

Regards,

Silvestar

관련 게시물 답글 화면 활동
3
2월 24
14464
3
5월 25
1828
5
5월 25
9546
1
4월 25
1360
3
9월 24
14284