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

Hello everyone 
i have odoo16

and encountered this problem

_description = 'tracking the path of employee in our enterprise'
_inherit = 'hr.employee'

contract_ids = fields.One2many('hr.contract', 'employee_id', string='Employee Contracts',
compute="_compute_contracts")
jobs_id = fields.Many2one(string='the job', related='contract_ids.job_id')

i want to retrieve the jobs objects as field what should i specify the field type should i use to get the jobs_id entities stored in jobs_id

形象
丢弃
最佳答案

Hello Ayoub Razali,

You have taken jobs_id as Many2one field so you can store only one Job ID. Instead of related use same compute=_compute_contracts which used for contract_ids

You can add this code in _compute_contracts method of contract_ids field.

jobs_id = contract_ids[0].job_id.id if contract_ids and contract_ids[0].job_id else False

If want to store all Job ids of all contracts change type with Many2many field and use same compute=_compute_contracts which used for contract_ids

jobs_id = [(4, contract.job_id.id if contract.job_id) for contract_id in contract_ids] 


Regards,

Hemangi


形象
丢弃
编写者

thank you so much
but i had to initialize the jobs_id = contract_ids[0].job_id.id
def _get_default_contract(self):
jobs_id = contract_ids[0].job_id
default= _get_default_contract

相关帖文 回复 查看 活动
6
6月 18
5787
1
10月 16
11397
2
12月 15
3850
1
1月 25
1774
2
9月 22
9491