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

So I'd like to display the name of the location on the Track List but so far I'm getting stuck with errors.

I already added a new field to the event.track model names "x_location_name", which is a computed field with the following code:

​from odoo import api
location_name = fields.Text(compute='_compute_location_name')

@api.depends('location_id', 'location.name')
def _compute_location_name(self):
  if self.location_id:
    self.location_name = self.location_id.name
  else:
    self.location_name = ''


Then I went to the Tracks: List Display view and added a span with t-out="track.x_location_name" but after that the website throws an error as follows.


Error while render the template
ValueError: forbidden opcode(s) in "from odoo import api\nlocation_name = fields.Text(compute='_compute_location_name')\n\n@api.depends('location_id', location.name')\ndef _compute_location_name(self):\n  if self.location_id:\n    self.location_name = self.location_id.name\n  else:\n    self.location_name = ''": IMPORT_NAME, IMPORT_FROM
Template: website_event_track.tracks_display_list
Path: /t/div[2]/ul/li/div[2]/div/div[2]/div[1]/div[2]/span[1]
Node: 

The error occurred while rendering the template website_event_track.tracks_display_list and evaluating the following expression: 

So I'm stuck here and was wondering:

- Is the computed field not correct? (I'm not knowledgable in Python)

- Did I incorrectly try to render the computed field?


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

Yes, I'm using the Developer Tools, and the video indeed helped!

Looks like the issue was with the code of the computed field.

Just as a reference if someone else ends up with a similar issue, below the computation that worked

for rec in self:
  if rec.location_id:
    rec['x_location_name'] = rec.location_id.name
  else:
    rec['x_location_name'] = ''

So the issue was for one: the code including more than necessary Python things, then also the field name being incorrect in the computation and lastly record is a reserved word.

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

Hi,
Are you defining the computed field from the user interface , then see: https://www.youtube.com/watch?v=j981dytxE28

Thanks

Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
мая 25
906
1
нояб. 24
1207
1
июл. 15
5259
1
сент. 24
1547
0
авг. 24
987