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

i want to get the defalut value of the contract_id of the rh_contract module, the field is in relation of many2one with the rh.employee form

in my customu module i want to set the value of the field to my contrat field.

i did this but something still missing 

employee_id = fields.Many2one('hr.employee', string="Employee")
def _get_default_contrat(self):
    return self.env['hr.contract'].search([], limit=1).id

contrat = fields.Many2one('hr.contract', string='Contrat', default=_get_default_contrat, domain=[])

@api.onchange('employee_id')
def onchange_contrat_id(self):
self.contrat = self.employee_id.contract_id

形象
丢弃
编写者

Thanks Ismail, the code was functioning, the trick was just to active the contrat_id :D

最佳答案

Hi,

Use related.

employee_id = fields.Many2one('hr.employee', string="Employee")
contrat_id = fields.Many2one('hr.contract', string='Contrat', related="employee_id.contract_id" )


形象
丢弃
相关帖文 回复 查看 活动
4
6月 20
4150
4
5月 24
12567
1
4月 24
3208
0
11月 23
1946
1
9月 23
2046