How to do it...

To add the configuration options, follow the given steps:

  1. To add the needed dependency and the new XML data files, edit the __manifest__.py file like this and check that it depends on base_setup:
{  'name': 'Cookbook code', 
    'category': 'Library', 
    'depends': ['base_setup'], 
    'data': [ 
        'security/ir.model.access.csv', 
        'security/groups.xml', 
        'views/library_book.xml', 
        'views/res_config_settings.xml', 
    ], 
} 
  1. To add the new security group that's used for feature activation, edit the security/library_book.xml file and add the following record to it:
    <record id="group_release_dates" model="res.groups"> 
        <field name="name">Library: release date feature</field> 
        <field name="category_id" ref="base.module_category_hidden" /> 
    </record> 
  1. To make the book-release date visible only when this option is enabled, edit the field definition in the models/library_book.py file:
class LibraryBook(models.Model): 
    # ... 
    date_release = fields.Date( 
        'Release Date',  
        groups='my_library.group_release_dates',
)
  1. Edit the models/__init__.py file to add a new Python file for the configuration settings model:
from . import library_book 
from . import res_config_settings 
  1. To extend the core configuration wizard by adding new options to it, add the models/res_config_settings.py file with this code:
from odoo import models, fields 
 
class ConfigSettings(models.TransientModel): 
    _inherit = 'res.config.settings' 
    group_release_dates = fields.Boolean( 
            "Manage book release dates", 
            group='base.group_user', 
            implied_group='my_library.group_release_dates',
) module_note = fields.Boolean("Install Notes app")
  1. To make the options available in the UI, add views/res_config_settings.xml, which extends the form view:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_general_config_library" model="ir.ui.view">
<field name="name">Configuration: add Library options</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="business_documents" position="before">
<h2>Library</h2>
<div class="row mt16 o_settings_container">
<!-- Release Dates option -->
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="group_release_dates" class="oe_inline"/>
</div>
<div class="o_setting_right_pane">
<label for="group_release_dates"/>
<div class="text-muted">
Enable relase date feature on books
</div>
</div>
</div>
<!-- Release Dates option -->
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="module_note" class="oe_inline"/>
</div>
<div class="o_setting_right_pane">
<label for="module_note"/>
<div class="text-muted">
Install note module
</div>
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>

After upgrading the add-on module, the two new configuration options should be available at Settings|General Settings. The screen should look like this:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset