Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to use "import <module>" in automated action in Odoo.sh 11.0?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
actionpythonautomatedautomationodoo.sh
2 Replies
18932 Tampilan
Avatar
stanislav ploschansky

Hi!

I have my Python code which want to use in automated action. I can't use it directly because import is prohibited:

forbidden opcode(s) in ... IMPORT_NAME

I can create a module and publish it on GitHib to get our Odoo.sh updated, then install it, but then I stucked again with same problem: i can't use "import" command in action script.

What am I doing wrong? How to create automated action in a way allow to use my python code?

(my use case is very simple: when data changed in monitored model, in Automated Action, OnCreateOrUpdate, I must call my REST API endpoint (doing that by using "import requests") and passing there details of changed data).

Please give me an advice, I'm fully locked between closed doors, looking forward for any hint!

1
Avatar
Buang
Yenthe Van Ginneken (Mainframe Monkey)

Hi - can you please add the code too? It is hard to help/debug without the code.

ivailo tonev

Hello,

I tried to apply the monkey patch in question because I'm currently learning Odoo and I might need to write more complex code with Python imports in Automation Rules.

However, this monkey patch doesn't seem to work for me. I'm using Odoo 18 with odoo.sh.

Is there any change in the code for Odoo 18?

Thanks :)

Avatar
Denis Ledoux (dle)
Jawaban Terbai

`import` is indeed prevented in automated/server actions.

This is expected in Odoo for security concerns: Adding it would mean anyone having the Settings access to your Odoo database would be able to import any Python module, and therefore do about anything they want with your database and server filesystem.

e.g.

import shutil
shutil.rmtree('.')  # Deleting all folders and files of current directory

This is even more problematic when your Odoo server hosts multiple databases: Any administrator of any database would be able to do about anything in all other databases and filestores. It does not apply to Odoo.sh, as each server is isolated and only host one database at a time. But, this behavior is a restriction of the standard Odoo server, which can have multiple databases hosted by the server, and this is therefore important to mention this case.

Why don't you just create a custom module that overrides the `create` and `write` method of the model you want monitored, to contact this REST API endpoint ?
- It will be safer,
- It will scale better as your business/customization grows. Indeed, you will use the versioning of Git and have a history of what is done for which reason by who.

If you still want to be able to use imports in automated actions, which is STRICTLY UNADVISED for the reason stated above, you can create a custom module overriding the `_SAFE_OPCODES` list to add the given opcode `IMPORT_NAME`.
https://github.com/odoo/odoo/blob/d7cfa8c502f27bee5c2fccb35db47b08e3b3804b/odoo/tools/safe_eval.py#L95

1
Avatar
Buang
Avatar
Chris @ Five Devs
Jawaban Terbai

There is a way to do this. 5 years ago it may have been considered bad practice or unadvised. You now not only need to add the _SAFE_OPCODES but you also need to update the _ALLOWED_MODULES otherwise it will throw an import error since Odoo overrides __import__.

You still need a custom module to allow this and I consider it safe. Here is an example of allowing imports for requests and json modules

#your_module/tools/safe_eval.py
import odoo.tools.safe_eval as safe_eval
from opcode import opmap

safe_eval._SAFE_OPCODES.update(set(opmap[x] for x in ['IMPORT_NAME', 'IMPORT_FROM'] if x in opmap))
safe_eval._ALLOWED_MODULES.extend(['requests', 'json'])

This then allows you to do Automated Action > On Creation > Execute Python Code

import requests, json

headers = {"Content-Type": "application/json", "Accept": "application/json"}
url = "https://webhook.site/1234"
json_data = {'name' : record.name, 'date': record.date.strftime('%Y-%m-%d')}
response = requests.post(url, data=json.dumps(json_data), headers=headers)

Note: This is probably not needed in Odoo 17+ due to the ability to execute a webhook.

0
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Automated action with python expression Diselesaikan
action python automated odoo.sh v12
Avatar
Avatar
6
Mar 24
10675
Automated action : return another action Diselesaikan
action python automated
Avatar
Avatar
3
Jul 20
10883
Python expression in Automated Actions Diselesaikan
action python automated
Avatar
Avatar
1
Apr 20
14953
Access created/updated row on Python Automated Action
action python automated
Avatar
1
Jul 18
6356
Add a Mailing contact automatically to a mailing list Diselesaikan
python automated mailing odoo.sh v12
Avatar
Avatar
Avatar
Avatar
Avatar
12
Apr 24
14500
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now