Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profit organisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

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

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
settingssaveodoo12.0
2 Antwoorden
33340 Weergaven
Avatar
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
Avatar
Annuleer
Niyas Raphy (Walnut Software Solutions)

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

Avatar
Haresh Kansara
Beste antwoord

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
Avatar
Annuleer
Paulo Matos
Auteur

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
Auteur

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

Avatar
rabeb246
Beste antwoord

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


0
Avatar
Annuleer
Zahid Mehmood

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

Add config_parameter this parameter in the field definition

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Value in own settings is not stored
settings value save
Avatar
0
mrt. 15
4252
Can't fix Error On Save in Settings: Invalid Fields Opgelost
settings error invalid save
Avatar
Avatar
2
jul. 24
9785
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
Avatar
Avatar
Avatar
2
okt. 25
1945
USUARIO DE LECTURA - ODOO
settings
Avatar
Avatar
Avatar
2
sep. 25
724
Fiscal localizations
settings
Avatar
Avatar
2
apr. 25
10950
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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