Skip to Content
Menu
This question has been flagged

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
Discard
Related Posts Replies Views Activity
2
Oct 24
49
2
Dec 22
5266
0
Jun 20
2548
1
Jun 19
3447
1
Apr 24
257