Skip to content
Napatdev
HomeProjectsNotesAI SkillsAboutContact
Menu
Napatdev
HomeProjectsNotesAI SkillsAboutContact

LanguageENTH

Get in touch

[email protected]
TH
All notes
ENTH

Odoo Automated Action: why imports fail and how to fix IMPORT_NAME

Written byNapat Pamornsut·~2 min read·Published Sep 14, 2026
On this page
  • Environment
  • Reproducer
  • Why Odoo forbids imports
  • Names available without importing
  • The fix: rewrite without imports
  • Common mistakes
  • When to stop using Automated Actions and write a module instead
  • References
  • Related notes

Short answer: ValueError: forbidden opcode(s) in "...": IMPORT_NAME means your code contains an import statement, which Odoo's safe_eval forbids. Delete the import line and use what Odoo already preloads: env, datetime, dateutil, time, user.

Environment

  • Odoo 17 / 18 / 19
  • Settings > Technical > Automation > Automated Actions > Execute Python Code

Reproducer

python
import datetime

for record in records:
    record.write({'x_reminder_date': datetime.date.today()})

Produces:

text
ValueError: forbidden opcode(s) in "<string>": IMPORT_NAME

Why Odoo forbids imports

safe_eval only allows names Odoo puts into the execution context. An import would pull in arbitrary external modules outside Odoo's control, so it is removed at opcode level — together with STORE_ATTR and other risky opcodes.

The good news: everything commonly needed is already preloaded, so no import is required.

Names available without importing

NameUsed forExample
envAccessing other modelsenv['res.partner'].search([])
records / recordTriggering recordsfor record in records:
userCurrent useruser.id, user.company_id
datetimeDates and timesdatetime.date.today()
dateutilRelative date mathdateutil.relativedelta.relativedelta(days=7)
timeTime formattingtime.strftime('%Y-%m-%d')

The fix: rewrite without imports

The example above is fixed by simply deleting the import line:

python
for record in records:
    record.write({'x_reminder_date': datetime.date.today()})

A deadline 7 days out:

python
for record in records:
    deadline = datetime.date.today() + dateutil.relativedelta.relativedelta(days=7)
    record.write({'x_deadline': deadline})

Looking up a partner and linking it:

python
for record in records:
    partner = env['res.partner'].search([('email', '=', record.x_contact_email)], limit=1)
    if partner:
        record.write({'partner_id': partner.id})

Common mistakes

  1. from datetime import date — still IMPORT_NAME. Every form of import is blocked.
  2. import json for data conversion — find another way, e.g. pass strings through Char/Text fields directly. If you genuinely need it, move the logic into a custom addon module.
  3. External libraries like requests — impossible inside Automated Actions. Use Odoo's webhook action or a custom module for external API calls.
  4. Confusing it with STORE_ATTR — if fixing the import reveals STORE_ATTR, your code still assigns fields directly. Switch to record.write() as shown in Fix forbidden opcode STORE_ATTR with record.write().

When to stop using Automated Actions and write a module instead

  • You need external libraries (requests, pandas, others).
  • Logic exceeds roughly 30–40 lines and becomes hard to read.
  • You need real unit tests or version control.

Automated Actions fit short if-then-write jobs. Beyond that, a custom addon is cheaper long-term.

References

  • Odoo 19 Automated Actions docs: https://www.odoo.com/documentation/19.0/applications/studio/automated_actions.html

Related notes

  • Odoo Automated Action: Fix forbidden opcode STORE_ATTR with record.write()
  • Odoo QWeb: fixing PDF page breaks with real examples
  • All Odoo notes

Author: Napat Pamornsut — About · Projects · All notes

← Previous noteOdoo 19 Certification study guide: exam structure and reading plan
Next note →Odoo Automated Action: Fix forbidden opcode STOREATTR with record.write
N

Napat Pamornsut

Web Developer / Software Tester

AboutProjectsAll notes

On this page

  • Environment
  • Reproducer
  • Why Odoo forbids imports
  • Names available without importing
  • The fix: rewrite without imports
  • Common mistakes
  • When to stop using Automated Actions and write a module instead
  • References
  • Related notes

All notes

  • Next.js Server Actions explained: when to use them vs Route Handlers
  • Next.js Server Actions Security: validation, authorization and CSRF
  • Odoo 19 Certification study guide: exam structure and reading plan
  • Odoo Automated Action: why imports fail and how to fix IMPORTNAME
  • Odoo Automated Action: Fix forbidden opcode STOREATTR with record.write
  • Odoo QWeb: fixing PDF page breaks with real examples
  • Odoo QWeb Table Border: controlling PDF table lines on every page
  • Playwright Page Object Model: a test structure that stays maintainable
  • What is Playwright? Start E2E testing with TypeScript for real projects
  • Next.js Server Actions + Prisma Transaction: atomic mutations

Napat Pamornsut

ณภัทร ภมรสูตร

Web development & software testing

ProjectsNotesAI SkillsAboutContactSearch

© 2026 Napatdev

Back to top