Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2650 Представления

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

Related Posts Ответы Просмотры Активность
6
июн. 18
5793
1
окт. 16
11397
2
дек. 15
3855
1
янв. 25
1808
2
сент. 22
9533