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ợ

Problems on saving data to "res.config.settings" in Odoo 12

Đă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ờ
settingssaveodoo12.0
2 Trả lời
33343 Lượt xem
Ảnh đại diện
Paulo Matos

Dear all,

I am having a problem on Odoo v12 on saving data on "res.config.settings" model.

I have inherited the model and defined my custom fields:

       class ResConfigSettings(models.TransientModel):
           _inherit = ['res.config.settings']
           #My custom fields
           my_custom_field1_id = fields.Many2one('res.partner', string='For Customer')
           my_custom_field2_id = fields.Many2one('res.partner', string='For Supplier')

The above code is the only code I have on the module .py.

For the UI I have inherited the "res_config_settings_view_form" on the corresponding XML file.

      <record id="res_config_settings_mymodule_form" model="ir.ui.view">
      <field name="name">Config Settings for My Module</field>
      <field name="model">res.config.settings</field>
      <field name="priority" eval="90"/>
      <field name="inherit_id" ref="base.res_config_settings_view_form"/>
      <field name="arch" type="xml">
           <xpath expr="//div[hasclass('settings')]" position="inside">
           <div class="app_settings_block" data-string="MyModule" string="MyModule" data-key="mymodule" groups="account.group_account_manager">
           <t groups="account.group_account_user">
                <h2>My Module Defaults</h2>
                <div class="row mt16 o_settings_container">
                <div class="col-12 col-lg-6 o_setting_box" title="These values are default values the module">
                <div class="o_setting_left_pane">
                </div>
                     <div class="o_setting_right_pane">
                     <span class="o_form_label">Default Data</span>
                     <span class="fa fa-lg fa-building-o" title="Values set here are company-specific." aria-label="Values set here are company-specific." groups="base.group_multi_company" role="img"/>
                     <div class="text-muted">
                     Default values for module
                     </div>
                     <div class="content-group">
                     <div class="row mt16">
                          <label string="Customer" for="my_custom_field1_id" class="col-lg-3 o_light_label"/>
                          <field name="my_custom_field1_id" domain="[('customer', '=', 'True'), ('company_id', '=', company_id)]"/>
                     </div>
                     <div class="row mt16">
                          <label string="Supplier" for="my_custom_field2_id" class="col-lg-3 o_light_label"/>
                          <field name="my_custom_field2_id" domain="[('supplier', '=', 'True'), ('company_id', '=', company_id)]"/>
                     </div>
                     </div>
                     </div>
                     </div>
                     </div>
           </t>
           </div>
           </xpath>
      </field>
      </record>

Everything seems to be working fine and I get no errors and I can see the new "app_settings_block" created for My Module with both new fields and they work for the domain I set for each field.

The problem I have is that when I set a value to any of the fields and click on the "Save" button, the data is simple not saved into the database.

I am sure I am working with correct user/group and have full access to the system.

What could be the problem?

Any idea?

Thank you all in advance

Best regards

Paulo


5
Ảnh đại diện
Huỷ bỏ
Niyas Raphy (Walnut Software Solutions)

https://www.youtube.com/watch?v=MsVoYPQ4-J4

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

Hello Paulo,

The General Settings (res.config.settings) data is not directly save on Save button click, you need to set setter-getter method to manage this field's data. These data are store in config parameter and fetch from this config parameter.

You are doing all perfect, but add bellow code in your python file:

from odoo import api, fields, models, modules

class ResConfigSettings(models.TransientModel):
    _inherit = ['res.config.settings']

    #My custom fields
    my_custom_field1_id = fields.Many2one('res.partner', string='For Customer')
    my_custom_field2_id = fields.Many2one('res.partner', string='For Supplier')

    @api.model
    def get_values(self):
        res = super(ResConfigSettings, self).get_values()
        res.update(
            my_custom_field1_id = self.env['ir.config_parameter'].sudo().get_param('your_custom_module_name.my_custom_field1_id'),
            my_custom_field2_id = self.env['ir.config_parameter'].sudo().get_param('your_custom_module_name.my_custom_field2_id'),
        )
        return res

    @api.multi
    def set_values(self):
        super(ResConfigSettings, self).set_values()
        param = self.env['ir.config_parameter'].sudo()

        field1 = self.my_custom_field1_id and self.my_custom_field1_id.id or False
        field2 = self.my_custom_field2_id and self.my_custom_field2_id.id or False

        param.set_param('your_custom_module_name.my_custom_field1_id', field1)
        param.set_param('your_custom_module_name.my_custom_field2_id', field2)


Hope it will helpful for you.

Thanks and regards

Haresh Kansara

9
Ảnh đại diện
Huỷ bỏ
Paulo Matos
Tác giả

Dear @Haresh,

Thank you very much for your asnwer.

It helps me to better understand how "res.config.settings" works.

Anyway, I'm having a problem with the "set_values()" function you provided on your sample code and need your help on fixing it.

I am testing your code with only "my_custom_field1" from the code on my question.

After testing it, only with the "get_values()" function, I can see on the postgresql database table "res_config_setting" that the ID for the selected partner is correctly set.

In my case, the id is "7".

When I "activate" the "set_values()" function, I am getting the below error:

"Database fetch misses ids (('7',)) and has extra ids ((7,)), may be caused by a type incoherence in a previous request"

In fact this ids "7" from the error is the same id for the selected partner and I believe it's something related with data type.

Tested with other partners and the error id is always equal to the id of the selected partner.

Can you please help fixe this?

Thank you in advance

Best regards

Paulo

Paulo Matos
Tác giả

Dear @Haresh,,

I have found the issue.

I had to convert the result into an integer since it receives a char result.

I have changed the code for "get_values()" function to:

my_custom_field1_id = int(self.env['ir.config_parameter'].sudo().get_param('your_custom_module_name.my_custom_field1_id')),

By convert the result to an integer (int()) value it's working as expected.

Thank you once again

Best regards

Paulo

CARLOS ALBERTO GARCIA BRIZUELA

Excellent solution, works great for me!

Thanks a lot

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

editor doesn't save the content when I press "Save" odoo14???????


0
Ảnh đại diện
Huỷ bỏ
Zahid Mehmood

field_name = fields.Integer('Field String',config_parameter="field_name")

Add config_parameter this parameter in the field definition

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
Value in own settings is not stored
settings value save
Ảnh đại diện
0
thg 3 15
4252
Can't fix Error On Save in Settings: Invalid Fields Đã xử lý
settings error invalid save
Ảnh đại diện
Ảnh đại diện
2
thg 7 24
9786
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
2
thg 10 25
1945
USUARIO DE LECTURA - ODOO
settings
Ảnh đại diện
Ảnh đại diện
Ảnh đại diện
2
thg 9 25
724
Fiscal localizations
settings
Ảnh đại diện
Ảnh đại diện
2
thg 4 25
10951
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