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ợ

An error occurs in odoo 17 at the python code level, when trying to query a related field of the Many2one type

Đă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ờ
odooodoo17odoo17EE
2494 Lượt xem
Ảnh đại diện
yorlysoro
An error appears in odoo 17 at the python code level, when trying to 
query a related field type Many2one, this field is recognized as False 
or empty, even though it is queried at the SQL database level, this same
 shows that the field is saved at the database level, but when trying to
 query at the odoo ORM level, it is shown as empty or False, this error 
also causes an access error, where it is indicated that the user does 
not have access to it, but these permissions are already placed in the 
corresponding user, at the graphical interface level the field is shown 
as full, the user can enter it normally from the graphical interface, 
the code has been inspected, and how the field is being declared and it 
does not have security restrictions, I show below the code that carries 
out the process:

from odoo import SUPERUSER_ID, fields, models, api import random import string import logging _logger = logging.getLogger(__name__) class CreateFinancialReport(models.TransientModel): _name = "create.financial.report" _description = "Create Financial Report" name = fields.Char() company_id = fields.Many2one("res.company", default=lambda self: self.env.company) type = fields.Selection( [("balance", "Balance"), ("profit_loss", "Profit and Loss"), ("all", "All")] ) def create_financial_report(self): self.env['ir.rule'].clear_caches() financial_report = self.with_user(SUPERUSER_ID).env["account.report"].create( { "name": self.name + " / " + self.company_id.name, "filter_date_range": True, "filter_period_comparison": True, "filter_growth_comparison": True, "filter_unfold_all": True, "filter_journals": True, "filter_analytic": True, "filter_multi_company": 'selector', } ) financial_report.column_ids = [(0, 0, { "name": "Balance", "expression_label": "balance", })] sql = """ select id from account_account where company_id= %s """ if self.type == "balance": sql += " and code between '1' and '399999999999' " elif self.type == "profit_loss": sql += " and code between '4' and '699999999999' " sql += " order by code , company_id " self.with_user(SUPERUSER_ID)._cr.execute(sql, [self.company_id.id]) values = self.with_user(SUPERUSER_ID)._cr.fetchall() self_line = self.with_user(SUPERUSER_ID).env["account.report.line"] msg = "Values: " + str(values) _logger.info(msg) for value in values: _logger.info("Value: " + str(value)) account = self.with_user(SUPERUSER_ID).with_company(self.company_id.id).env["account.account"].search([("id", "=", value[0]), ('company_id', '=', self.company_id.id)]) account_parent = account.sudo().parent_id account_parent = self.with_user(SUPERUSER_ID).with_company(self.company_id.id).env["account.account"].search([("id", "=", account_parent.id), ('company_id', '=', self.company_id.id)]) _logger.info("Account: " + str(account)) if account: if account.name and account.code: name = account.code + " " + account.name elif account.name: name = account.name else: name = account.code if account.parent_id: _logger.info("Whit child lines IDS") _logger.info("Account Parent: " + str(account_parent)) old_line = self_line.with_user(SUPERUSER_ID).search( [ ("code", "=", account_parent.code), ("report_id", "=", financial_report.id), ], limit=1, ) line = self_line.with_user(SUPERUSER_ID).create( { "name": name, "report_id": financial_report.id, "parent_id": old_line.id, "code": account.code, "hide_if_zero": True, } ) if account and account.account_type in ( 'income', 'liability_current', 'liability_credit_card', 'liability_non_current', 'equity_unaffected', 'income_other', 'equity', 'off_balance', ): line.with_user(SUPERUSER_ID).expression_ids = [( 0, 0, { 'label': 'balance', 'engine': 'aggregation', 'formula': '-sum', } )] else: line.expression_ids = [( 0, 0, { 'label': 'balance', 'engine': 'aggregation', 'formula': 'sum', } )] else: _logger.info("Parent ID is None") self_line.with_user(SUPERUSER_ID).create( { "report_id": financial_report.id, "name": name, "code": account.code, "hide_if_zero": True, } ) level = 1 for line in financial_report.line_ids: _logger.info("Line ID: " + str(line.id)) self.with_user(SUPERUSER_ID).set_data_to_line(line, level) def set_data_to_line(self, line, level): line.hierarchy_level = level level += 1 _logger.info("Line with children IDS: " + str(line.children_ids)) if line.children_ids: sql_sum = """ select string_agg(CONCAT(code, '.balance'), '+') from account_report_line where parent_id = %s """ self._cr.execute(sql_sum, [line.id]) value_sum = self._cr.fetchall() report_expression = self.env['account.report.expression'].search([('report_line_id', '=', line.id)]) for expression in report_expression: expression.with_user(SUPERUSER_ID).write({ 'engine': 'aggregation', 'formula': value_sum[0][0], 'blank_if_zero': True, }) for child in line.children_ids: self.set_data_to_line(child, level) line.with_user(SUPERUSER_ID).groupby = "account_id" else: if line.parent_id.code: report_expression = self.env['account.report.expression'].search( [('report_line_id', '=', line.id)]) for expression in report_expression: expression.with_user(SUPERUSER_ID).write({ 'engine': 'domain', 'formula': "[('account_id.code', '=', " + "'" + line.code + "'" + ")]", 'blank_if_zero': True, 'subformula': 'sum', }) line.with_user(SUPERUSER_ID).groupby = "account_id"

In the case of if account.parent_id, the code enters the if, indicating that the field is full, but when you try to perform the query to obtain the


account_parent, account_parent = self.with_user(SUPERUSER_ID).with_company(self.company_id.id).env["account.account"].search([("id", "=", account.parent_id.id),
    ('company_id', '=', self.company_id.id)])

This returns empty and prevents the code from continuing to function normally. It also happens that when trying to enter a specific field such as account_parent.code or account_parent.name, an access error occurs as if the user had been assigned the permissions. The permissions and registration rules have already been verified and are placed correctly.

What is required is to be able to access the different fields of this model to be able to generate the financial reports with their own formulas?

0
Ảnh đại diện
Huỷ bỏ
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ý
Bài viết liên quan Trả lời Lượt xem Hoạt động
How to create a dynamic domain in Odoo 17? Đã xử lý
odoo odoo17
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
3
thg 3 25
4218
How to Change the Error Dialog Box, Odoo Title Name, and Odoo Server Name?
odoo odoo17
Ảnh đại diện
0
thg 3 25
2273
How to create a custom discard button?
odoo odoo17
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
4
thg 1 25
3563
'\n' new line option not working in UserError in Odoo 17
odoo odoo17
Ảnh đại diện
Ảnh đại diện
1
thg 11 24
3448
Send notification to specific users Đã xử lý
odoo17 Odoo17 odoo17EE
Ảnh đại diện
Ảnh đại diện
2
thg 9 25
1132
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