如何在所有形式的odoo中隐藏"Create And Edit"按钮以及每行中的"Search More"按钮
How to hide "Create And Edit" button in all form odoo And also "Search More" Button in every line
我想隐藏所有形式的"Create and Edit"按钮
我还想以所有形式显示 "Search More" 按钮
我目前正在使用 odoo 10。
让我们看看这个插件
https://apps.openerp.com/apps/modules/9.0/web_m2x_options/
我试过使用那个插件,但它根本不起作用。
在这种情况下有人可以帮助我吗?无论是使用该插件,还是其他简单的方法来完成我需要做的事情。
如有任何回复,我将不胜感激。
提前致谢。
您可以将选择小部件带到您的字段中:
<field name="your_one2many_field" widget="selection"/>
要隐藏 "Create and edit" 使用:
<field name="your_one2many_field" options="{'no_create_edit':True}"/>
它可以用于所有模块。但是您需要在 ir.config.parameter 中创建一条记录。
配置 -> 技术 -> 参数 -> 系统参数
要删除 create_edit 按钮,您必须添加此信息。
密钥:"web_m2x_options.create_edit"
值:"false"。
要在任何 many2one 和 Many2many 字段上添加更多搜索,您必须添加。
密钥:"web_m2x_options.search_more"
值:"true".
PS:您可以在此 github 页面上查看更多信息 https://github.com/OCA/web/tree/9.0/web_m2x_options
在这里,我将更改 odoo 的默认行为以在我想要时显示创建和编辑
通过使用这个:
<field name="many2one_field" options="{'create':true, 'quick_create':true}"/>
现在在你的 costum 模块目录下定义一个 javascript 文件来更改 many2one 小部件
you_costum_module_directory_name
--> static
--> src
--> js
--> costum_many2one_widget.js
javascript 文件:
odoo.define('you_costum_module_directory_name.costum_many2one_widget' , function(require) {
// I hope that you know how to add this to odoo backendassets
// first we need core
var core = require('web.core');
// it's needed when we override get_search_result
var data = require('web.data');
// NOTE: i may forget to require some object in the code by mistake check it
// now we must get the many2one widget for form widget
var FieldMany2One = core.form_widget_registry.get('many2one');
// now we can override the method to change the behavor
FieldMany2one.include({
// if you want the search more to be always shown we must overrid
// get_search_result and we need to require every thing we need first like data object
// now to show search more always we must reimplement the
get_search_result: function(search_val) {
var self = this;
var dataset = new data.DataSet(this, this.field.relation, self.build_context());
this.last_query = search_val;
var exclusion_domain = [], ids_blacklist = this.get_search_blacklist();
if (!_(ids_blacklist).isEmpty()) {
exclusion_domain.push(['id', 'not in', ids_blacklist]);
}
return this.orderer.add(dataset.name_search(
search_val, new data.CompoundDomain(self.build_domain(), exclusion_domain),
'ilike', this.limit + 1, self.build_context())).then(function(_data) {
self.last_search = _data;
// possible selections for the m2o
var values = _.map(_data, function(x) {
x[1] = x[1].split("\n")[0];
return {
label: _.str.escapeHTML(x[1].trim()) || data.noDisplayContent,
value: x[1],
name: x[1],
id: x[0],
};
});
// show search more if there is only one element at least
// you can make it 0 if you want
if (values.length >= 1) {
values = values.slice(0, self.limit);
values.push({
label: _t("Search More..."),
action: function() {
dataset.name_search(search_val, self.build_domain(), 'ilike', 160).done(function(_data) {
self._search_create_popup("search", _data);
});
},
classname: 'o_m2o_dropdown_option'
});
}
// if the user provide an option quick_create show quick create
var raw_result = _(_data.result).map(function(x) {return x[1];});
if (
search_val.length > 0 &&
!_.include(raw_result, search_val) &&
self.options && self.options.quick_create
) {
self.can_create && values.push({
label: _.str.sprintf(_t('Create "<strong>%s</strong>"'),
$('<span />').text(search_val).html()),
action: function() {
self._quick_create(search_val);
},
classname: 'o_m2o_dropdown_option'
});
}
// if the user provide a create option show create and Edit option
if (self.options && self.options.create && self.can_create){
values.push({
label: _t("Create and Edit..."),
action: function() {
self._search_create_popup("form", undefined, self._create_context(search_val));
},
classname: 'o_m2o_dropdown_option'
});
}
else if (values.length === 0) {
values.push({
label: _t("No results to show..."),
action: function() {},
classname: 'o_m2o_dropdown_option'
});
}
return values;
});
}
});
// id don't know if this line is required or not
// but if we have to registre the widget again
core.form_widget_registry.add('many2one', FieldMany2One);
});
现在您需要将 js 文件添加到后端资产模板
you_costum_module_directory_name
--> static
--> src
--> js
--> costum_many2one_widget.js
--> xml
--> widgets.xml
添加 xml 文件到清单:
<?xml version="1.0" encoding="utf-8" ?>
<openerp> <!-- odoo in odoo 10.0 -->
<data>
<!--We need to load our js file to backend_assets-->
<template id="assets_backend" name="many2one new edits " inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/you_costum_module_directory_name/static/src/js/costum_many2one_widget.js"></script>
</xpath>
</template>
</data>
</openerp>
在您的清单 __openerp__.py
中添加 xml 文件:
我想隐藏所有形式的"Create and Edit"按钮
我还想以所有形式显示 "Search More" 按钮
我目前正在使用 odoo 10。
让我们看看这个插件
https://apps.openerp.com/apps/modules/9.0/web_m2x_options/
我试过使用那个插件,但它根本不起作用。
在这种情况下有人可以帮助我吗?无论是使用该插件,还是其他简单的方法来完成我需要做的事情。
如有任何回复,我将不胜感激。
提前致谢。
您可以将选择小部件带到您的字段中:
<field name="your_one2many_field" widget="selection"/>
要隐藏 "Create and edit" 使用:
<field name="your_one2many_field" options="{'no_create_edit':True}"/>
它可以用于所有模块。但是您需要在 ir.config.parameter 中创建一条记录。
配置 -> 技术 -> 参数 -> 系统参数
要删除 create_edit 按钮,您必须添加此信息。
密钥:"web_m2x_options.create_edit" 值:"false"。
要在任何 many2one 和 Many2many 字段上添加更多搜索,您必须添加。
密钥:"web_m2x_options.search_more" 值:"true".
PS:您可以在此 github 页面上查看更多信息 https://github.com/OCA/web/tree/9.0/web_m2x_options
在这里,我将更改 odoo 的默认行为以在我想要时显示创建和编辑 通过使用这个:
<field name="many2one_field" options="{'create':true, 'quick_create':true}"/>
现在在你的 costum 模块目录下定义一个 javascript 文件来更改 many2one 小部件
you_costum_module_directory_name
--> static
--> src
--> js
--> costum_many2one_widget.js
javascript 文件:
odoo.define('you_costum_module_directory_name.costum_many2one_widget' , function(require) {
// I hope that you know how to add this to odoo backendassets
// first we need core
var core = require('web.core');
// it's needed when we override get_search_result
var data = require('web.data');
// NOTE: i may forget to require some object in the code by mistake check it
// now we must get the many2one widget for form widget
var FieldMany2One = core.form_widget_registry.get('many2one');
// now we can override the method to change the behavor
FieldMany2one.include({
// if you want the search more to be always shown we must overrid
// get_search_result and we need to require every thing we need first like data object
// now to show search more always we must reimplement the
get_search_result: function(search_val) {
var self = this;
var dataset = new data.DataSet(this, this.field.relation, self.build_context());
this.last_query = search_val;
var exclusion_domain = [], ids_blacklist = this.get_search_blacklist();
if (!_(ids_blacklist).isEmpty()) {
exclusion_domain.push(['id', 'not in', ids_blacklist]);
}
return this.orderer.add(dataset.name_search(
search_val, new data.CompoundDomain(self.build_domain(), exclusion_domain),
'ilike', this.limit + 1, self.build_context())).then(function(_data) {
self.last_search = _data;
// possible selections for the m2o
var values = _.map(_data, function(x) {
x[1] = x[1].split("\n")[0];
return {
label: _.str.escapeHTML(x[1].trim()) || data.noDisplayContent,
value: x[1],
name: x[1],
id: x[0],
};
});
// show search more if there is only one element at least
// you can make it 0 if you want
if (values.length >= 1) {
values = values.slice(0, self.limit);
values.push({
label: _t("Search More..."),
action: function() {
dataset.name_search(search_val, self.build_domain(), 'ilike', 160).done(function(_data) {
self._search_create_popup("search", _data);
});
},
classname: 'o_m2o_dropdown_option'
});
}
// if the user provide an option quick_create show quick create
var raw_result = _(_data.result).map(function(x) {return x[1];});
if (
search_val.length > 0 &&
!_.include(raw_result, search_val) &&
self.options && self.options.quick_create
) {
self.can_create && values.push({
label: _.str.sprintf(_t('Create "<strong>%s</strong>"'),
$('<span />').text(search_val).html()),
action: function() {
self._quick_create(search_val);
},
classname: 'o_m2o_dropdown_option'
});
}
// if the user provide a create option show create and Edit option
if (self.options && self.options.create && self.can_create){
values.push({
label: _t("Create and Edit..."),
action: function() {
self._search_create_popup("form", undefined, self._create_context(search_val));
},
classname: 'o_m2o_dropdown_option'
});
}
else if (values.length === 0) {
values.push({
label: _t("No results to show..."),
action: function() {},
classname: 'o_m2o_dropdown_option'
});
}
return values;
});
}
});
// id don't know if this line is required or not
// but if we have to registre the widget again
core.form_widget_registry.add('many2one', FieldMany2One);
});
现在您需要将 js 文件添加到后端资产模板
you_costum_module_directory_name
--> static
--> src
--> js
--> costum_many2one_widget.js
--> xml
--> widgets.xml
添加 xml 文件到清单:
<?xml version="1.0" encoding="utf-8" ?>
<openerp> <!-- odoo in odoo 10.0 -->
<data>
<!--We need to load our js file to backend_assets-->
<template id="assets_backend" name="many2one new edits " inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/you_costum_module_directory_name/static/src/js/costum_many2one_widget.js"></script>
</xpath>
</template>
</data>
</openerp>
在您的清单 __openerp__.py
中添加 xml 文件: