Skip to Content
Menú
This question has been flagged

Hello guys,


I am trying to make a field to a related field.

I am taking project_id.company_id.name and I am trying to put this into an existing field inside timesheets.

But when defining this into related='project_id.company_id.name' or  'project_id.company_id' ,, Odoo either crashes or I get an error

KeyError: 'Field project_id referenced in related field definition account.analytic.line.company_id does not exist.'

  Any ideas ? 

also this is the field definition

company_id= fields.Many2one('res.company', string='Company', related='project_id.company_id', required=True, readonly=False)

Avatar
Descartar
Best Answer

Hello Juraj Rechtoris,

You can try the below code, I also checked with my database and it's worked. Please ensure dependency of hr_timesheet.

Please find Code in Comment. 

I hope this will help you. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Descartar

Code Example :

from odoo import models, fields

class AccountAnalytic(models.Model):
_inherit = "account.analytic.line"

company_id = fields.Many2one('res.company', string='Company', related='project_id.company_id', required=True,
readonly=False)
company_name = fields.Char(related="project_id.company_id.name")

Autor Best Answer

Hello,

I think I was missing the dependancy on hr_timesheet

It works perfectly now, thank you!

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
de des. 23
21234
3
de des. 22
8001
1
de març 17
2784
0
de març 15
3575
1
de nov. 19
4475