Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Error in field calculation in Odoo 17: "forbidden opcode(s)" when summing values of assets associated with a project

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
2 Replies
1616 Rodiniai
Portretas
Euroservis S.r.l.

Hello Odoo Community,

I am working on Odoo 17 Online with Studio I am trying to calculate a field in the project.project model, which should sum the values of a field x_studio_valore_investimento in a x_beni_4_0_e_5_0 model (representing the assets associated with the project). Each asset is linked to the project via a relational field x_studio_progetto.

However, when I try to calculate this field using a computed field and a Python function, I get the following error:

css

Copia

ValueError: forbidden opcode(s) in 'class Project(models.Model): ...'

The error seems to be caused by the fact that the Python code contains a class definition within the context of the field calculation, which is not allowed. I have tried several approaches, but none seem to resolve the issue.

Details of my code:

I have defined the computed field in the project.project model as follows:

python

Copia

class Project(models.Model): _inherit = 'project.project' x_studio_valore_stimato_investimento = fields.Float( string="Estimated Investment Value", compute="_compute_valore_stimato_investimento", store=True ) @api.depends('x_studio_one2many_field_8v9_1iff9798r') # Depends on the relational field Many2one def _compute_valore_stimato_investimento(self): for record in self: assets = self.env['x_beni_4_0_e_5_0'].search([('x_studio_progetto', '=', record.id)]) total_investment = sum(assets.mapped('x_studio_valore_investimento')) record.x_studio_valore_stimato_investimento = total_investment

However, this code generates the error mentioned above.

What I have tried:

  1. I tried modifying the field calculation without redefining the Project class, but it doesn't seem to be sufficient.
  2. I reviewed the Odoo documentation and some online resources, but I couldn't find a solution for this specific error.

Questions:

  • Is there a way to avoid the "forbidden opcode(s)" error when calculating fields in Odoo?
  • How can I sum the values of the assets associated with the project without encountering this error?
  • Is it possible to use a One2many relationship in a computed field like in my case?

I hope someone can help me resolve this issue. Thank you in advance for your support!

Additional Information:

  • Odoo Version: 17.0
  • Project Model: project.project
  • Assets Model: x_beni_4_0_e_5_0
  • Relational Field in the Assets Model: x_studio_progetto
  • Field to Sum in the Assets Model: x_studio_valore_investimento
  • Computed Field in the Project Model: x_studio_valore_stimato_investimento

0
Portretas
Atmesti
Portretas
Ray Carnes (ray)
Best Answer

You cannot write traditional modules with Odoo Online.

See https://www.odoo.com/documentation/18.0/developer/tutorials/importable_modules.html for examples of what you can do. 

1
Portretas
Atmesti
Euroservis S.r.l.
Autorius

Thank you for your response.
In this case, in a standard module (project), it's about using the calculation section in the advanced settings of the field through Studio.

Ray Carnes (ray)

You can't define classes or use @api directives in custom fields.

Portretas
Marc Durepos
Best Answer

Hello,

From your description and the error provided it seems  you are inserting this code into the "compute" field via the Odoo interface, when viewing the field in the technical settings (developer mode). If that's the case, you instead need to define only the body of the function within the "compute" field, and add your field x_studio_one2many_field_8v9_1iff9798r​ as a dependency (the field just above in the field form view).
If your code is actually within a module, there are some design problems you will want to consider since hard-coding Studio field names into a module is very likely to break. I don't think this is your case, but if it is, please consider moving all of this customization into an actual stand-alone module.

Best of luck!

1
Portretas
Atmesti
Euroservis S.r.l.
Autorius

Hi Marc,

Thank you for your help! You were absolutely right.

I have tried several solutions, including:

python

Copia

beni = self.env['x_beni_4_0_e_5_0'].search([('x_studio_progetto', '=', record.id)])
totale_investimento = sum(beni.mapped('x_studio_valore_investimento'))
record.x_studio_valore_stimato_investimento = totale_investimento

And

python

Copia

totale_investimento = sum(record.x_studio_one2many_field_8v9_1iff9798r.mapped('x_studio_valore_investimento'))
record.x_studio_valore_stimato_investimento = totale_investimento

But the system says it is too complex to calculate.

Do you happen to have a solution?

Thanks again for your support!

Marc Durepos

Hi again,
Have you defined the reciprocal field for your Many2one as a One2many field with its inverse_name='x_studio_one2many_field_8v9_1iff9798r' on the Project model as well? If not, you'll need to for the dependency. With that field present, say you call it `x_studio_beni_ids` you could simply use:

```
python

for project in self:
project.x_studio_valore_stimato_investimento = sum(
x_studio_beni_ids.mapped('x_studio_valore_investimento')
)
```

Marc Durepos

Apologies, I missed a project. before the x_studio_beni_ids in my previous comment. Nothing like writing naked code in a forum comment ;)

Euroservis S.r.l.
Autorius

Thank you so much!

I am not able to find a solution.

I tried

for project in self:
project.x_studio_valore_stimato_investimento = sum(
x_beni_4_0_e_5_0_ids.mapped('x_studio_valore_investimento'))

With the dipedendences x_studio_one2many_field_8v9_1iff9798r

Thank you anyway!

Marc Durepos

Your dependency is on the wrong field, but I'm not sure what other error you're getting. You should have x_beni_4_0_e_5_0_ids as the dependency.

Euroservis S.r.l.
Autorius

Thank you!

Enjoying the discussion? Don't just read, join in!

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

Registracija
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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