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


Hello, I have a date field and I need to extract its month and year using studio, I tried the following, but it gives me an error, how can I solve it? I thought that I needed to compute a new month field, but I got an error with this one:

for record in self:
  from datetime import datetime, date
  record[("x_studio_month")] = datetime.record.x_studio_from.strftime("%B")


The error is something like:

  ValueError: forbidden opcode(s) in 'for record in self:\n from datetime import datetime\n record[("x_studio_mes_desde")] = record.x_studio_desde.month': IMPORT_NAME, IMPORT_FROM

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

Hi,

You can try the following method for the same:

1) Go to settings and turn on the developer mode and switch to the studio.
2) Now add 2 Text fields for Month and Year respectively.
3) Now define the compute methods, by clicking on the more option of the field. You can refer to Odoo Studio Book for any help: https://www.cybrosys.com/odoo/odoo-books/odoo-15-studio/build-an-app/define-compute-method/
4) In "Dependencies" add the technical name of the date field from which you need to extract the date.
5) Now in the "Compute" field of the month enter the following code "for rec in self:
rec['x_studio_month'] = rec.date_field.strftime('%B')"
6) Now in the "Compute" field of the year enter the following code "for rec in self:
rec['x_studio_year'] = rec.date_field.strftime('%Y')"
7) Now you can save it and close the studio view.

Now the fields will be computed when we enter the value into the date field

Regards

Аватар
Отменить
Related Posts Ответы Просмотры Активность
1
июл. 24
2203
0
февр. 24
2297
1
апр. 20
2427
1
мар. 18
6272
2
окт. 24
1113