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

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
Ảnh đại diện
Huỷ bỏ
Tác giả

anyone

Câu trả lời hay nhất

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')

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

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


Gus

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 24
3668
1
thg 11 24
2372
1
thg 3 23
1739
4
thg 8 24
22891
0
thg 12 21
1998