Skip to Content
Menu
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
Discard
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
Discard

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")

Author Best Answer

Hello,

I think I was missing the dependancy on hr_timesheet

It works perfectly now, thank you!

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
19966
3
Dec 22
6583
1
Mar 17
2039
0
Mar 15
2676
1
Nov 19
3229