Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How can I save/load my own configuration/settings

Subscribe

Get notified when there's activity on this post

This question has been flagged
configurationsettingsres_config
6 Replies
40306 Views
Avatar
Stefan Reisich

Hello,

how can I save and load my own configuration/settings. And create my own section in Settings -> Configuration? How can I load this saved settings?

I want save a URL, a user name and a password needed for my module...

image description

Thank you very much.

6
Avatar
Discard
Avatar
Simplify it!
Best Answer

To add a configuration page you have to do this:

from openerp.osv import fields, osv 

class custom_config_settings(osv.osv_memory):

    _name = 'custom.config.settings'
    _inherit = 'res.config.settings'
    _columns = {
        'username': fields.char('Username', size=48),
    }
    _defaults = {
        'username': ""
    }

    def get_default_username(self, cr, uid, fields, context=None):
        #some code... 
        #you can get the field content from some table and return it
        #as a example
        user_name=self.pool.get('res.users').browse(cr, uid, uid, context=context).name
        return {'username': user_name}

    def set_default_username(self, cr, uid, ids, context=None):
        #some code... 
        #you can get the field content from some table and return it
        #as a example
        config = self.browse(cr, uid, ids[0], context)
        new_username=config.username
        self.pool.get('res.users').write(cr, uid, uid, {'name': new_username})

And the view:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
    <record id="view_custom_config_settings" model="ir.ui.view">
        <field name="name">custom settings</field>
        <field name="model">custom.config.settings</field>
        <field name="arch" type="xml">
            <form string="Configure Accounting" version="7.0" class="oe_form_configuration">
                <header>
                    <button string="Apply" type="object" name="execute" class="oe_highlight"/>
                    or
                    <button string="Cancel" type="object" name="cancel" class="oe_link"/>
                </header>
                <field name="username"/>
            </form>
        </field>
    </record>

    <record id="action_custom_config" model="ir.actions.act_window">
        <field name="name">Custom Settings</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">custom.config.settings</field>
        <field name="view_mode">form</field>
        <field name="target">inline</field>
    </record>

    <menuitem id="menu_custom_config" name="Custom Settings" parent="base.menu_config"
        sequence="16" action="action_custom_config"/>

    </data>
</openerp>

This is only an example.

The config page works because when you open the configuration page all the "get_" functions will be called. And when you save it all the "set_" functions are going to run.

I hope this can help you.

EDIT

Taken from OpenERP docs:

Base configuration wizard for application settings. It provides support for setting default values, assigning groups to employee users, and installing modules. To make such a 'settings' wizard, define a model like::

        class my_config_wizard(osv.osv_memory):
            _name = 'my.settings'
            _inherit = 'res.config.settings'
            _columns = {
                'default_foo': fields.type(..., default_model='my.model'),
                'group_bar': fields.boolean(..., group='base.group_user', implied_group='my.group'),
                'module_baz': fields.boolean(...),
                'other_field': fields.type(...),
            }

The method execute provides some support based on a naming convention:

*   For a field like 'default_XXX', ``execute`` sets the (global) default value of
    the field 'XXX' in the model named by ``default_model`` to the field's value.

*   For a boolean field like 'group_XXX', ``execute`` adds/removes 'implied_group'
    to/from the implied groups of 'group', depending on the field's value.
    By default 'group' is the group Employee.  Groups are given by their xml id.

*   For a boolean field like 'module_XXX', ``execute`` triggers the immediate
    installation of the module named 'XXX' if the field has value ``True``.

*   For the other fields, the method ``execute`` invokes all methods with a name
    that starts with 'set_'; such methods can be defined to implement the effect
    of those fields.

The method ``default_get`` retrieves values that reflect the current status of the
fields like 'default_XXX', 'group_XXX' and 'module_XXX'.  It also invokes all methods
with a name that starts with 'get_default_'; such methods can be defined to provide
current values for other fields.
13
Avatar
Discard
Atchuthan - Technical Consultant, Sodexis Inc

@Grover, in many configuration settings available in OpenERP, most of the field does not have get or set function with it

For instance take sales configuration, `module_sale_analytic_plans,

Simplify it!

Of course, but it depends on what you are trying to do: If field name starts with module_ that means that it's going to install that module. It's not an ordinary boolean. I've edited the answer. Hope it helps

Atchuthan - Technical Consultant, Sodexis Inc

@thanks Grover, your description was helpful

Avatar
Iwan Dermawan
Best Answer

Please help,

why in my configurations, new record added after Apply button clicked not updated last config data (reload record succesfull display in form)

1
Avatar
Discard
Avatar
Thierry Godin
Best Answer

Hello,

Your configuration will be saved while you're making backup of your database.

Regards

-2
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
res_config.py error Solved
configuration settings xml res_config
Avatar
Avatar
1
May 15
6174
disable delete and edit options in conversations Odoo 15
configuration settings
Avatar
Avatar
Avatar
2
Apr 24
5287
In res_config.py why odoo cannot find a field that is already defined? Solved
settings res_config
Avatar
Avatar
1
May 15
6347
What are the things to watch out for before my OpenERP goes live? Version 7.
configuration settings
Avatar
0
Mar 15
8145
Reserve Profit and Loss Account
configuration settings
Avatar
Avatar
1
Mar 15
7455
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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