Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
2645 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

Gerelateerde posts Antwoorden Weergaven Activiteit
6
jun. 18
5787
1
okt. 16
11397
2
dec. 15
3850
1
jan. 25
1774
2
sep. 22
9491