Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
4678 Widoki


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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lip 24
2430
0
lut 24
2414
1
kwi 20
2610
1
mar 18
6385
2
paź 24
1234