Odoo Help


How to define custom settings on configuration view?

on 8/21/15, 12:06 PM 3,134 views

Hi guys,

I've created a new view which should always only allow one record, so I've made a view just like under Settings > Configuration.
1) Create a menu item

 <menuitem id="menu_tech_settings_screen"
                action="technical_details_odoo_installer_action" parent="server_main_menu"

2) Add an act_window behind it:

 <record id="technical_details_odoo_installer_action" model="ir.actions.act_window">
            <field name="name">Configure settings</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">odoo.environment.technical.settings</field>
            <field name="view_id" ref="configure_technical_settings_odoo_installer"/>
            <field name="view_mode">form</field>
            <field name="target">inline</field>

3) Create a view just like under Settings > Configuration > General Settings:

 <record id="configure_technical_settings_odoo_installer" model="ir.ui.view">
            <field name="name">Technical configuration</field>
            <field name="model">odoo.environment.technical.settings</field>
            <field name="arch" type="xml">
                <form string="Configure Sales" class="oe_form_configuration">
                        <button string="Apply" type="object" name="execute" class="oe_highlight"/>
                        <button string="Cancel" type="object" name="cancel" class="oe_link"/>
		<div name="configuration">
		        <field name="my_custom_field"/>

The view is being rendered fine but I'm now wondering how to proceed. How exactly can I store the new value when a user clicks on the Apply button? There should only be one record at all times and this is used to configure the rest on. I've inherited res.config.settings, created my own model and I have a get and set function for this. Example:

 class my_custom_class(models.Model):
    _name = 'my.custom.model'
    _inherit = 'res.config.settings'
    odoo_username = fields.Char('Ubuntu users password',help='Please fill in the password for the Ubuntu user that runs this Odoo. This password is needed to automatically install a new Odoo server through a shell script. Installing a new Odoo needs sudo rights!',required=True)

    def get_default_username(self, cr, uid, fields, context=None):
        odoo_username=self.pool.get('my.custom.model').browse(cr, uid, uid, context=context).odoo_username
        return {'odoo_username': odoo_username}

    def set_default_username(self, cr, uid, ids, context=None):
        config = self.browse(cr, uid, ids[0], context)
        self.pool.get('my.custom.model').write(cr, uid, uid, {'odoo_username': new_odoo_username})

The problem here is that this will still create a new record every time and I'm not sure if this is the correct behaviour for this type of view either.



Tarek Mohamed Ibrahim

--Tarek Mohamed Ibrahim--
| 5 3 7
Gîza, Egypt
--Tarek Mohamed Ibrahim--

I am an old VFP developer on ERP

I have moved to 2p since Nov-2014 and started developing with Python on Odoo.



Tarek Mohamed Ibrahim
On 8/28/15, 6:06 PM

I checked your code, but since I don't have much experience with inheriting res.config.settings I can't judge if this is not appropriate, or find a bug in it. 

Instead, I came up with a different solution, you don't need to inherit the settings class, you can create a new class for your setup purpose.

Code is below:

This is the class:

class my_custom_class(osv.osv):
    _name = 'my.custom.class'
    _description = 'my_custom_class'
    _columns = {


This is the view, along with the menu and the action

<record id="my_custom_class_view" model="ir.ui.view">
<field name="name">my.custom.class.view</field>
<field name="model">my.custom.class</field>
<field name="arch" type="xml">
<form string="my custom class" create="false" delete="false">
<field name="odoo_username" string="Odoo Username"/>
<record id="act_my_custom_class_view" model="ir.actions.act_window">
<field name="name">my.custom.class.view</field>
<field name="res_model">my.custom.class</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<!-- the following is a one record as initial data -->
<record id="my_custom_class_only_one_record" model="my.custom.class">
<field name="odoo_username">"test odoo user name"</field>

<menuitem action="act_my_custom_class_view" id="menu_act_my_custom_class_view" parent="some_module.some_parent_id" sequence="30"/>

Note that I tagged the view form with 

create="false" delete="false" 

so, no one can add or delete records to this view

I also furnished this class with one data record with initial value(s) user can starts with.

I hope this will help until we get some more experience with the res.config.settings, which is the standard for this purpose.

Thanks for your answer Tarek! I gave you a +1 since its another option and it would work but I honestly do not think this is the ideal way to do it.

on 9/1/15, 4:27 AM

I agree with you that this is not the ideal way, and for that I said that "I hope this will help until we get some more experience with the res.config.settings". This is a workaround, I do that when I'm pressed in time and need to deliver to the customer. When got the idea and there is an area to enhance, I provide the customer with the standard solution

Tarek Mohamed Ibrahim
on 9/1/15, 4:37 AM

Anil R. Kesariya

--Anil R. Kesariya--
| 7 6 8
Rajkot, India
--Anil R. Kesariya--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.

Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66

Anil R. Kesariya
On 9/1/15, 10:32 AM

HI Yenthe,

These solution might helps you.

1) Override create method of new model and search all the records created with new model and check length if  already having 1 than either raise warning or just return false instead of retuning result of super. this will stop user to creating more than 1 record in new model.

2) Apply create="false" and edit="false" in both tree and form view of new model. and create of actions todo with trigger your actions in that case open the form view in edit mode which will trigger once you install or upgrade module after adding this feature which will create record as you want than . after that user will not able to add any record inside as create & edit is false already.

Hope this might help.



Thanks for your answer Anil! While this is a way and it will work I can't imagine that this is the way to go. Sounds like a lot of hassle and code for such a little functionality.

on 9/1/15, 10:36 AM

@yenthe: If you don't want to show that record that user than don't create any action or view for that. Just create record in back end by automated actions as simple as that. But if you want to show that records in UI with different view and model than of course you have to create views and action for it.

Anil R. Kesariya
on 9/1/15, 1:02 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 8/21/15, 12:06 PM
Seen: 3134 times
Last updated: 9/1/15, 10:32 AM