Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
developmentconfiguration
2 Răspunsuri
999 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Cybrosys Techno Solutions Pvt.Ltd
Cel mai bun răspuns

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
Imagine profil
Abandonează
Ray Carnes (ray)

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

Imagine profil
Ray Carnes (ray)
Cel mai bun răspuns

You cannot import any libraries, UserError is already available.

All record assignments must be in the form:

record['field'] = value
0
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
Dynamic Dashboard Background and Text on Dark/Light Theme Switch in Odoo 16 sh
development configuration
Imagine profil
Imagine profil
1
nov. 25
193
Bulk PDF download error
development configuration
Imagine profil
0
oct. 25
512
Google Calendar Sync - Odoo Calendar
development configuration
Imagine profil
Imagine profil
Imagine profil
3
aug. 25
1904
Timesheets multiple days
development configuration
Imagine profil
Imagine profil
Imagine profil
3
iul. 25
1234
How to set up contacts to require confirmation from a significant person when saving a new contact?
development configuration
Imagine profil
Imagine profil
Imagine profil
2
iul. 25
1867
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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