Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
16610 มุมมอง

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

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Add New Operation Type in Warehouse แก้ไขแล้ว
2
ธ.ค. 24
3668
1
พ.ย. 24
2372
1
มี.ค. 23
1738
4
ส.ค. 24
22891
0
ธ.ค. 21
1998