Skip to Content
Menu
This question has been flagged
2 Replies
3961 Views

Hi all, 

I am new to Odoo development. I was trying to make a custom setting tab for my module but it is not showing. Here is what I have done. My module is under zk_sandbox folder

  • Create a res_config_settings.py inherited from res.config.settings

from odoo import models, fields

class ResConfigSettings(models.TransientModel):    

_inherit = 'res.config.settings'
zk_sandbox_is_enabled = fields.Boolean(string='Enable Advanced Feature')


  • create a res_config_settings_views.xml 

<?xml version='1.0' encoding='utf-8'?>
<odoo>

<record id='res_config_settings_view_form' model='ir.ui.view'>
<field name='name'>res.config.settings.view.form.inherit.zk_sandbox</field>
<field name='model'>res.config.settings</field>
<field name='priority' eval='80'/>
<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="Library" string="Library" data-key="zk_sandbox" >
<h2>Library</h2>
<div class='row mt16 o_settings_container'>
<div class="col-12 col-lg-6 o_setting_box" title="Show organizational chart on employee form">
<div class="o_setting_left_pane">
<field name="zk_sandbox_is_enabled"/>
</div>
<div class="o_setting_right_pane">
<label for="zk_sandbox_is_enabled"/>
<div class="text-muted">
Is advanced feature enabled?
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>

<record id="library_config_settings_action" model="ir.actions.act_window">
<field name="name">Settings</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">res.config.settings</field>
<field name="view_id" ref="res_config_settings_view_form"/>
<field name="view_mode">form</field>
<field name="target">inline</field>
<field name="context">{'module' : 'zk_sandbox'}</field>
</record>

<menuitem name="Settings" id="library_book_setting_menu" parent="library_resources_configuration" action="library_config_settings_action" sequence="0"/>

</odoo>

  • library_resources_configuration is defined in another view xml file as 

    <menuitem id="library_resources_configuration" name="Configuration" parent="library_base_menu"/>


  • Reload the odoo-bin, upgrade the module. But I didn't see the configuration menu in my module also I didn't see the configuration tab for my little module in the general settings. I have not include the group permission in the view. Did I miss anything here? Thanks in advance. 


Avatar
Discard
Best Answer

Hello,

Firstly, fields on the res.config.settings model are different to every other model. Each field generally does one of five things:

  1. Stores a system value (What I assume you're trying to do). To do this, you need to use the config_parameter parameter in the field definition.

  2. Installs a module when ticked. To do this you need to call the field module_<module-name>

  3. Adds all users to a group when ticked. To do this you need to use the implied_group parameter in the field definition.

  4. Sets a field on another record, generally the current company or current website. This is handled by making the field a related.

  5. Sets the default value of a field on another model. To do this you need to call the field default_<field-name> and and add the default_model parameter on the field.

So you will likely need to update it to something like:

from odoo import models, fields

class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
    zk_sandbox_is_enabled = fields.Boolean(string='Enable Advanced Feature', config_parameter='zk_sandbox.enabled')

This can then be accessed in python by calling self.env['ir.config_parameter'].sudo().get_param('zk_sandbox.enabled').

As to why it isn't showing, I suspect it hasn't been imported in the data section of the manifest.

Cheers,
Jake

Avatar
Discard
Author Best Answer

Thanks a lot, Jake. That works for me. Thank you so much for the extra information about config_parameter. In my case, I forgot to add the view xml to the manifest. 

I now have another question. Now I have my config rendered next the other modules in the settings. I have a setting menu showing as well, but how do I point my own setting menu to my configuration tab? Currently when the setting menu is clicked inside my module, it opens the first tab of the system settings which is for another module. How do I link my setting menu to the settings of my module? 

Avatar
Discard

I'm not sure what the issue is there, by the looks of it you've done the two steps that are usually required for that to work (add a data-key in the view and a context to the action). I'd just make sure both of those are actually updated in the database (check in the technical menus views and window actions).

Author

Thanks Jake!! After checking, there is a typo in the data-key. Updating the data-key attribute solve my problem. Now it works properly. You saved my day!! Thank you.