Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd

Hello guys, does somebody know what this error means?

I'm trying to generate the value of a new field from the creation date of a crm.lead object.

My field's name is "x_codigo_oportunidad" and I just need to save a string of the current date in "YYYY-MM" format, because then I will generate an identifier for the lead.

So, this is the code that I typed on Compute field on odoo GUI when creating a new field:

from datetime import datetime
for record in self:
  date_aux= datetime.now()
  record[('x_codigo_oportunidad')] = str(date_aux.date().year) + '-' + str(date_aux.date().month).zfill(2)

But then, when I try to save the field, it gives me this:

File "C:\Program Files (x86)\Odoo 11.0\server\odoo\tools\safe_eval.py", line 187, in assert_valid_codeobj
    raise ValueError("forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in codes)))
ValueError: forbidden opcode(s) in "from datetime import datetime\nfor record in self:\n  date_aux= datetime.now()\n  record[('x_codigo_oportunidad')] = str(date_aux.date().year) + '-' + str(date_aux.date().month).zfill(2)": IMPORT_NAME, IMPORT_FROM

I don't really know what I am doing wrong. 

I hope you guys can help me because I've been two days stucked on it.

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
okt. 24
49
2
dec. 22
7291
0
jun. 20
3413
1
jun. 19
4149
1
mrt. 25
835