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

hi all , i want to get values from a field which is in res config settings model and use it in another model


i have tried like this below method to get the values but , its not working

// my model :

class HolidaysAllocation(models.Model):

_inherit = "\hr\.leave\.allocation\"\\
\
\ \ \ \ _description\ \=\ \"Time\ Off\ Allocation\"\
\
\
\
\ \ \ \ \@api\.model\ \ \
\
\ \ \ \ def\ _get_values\(self\)\:\ \ \ \ \ \ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ res\ \=\ super\(HolidaysAllocation\,\ self\)\._get_values\(\)\ \ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ with_user\ \=\ self\.env\[\'ir\.config_parameter\'\]\.sudo\(\)\ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ inform_taking_leave_id\ \=\ \ with_user\.get_param\(\'inform_taking_leave\.res_ids\ \'\)\ \ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ res\.update\(res_inform_ids\=\[\(6\,\ 0\,\ literal_eval\(inform_taking_leave_id\)\)\]\ if\ inform_taking_leave_id\ else\ False\,\ \)\ \ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ return\ res\
\
\
\
\
\
\ \ \ \ res_inform_ids\ \=\ fields\.Many2many\(\'hr\.employee\'\,string\=\'Inform\ and\ Taking\ Leave\'\,\ help\=\'Inform\ and\ Taking\ Leave\'\,default\=_get_values\,\)\
\
\
\
\
\
\\

\/\/\ res\ config\ field\ \\

class\ HrLeaveInform\(models\.TransientModel\)\:\
\
\ \ \ \ _inherit\ \=\ \'\res\.config\.settings\'\\
\
\
\
\ \ \ \ res_ids\ \=\ fields\.Many2many\(\'hr\.employee\'\)\
\
\ \
\
\ \ \ \ def\ set_values\(self\)\:\ \ \ \ \ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ res\ \=\ super\(HrLeaveInform\,\ self\)\.set_values\(\)\ \ \ \ \ \ \ \
\
\ \ \ \ \ \ \ \ self\.env\[\'ir\.config_parameter\'\]\.sudo\(\)\.set_param\(\'inform_taking_leave\.res_ids\'\,\ \
self.res_ids.ids)

return res



@api.model

def get_values(self):

res = super(HrLeaveInform, self).get_values()

with_user = self.env['ir.config_parameter'].sudo()

inform_taking_leave_id = with_user.get_param('inform_taking_leave.res_ids')

res.update(res_ids=[(6, 0, literal_eval(inform_taking_leave_id))] if inform_taking_leave_id else False, )

return res
아바타
취소
작성자

anyone

베스트 답변

Hello @madara
     

    please define field in res.config.settings like below..

    Fieldname = fields.Boolean(config_parameter='module_name.field_name')

    then fetch field value..

    Fieldname = self.env['ir.config_parameter'].sudo().get_param('module_name.field_name')

아바타
취소
베스트 답변

Hi, what is the error, your param is empty ? 


Gus

아바타
취소
관련 게시물 답글 화면 활동
2
12월 24
3994
1
11월 24
2780
1
3월 23
2043
4
8월 24
23483
0
12월 21
2296