- 上传者: Administrator
- 上传时间:2023年11月19日 02时18分58秒
* Custom Settings ** *** The option to configure certain settings may occasionally be needed by the user. In Odoo, there are currently more settings ......
Custom Settings
The option to configure certain settings may occasionally be needed by the user. In Odoo, there are currently more settings options available. In this section, let's discuss how to add a custom setting for our custom module.
Consider a model that maintains a complete student record database for that. Some organizations might demand that you email them when a student is created. However, not all of them might require the same thing. Let's design a setting that allows us to choose whether to enable or disable the feature. To do that, first make a model to store student records and a module called education_organisation.
from odoo import fields, models
class Student(models.Model):
_name = "student.student"
_description = "Student"
name = fields.Char(string="Name", required=True)
phone = fields.Char(string="Phone Number")
email = fields.Char(string="Email", required=True)
The student model only adds the most fundamental fields. Now, in order to add a custom settings option, we want to inherit the res.config.settings model.
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
# mail send configurator
send_mail = fields.Boolean(string="Notify Student", default=True,
help="Check to Send a mail to Student on "
"creating a Student")
Under the Configuration menu, add a new menu called Settings and specify the action.
Action record
<record id="res_config_settings_menu_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' : education_organisation}</field>
</record>
One thing to remember when creating action record is the context. It is necessary to pass {'module' : education_organisation} in the context of action.
Now let's see how we can inherit the form view of res.config.settings to show the custom field.
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">
res.config.settings.view.form.inherit.organisation
</field>
<field name="model"> res.config.settings</field>
<field name="priority" eval="10"/>
<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="Edu Organisation" data-key="education_organisation"
string="Edu Organization">
<h2 groups="website.group_multi_website">Notify Student</h2 >
<div class="row mt16 o_settings_container" id="org_management" >
<div class="col-12 col-lg-6 o_setting_box" id="notify_student" >
<div class="o_setting_left_pane">
<field name="send_mail"/>
</div>
<div class="o_setting_right_pane" >
<label for="send_mail"/ >
<div class="text-muted" >
Check to Send a mail to Student on creating a Student
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
Adding the new boolean field to the form involves inheriting the current view. However, only our custom field will be visible under our menu when we access the view. You have to provide the model name to the data-key attribute in order to make this possible. If not, the same settings options that are displayed under the main settings option will be displayed.
The model res.config.settings is a transient model, so keep that in mind. That is, the data in the model are not database persistent. Therefore, we will need to create a few additional functions for storing and retrieving data for the view.
本文章从网上收集,如有侵权请联系tderp@tderp.com删除
- 微信扫一扫,一分也是爱:
服务原则及地区范围
宜兴通达网络科技有限公司,地处中国宜兴环科园内,是一家高新技术企业。公司在企业网络维护和企业信息化建设与咨询方面,有10多年经验。
我公司愿与客户一道,力求彻底解决客户问题!
我们不是在给企业提供“头痛医头、脚痛医脚”的暂时解决方案,而是在部署根本性安全与稳定服务!!
我们愿携手客户,建立企业IT规划;杜绝随意安装系统、软件等操作;力求共同维护有序、安全、稳定的网络办公环境!!!
IT服务,服务是根本,客户是上帝;我们提供快速响应、快速上门、快速排查,提供优质高效的服务!!!!
通达科技提供全国范围内的服务,服务形式包括远程协助、电话咨询、电子邮件咨询、传真咨询、问答平台的问题解决等。
宜兴地区提供上门服务:
- 市区服务:宜城街道、城北街道(屺亭街道)、新街街道、新庄街道、环科园、渚桥开发区
- 市郊服务:张渚镇、西渚镇、太华镇、徐舍镇、官林镇、杨巷镇、新建镇、和桥镇、高塍镇、万石镇、周铁镇、芳桥镇、丁蜀镇、湖父镇。