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

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

Ảnh đại diện
Huỷ bỏ
Tác giả

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

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

Hi,

Use related.

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


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 6 20
4189
4
thg 5 24
12636
1
thg 4 24
3273
0
thg 11 23
2022
1
thg 9 23
2109