Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
2 Antwoorden
3255 Weergaven

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

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
Annuleer

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

Auteur Beste antwoord

Hello,

I think I was missing the dependancy on hr_timesheet

It works perfectly now, thank you!

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
1
dec. 23
21538
3
dec. 22
8402
1
mrt. 17
3011
0
mrt. 15
3846
1
nov. 19
4726