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

I am trying to set up a mass BOM edit. My Python code is giving forbidden opcode(s) error. Odoo 18

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
developmentconfiguration
2 Replies
998 Tampilan
Avatar
Mahmood

Basically I was adding 2 fields to the form view: Material to replace and Replacement material, then I would give the option to select multiple BOMs and each of them will replace the material selected with the replacement material. My problem was when I tried adding the code, It gives me forbidden opcode(s) error.

Im using odoo studio btw.

This is the code:

from odoo.exceptions import UserError


# Get the material to replace and the replacement material from the FIRST selected record

if records:

    first_record = records[0]

    material_to_replace = first_record.x_studio_material_to_replace_1

    replacement_material = first_record.x_studio_replacement_material_1


    if not material_to_replace or not replacement_material:

        raise UserError("Please specify both 'Material to Replace' and 'Replacement Material' in the first selected BOM.")


    # Loop through the selected BOMs

    for bom in records:

        # Loop through the BOM lines

        for line in bom.bom_line_ids:

            # Check if the material matches the one to replace

            if line.product_id == material_to_replace:

                # Replace the material

                line.product_id = replacement_material

                line.product_qty = line.product_qty #This line is added to force the recomputation of values

else:

    raise UserError("No BOMs selected.")


And this is the error:  forbidden opcode(s) in 'from odoo.exceptions import UserError\n\n# Get the material to replace and the replacement material from the FIRST selected record\nif records:\n    first_record = records[0]\n    material_to_replace = first_record.x_material_to_replace\n    replacement_material = first_record.x_replacement_material\n\n    if not material_to_replace or not replacement_material:\n        raise UserError("Please specify both \'Material to Replace\' and \'Replacement Material\' in the first selected BOM.")\n\n    # Loop through the selected BOMs\n    for bom in records:\n        # Loop through the BOM lines\n        for line in bom.bom_line_ids:\n            # Check if the material matches the one to replace\n            if line.product_id == material_to_replace:\n                # Replace the material\n                line.product_id = replacement_material\n                line.product_qty = line.product_qty #This line is added to force the recomputation of values\nelse:\n    raise UserError("No BOMs selected.")': IMPORT_NAME, IMPORT_FROM, STORE_ATTR

0
Avatar
Buang
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Jawaban Terbai

Hi,

Please refer to the code:


if not records:

    raise UserError("No BOMs selected.")


first_record = records[0]

material_to_replace = first_record.x_studio_material_to_replace_1

replacement_material = first_record.x_studio_replacement_material_1


if not material_to_replace or not replacement_material:

    raise UserError(

        "Please specify both 'Material to Replace' and 'Replacement Material' in the first selected BOM.")


# Loop through the selected BOMs

for bom in records:

    for line in bom.bom_line_ids:

        if line.product_id == material_to_replace:

            # Use write() instead of direct assignment

            line.write({

                "product_id": replacement_material.id,

            })


Hope it helps.

0
Avatar
Buang
Ray Carnes (ray)

You should use assignment and let the ORM manage the database updates.

Avatar
Ray Carnes (ray)
Jawaban Terbai

You cannot import any libraries, UserError is already available.

All record assignments must be in the form:

record['field'] = value
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
Dynamic Dashboard Background and Text on Dark/Light Theme Switch in Odoo 16 sh
development configuration
Avatar
Avatar
1
Nov 25
192
Bulk PDF download error
development configuration
Avatar
0
Okt 25
512
Google Calendar Sync - Odoo Calendar
development configuration
Avatar
Avatar
Avatar
3
Agu 25
1903
Timesheets multiple days
development configuration
Avatar
Avatar
Avatar
3
Jul 25
1233
How to set up contacts to require confirmation from a significant person when saving a new contact?
development configuration
Avatar
Avatar
Avatar
2
Jul 25
1867
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