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
    • Discuss
    • 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

Evaluation of python expression

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
pythonodoo8.0
1 Balas
10877 Tampilan
Avatar
dorsaf dhouibi

I tried to evaluate a python code that i write it in a text field.

this is the error that i face

TypeError: unsupported operand type(s) for %: 'ValidationError' and 'exceptions.ValueError'

First of all i have this class condition:

class condition(models.Model):
_name = 'condition'


expression_cond = fields.Selection(
string="Expression",
selection=[('python', 'Expression Python'), ],
required=True,
default="python")

value_cond = fields.Text(
string="Valeur",
required=True,
default="""
# Python code.
# You can use the following variables :
# - self: ORM model of the record which is checked
# - object: same as order or line, browse_record of the sale order or
# - pool: ORM model pool (i.e. self.pool)
# - cr: database cursor
# - context: current context
# - invoice: test for invoice tests
# Note: returned value have to be set in the variable 'result'
"""
)

name = fields.Char(string="Condition", required=True, )

The second class is the rules; i create this calss to select a condition and to verifier if the python expression is correct

class rules(models.Model):
_name = 'rules'

name = fields.Char(string="Régles" ,required=True)
code = fields.Char(string="Code" ,required=True)
condition_id = fields.Many2one(comodel_name="condition", string="Condition ", required=True, )
amount_type_id = fields.Many2one(comodel_name="amount.type", string="Méthode de Calcul", required=True, )

i create those method in this class

@api.model
def _rules_eval_context(self, obj_name, rec):
invoice = self.env['account.invoice']
return {obj_name: rec,
'invoice': invoice,
'self': self.pool.get(rec._name),
'object': rec,
'obj': rec,
'pool': self.pool,
'cr': self._cr,
'uid': self._uid,
}

@api.model
def _rule_eval(self,rule, obj_name, rec):
rule =self.condition_id.value_cond
expr = rule
space = self._rules_eval_context(obj_name, rec)

)

try:
safe_eval(expr,
space,
mode='exec',
nocopy=True) # nocopy allows to return 'result'
except Exception as e:
raise ValidationError("Wrong python code defined for Condition : %s") % (e)
return space.get('result', False)

@api.onchange('condition_id')
def _detect_rules(self):

rule = self.condition_id.value_cond
if self._rule_eval(rule,'invoice', self):
print("*****dectect rules")
else:
print("*********wrong detection")

 this is my expression that i creat 

if invoice.amout_total >=1000 :
    result=True

 you can find the pictures on this link

https://drive.google.com/drive/folders/0BwRD3KEH7ZiVS0VFemxTNjJkSHc?usp=sharing










ff

0
Avatar
Buang
Avatar
Annadurai
Jawaban Terbai

Hello, Try this

raise   ValidationError("Wrong python code defined for Condition : %s") % (e.name)
1
Avatar
Buang
dorsaf dhouibi
Penulis

thanks but its give me this error

AttributeError: 'exceptions.TypeError' object has no attribute 'name'

Niyas Raphy (Walnut Software Solutions)

Please check this sample and just adjust accordingly,

raise ValidationError(_("The amount of the payment '%s' is too high. The maximum permitted is %s.") % (payment.name, str(9) * (max_digits - 3) + ".99"))

dorsaf dhouibi
Penulis

its work thanks Annadurai

i don't have the error anymore but i still don't find a solution how to create a python expression to test for example if the amount_total of an invoice >=1000

dorsaf dhouibi
Penulis

Sorry thanks Niyas :)

Annadurai

do upvote :)

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
create a getter for odoo 8 Diselesaikan
python odoo8.0
Avatar
Avatar
2
Jul 17
4672
recuperate fields of budget lines
python odoo8.0
Avatar
0
Agu 16
3763
Using Blob to save in postgres via odoo
python odoo8.0
Avatar
Avatar
1
Jul 16
5870
How to add auto refreshing for hr_attendance in odoo?
python odoo8.0
Avatar
0
Jun 16
3801
Team Manager
python python2.7 odoo8.0
Avatar
0
Agu 17
3689
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