تخطي للذهاب إلى المحتوى
أودو القائمة
  • تسجيل الدخول
  • جرب مجاناً
  • التطبيقات
    المالية
    • المحاسبة
    • فوترة
    • النفقات
    • جدول البيانات (BI)
    • المستندات
    • توقيع إلكتروني
    المبيعات
    • إدارة علاقات العملاء
    • المبيعات
    • نقطة البيع للمتاجر
    • نقطة البيع للمطاعم
    • الاشتراكات
    • تأجير
    المواقع الإلكترونية
    • أداة بناء المواقع الإلكترونية
    • متاجر إلكترونية
    • مدونة
    • المنتدى
    • دردشة مباشرة
    • التعليم الإلكتروني
    سلسلة التوريد
    • المستودعات
    • التصنيع
    • إدارة دورة حياة المنتج
    • المشتريات
    • الصيانة
    • الجودة
    الموارد البشرية
    • موظفون
    • التوظيف
    • إجازة عمل
    • التقييمات
    • الإحالات
    • تطبيق الأسطول
    التسويق
    • التسويق الإجتماعي
    • التسويق عبر البريد الإلكتروني
    • التسويق عبر الرسائل النصية
    • فعاليات
    • أتمتة التسويق
    • الاستطلاعات
    الخدمات
    • المشاريع
    • الجداول الزمنية
    • الخدمة الميدانية
    • مكتب المساعدة
    • التخطيط
    • مواعيد
    اﻹنتاجية
    • مناقشة
    • الموافقات
    • إنترنت الأشياء "IoT"
    • بروتوكول ربط المحادثات الصوتية عبر الإنترنت
    • المعرفة
    • WhatsApp
    التطبيقات الخارجية ستوديو أودو منصة أودو السحابية
  • قطاعات الأعمال
    البيع بالتجزئة
    • متجر كتب
    • متجر ملابس
    • متجر أثاث
    • متجر بقالة
    • متجر معدات
    • متجر ألعاب
    الطعام والضيافة
    • بار وحانة
    • المطعم
    • مطعم للوجبات السريعة
    • نزل للضيوف
    • موزّع مشروبات
    • فندق
    العقارات
    • وكالة عقارات
    • شركة هندسة معمارية
    • البناء
    • إدارة العقارات
    • العناية بالحدائق
    • اتحاد مُلاّك العقارات
    استشارة
    • مؤسسة محاسبية
    • شريك أودو
    • وكالة تسويقية
    • منشأة قانونية
    • استقطاب المواهب
    • التدقيق والتوثيق
    التصنيع
    • الأقمشة
    • معدني
    • الأثاث
    • الطعام
    • مصنع خمور
    • هدايا الشركات
    الصحة واللياقة البدنية
    • نادي رياضي
    • متجر نظارات
    • مركز لياقة بدنية
    • الممارسون الصحيون
    • صيدلية
    • صالون تصفيف الشعر
    التجارة
    • عامل صيانة
    • الأجهزة والمعدات التقنية ودعمها
    • أنظمة الطاقة الشمسية
    • صانع أحذية
    • خدمات التنظيف
    • خدمات التكييف (HVAC)
    غير ذلك
    • منظمة غير ربحية
    • وكالة بيئية
    • تأجير لوحات إعلانية
    • تصوير
    • تأجير دراجات
    • بائع وسيط للبرمجيات
    تصفح كافة قطاعات الأعمال
  • مجتمع أودو
    تعلم
    • دروس
    • التوثيق
    • شهادات
    • التدريب
    • مدونة
    • بودكاست
    قم بتعزيز التعليم
    • برنامج تعليم
    • Scale UP! لعبة الأعمال
    • قم بزيارة أودو
    احصل على البرنامج
    • تحميل
    • قارنْ الإصدارات
    • إطلاق
    تعاون
    • جيت هاب "Github"
    • المنتدى
    • فعاليات
    • الترجمات
    • كنْ شريكاً
    • خدمات الشركاء
    • سجل مكتب المحاسبة الخاص بك
    احصل على الخدمات
    • اعثر على شريك
    • اعثر على محاسب
    • قابل أحد مرشدي الأعمال
    • خدمات التنفيذ
    • مراجع العملاء
    • الدعم
    • الترقيات
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    الحصول على عرض توضيحي
  • الأسعار
  • المساعدة

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

  • إدارة علاقات العملاء
  • e-Commerce
  • المحاسبة
  • المخزون
  • PoS
  • المشروع
  • MRP
All apps
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
المساعدة

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

اشتراك

تسلم الإشعارات عندما يكون هناك نشاط في هذا المنشور

لقد تم الإبلاغ عن هذا السؤال
2 الردود
1612 أدوات العرض
الصورة الرمزية
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
الصورة الرمزية
إهمال
الصورة الرمزية
Ray Carnes (ray)
أفضل إجابة

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
الصورة الرمزية
إهمال
Euroservis S.r.l.
الكاتب

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.

الصورة الرمزية
Marc Durepos
أفضل إجابة

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
الصورة الرمزية
إهمال
Euroservis S.r.l.
الكاتب

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.
الكاتب

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.
الكاتب

Thank you!

هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!

أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!

تسجيل
المجتمع
  • دروس
  • التوثيق
  • المنتدى
مصدر مفتوح
  • تحميل
  • جيت هاب "Github"
  • المشغل الآلي رنبوت
  • الترجمات
خدماتنا
  • استضافة أودو إس إتش
  • الدعم
  • الترقية
  • التطويرات المخصصة
  • التعليم
  • اعثر على محاسب
  • اعثر على شريك
  • كنْ شريكاً
معلومات عنا
  • شركتنا
  • أصول العلامة التجارية
  • اتصلْ بنا
  • الوظائف
  • فعاليات
  • بودكاست
  • مدونة
  • عملاء
  • قانوني • الخصوصية
  • الحماية
الْعَرَبيّة 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

أودو هو عبارة عن مجموعة من تطبيقات الأعمال مفتوحة المصدر التي تغطي جميع احتياجات شركتك، مثل: إدارة علاقات العملاء والتجارة الإلكترونية والمحاسبة والمخزون ونقاط البيع وإدارة المشاريع وما إلى ذلك.

ما يجعل من أودو مميزاً هو هدفه بأن يكون سهل الاستخدام للغاية ومتكاملاً تمامًا في الوقت ذاته.

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