跳至內容
選單
此問題已被標幟
2 回覆
3266 瀏覽次數

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!

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
12月 23
21557
3
12月 22
8409
1
3月 17
3012
0
3月 15
3863
1
11月 19
4742