Defining custom settings in Odoo
Unfortunately Odoo documentation doesn’t seem to include any information about adding new configuration options to Odoo. So let’s fill in the gaps.
Defining a model
First of all, you need to define a new model inheriting from res.config.settings
:
class YourSettings(models.TransientModel):
_inherit = 'res.config.settings'
_name = 'your.config.settings'
It’s a TransientModel
, also known as a wizard. Do not expect it to permanently hold the values. TransientModels inherently store values on a temporary basis only. You need other means to make them permanent.
Fortunately res.config.settings
makes this easy. First of all, you need to add some fields to your TransientModel
- one for every setting option you want to define. Odoo comes with built-in support for four different kinds of settings. It distinguishes between them based on the field names.
“Default” settings
The value of a field named default_foo
will be set as a default value for a field namedfoo
on a model given as a default_model
argument.
class YourSettings(models.TransientModel):
_inherit = 'res.config.settings'
_name = 'your.config.settings'
default_name = fields.Char(default_model='your.other.model')
This will make the value of default_name
field the global default value of a field name
in model your.other.model
.
“Group” settings
Boolean fields named group_foo
take two arguments: group
(defaults tobase.group_user
) and implied_group
. If the value of such field is true, the group defined in group
gain all implied_group
’s permissions. This is exactly the same as adding a group to implied_ids
field on another group’s object (which as far as I know is also an undocumented feature). This is useful for controlling which groups of users have access to a feature.
class YourSettings(models.TransientModel):
_inherit = 'res.config.settings'
_name = 'your.config.settings'
group_kill = fields.Boolean(
group='your.secret_agents',
implied_group='your.licence_to_kill'
)
“Module” settings
Boolean fields named module_foo
, when enabled will trigger installation of a module named foo
.
class YourSettings(models.TransientModel):
_inherit = 'res.config.settings'
_name = 'your.config.settings'
# if enabled will install "spies" module
module_spies = fields.Boolean()
Other settings
By default the values of other fields will be discarded, but you change that by implementing your own means of saving them. Just define a method named set_foo
(where foo
is an arbitrary string). You can also set initial values of such fields using aget_default_foo
method (the exact form of foo
is once again irrelevant).
For example if you want to use settings to control the name and phone number of a company linked to the current user:
class YourSettings(models.TransientModel):
_inherit = 'res.config.settings'
_name = 'your.config.settings'
company_name = fields.Char()
company_phone = fields.Char()
@api.model
def get_default_company_values(self, fields):
"""
Method argument "fields" is a list of names
of all available fields.
"""
company = self.env.user.company_id
return {
'company_name': company.name,
'company_phone': company.phone,
}
@api.one
def set_company_values(self):
company = self.env.user.company_id
company.name = self.company_name
company.phone = self.company_phone
Defining a view
Then you just need to define a view for your settings. Let’s use the previous example:
<record id="your_configuration" model="ir.ui.view">
<field name="name">Your configuration</field>
<field name="model">your.config.settings</field>
<field name="arch" type="xml">
<form string="Your configuration" class="oe_form_configuration">
<header>
<button string="Save" type="object"
name="execute" class="oe_highlight"/>
or
<button string="Cancel" type="object"
name="cancel" class="oe_link"/>
</header>
<group string="Company">
<label for="id" string="Name & Phone"/>
<div>
<div>
<label for="company_name"/>
<field name="company_name"/>
</div>
<div>
<label for="company_phone"/>
<field name="company_phone"/>
</div>
</div>
</group>
</form>
</field>
</record>
<record id="your_settings_action" model="ir.actions.act_window">
<field name="name">Your configuration</field>
<field name="res_model">your.config.settings</field>
<field name="view_id" ref="your_configuration"/>
<field name="view_mode">form</field>
<field name="target">inline</field>
</record>
…and of course don’t forget to make a new entry in the settings menu:
<menuitem id="your_settings_menu" name="Your settings"
parent="base.menu_config" action="your_settings_action"/>
原文链接:http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html
Defining custom settings in Odoo的更多相关文章
- salesforce 零基础学习(四十)Custom Settings简单使用
有时候,项目中我们需要设置类似白名单的功能,即某些用户或者某种Profile的用户不走一些校验或者走一些校验,这时,使用Custom Settings功能可以很好的解决这一需求. Custom Set ...
- Material Design系列第六篇——Defining Custom Animations
Defining Custom Animations //自定义动画 This lesson teaches you to //本节课知识点 Customize Touch Feedback //1. ...
- Custom Settings.ini 和 bootstrap.ini 配置
[Settings]Priority=DefaultProperties=MyCustomProperty [Default] ;SkipWizard=YES 如果跳过部署向导,则即使 SkipCap ...
- Custom Settings.in 配置信息收集
[Settings] Priority=Default Properties=MyCustomProperty [Default] ;是否允许部署操作系统到目标计算机 OSInstall=YES ;是 ...
- Creating Apps With Material Design —— Defining Custom Animations
转载请注明 http://blog.csdn.net/eclipsexys 翻译自Developer Android,时间仓促,有翻译问题请留言指出.谢谢 定义动画 在材料设计动画让用户与您的应用程序 ...
- [VSCode] Custom settings
{ // UI IMPROVEMENTS —————————————————— // Part 1. "editor.minimap.enabled": false, " ...
- odoo配置界面设置字段默认值
转自国外牛人博客:http://ludwiktrammer.github.io/odoo/custom-settings-odoo.html Defining custom settings in O ...
- 配置ubuntu 16.04.1 LTS odoo 10.0开发环境
使用VMware Fusion 8.5.0创建ubuntu 64bit虚拟机:使用ubuntu-16.04.1-desktop-amd64.iso镜像缺省安装ubuntu,用户名odoo,密码1234 ...
- Access Editor Settings 访问编辑器设置
This topic demonstrates how to access editors in a Detail View using a View Controller. This Control ...
随机推荐
- Android系统介绍与框架(转)
一.Andriod是什么? Android系统是Google开发的一款开源移动OS,Android中文名被国内用户俗称“安卓”.Android操作系统基于Linux内核设计,使用了Google公司自己 ...
- c文件操作 (转)
文件文件的基本概念 所谓“文件”是指一组相关数据的有序集合. 这个数据集有一个名称,叫做文件名. 实际上在前面的各章中我们已经多次使用了文件,例如源程序文件.目标文件.可执行文件.库文件 (头文件)等 ...
- loj 1002(spfa变形)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=25828 题意:求所有点到给定的目标顶点的路径上的权值的最大值的最小 ...
- 数据分析(4):Scipy
科学计算 最小二乘leastsq # -*- coding: utf-8 -*- def func(x,p): # p 参数列表 A,k,theta = p; # 可以一一对应赋值 return A* ...
- 【T_SQL】 基础 事务
1.使用 T-SQL 语句来管理事务 开始事务:BEGIN TRANSACTION 提交事务:COMMIT TRANSACTION 回滚(撤销)事务:ROLLBAC ...
- Servlet请求头response应用简单案例
Servlet请求头response应用简单案例:访问AServlet重定向到BServlet,5秒后跳到CServlet,并显示图片: AServlet package cn.yzu; import ...
- hdu3496 二维01背包
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=3496 //刚看题目以为是简单的二维01背包,but,,有WA点.. 思路:题中说,只能买M ...
- SPOJ PHRASES 后缀数组
题目链接:http://www.spoj.com/problems/PHRASES/en/ 题意:给定n个字符串,求一个最长的子串至少在每个串中的不重叠出现次数都不小于2.输出满足条件的最长子串长度 ...
- POJ 1509 最小表示法
题目链接:http://poj.org/problem?id=1509 题意:给定一个字符串,求一个起点使字符串从该起点起的字符串字典序最小[题目的字符串起点从1开始] 思路:最小表示法模板题 #de ...
- testng.xml文件结构组成及节点属性说明
TestNG的DTD检查文件:http://testng.org/testng-1.0.dtd.PHP 更多testng配置及说明,请移步http://testdoc.org/docmaster?pi ...