Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

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

  • CRM
  • e-Commerce
  • Kế toán
  • Tồn kho
  • PoS
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

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

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
2 Trả lời
1611 Lượt xem
Ảnh đại diện
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
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Ray Carnes (ray)
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Euroservis S.r.l.
Tác giả

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.

Ảnh đại diện
Marc Durepos
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Euroservis S.r.l.
Tác giả

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.
Tác giả

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.
Tác giả

Thank you!

Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!

Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!

Đăng ký
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة 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 là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

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