跳至内容
菜单
此问题已终结
2 回复
16447 查看

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
3650
1
11月 24
2343
1
3月 23
1699
4
8月 24
22751
0
12月 21
1968