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

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


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
มิ.ย. 20
4272
4
พ.ค. 24
12855
1
เม.ย. 24
3455
0
พ.ย. 23
2124
Blank White Page After log in to Odoo13 แก้ไขแล้ว
1
ก.ย. 23
2292