Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2577 Tampilan

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

Avatar
Buang
Jawaban Terbai

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


Avatar
Buang
Penulis

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

Post Terkait Replies Tampilan Aktivitas
6
Jun 18
5678
1
Okt 16
11397
2
Des 15
3810
1
Jan 25
1655
2
Sep 22
9406