Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
3281 Представления

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)

Аватар
Отменить
Лучший ответ

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

Аватар
Отменить

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

Автор Лучший ответ

Hello,

I think I was missing the dependancy on hr_timesheet

It works perfectly now, thank you!

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
дек. 23
21571
3
дек. 22
8427
1
мар. 17
3014
0
мар. 15
3882
1
нояб. 19
4766