如何在自定义模块中更改文字'添加项目'到'添加新行"?
任何简单的解决方案?
答案 0 :(得分:2)
Hello指针,
请尝试以下代码,
your_module_name /视图/ custome_file_include.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!-- Include External/Custom/Own JS File. And Order Maintain. -->
<script type="text/javascript" src="/your_module_name/static/src/js/custome_file_include.js"></script>
<script type="text/javascript" src="/your_module_name/static/src/js/custome_view_form.js"></script>
</xpath>
</template>
</data>
</openerp>
your_module_name / SRC / JS / custome_file_include.js
openerp.fm_sale_order_ext_ept = function(instance) {
change_tree_view_add_item_name(instance);
}
your_module_name / SRC / JS / custome_view_form.js
function change_tree_view_add_item_name(instance) {
instance.web.form.AddAnItemList.include({
pad_table_to: function (count) {
if (!this.view.is_action_enabled('create') || this.is_readonly()) {
this._super(count);
return;
}
this._super(count > 0 ? count - 1 : 0);
var self = this;
var columns = _(this.columns).filter(function (column) {
return column.invisible !== '1';
}).length;
if (this.options.selectable) { columns++; }
if (this.options.deletable) { columns++; }
var $cell = $('<td>', {
colspan: columns,
'class': this._add_row_class || ''
}).html(
$('<a>', {href: '#'}).text(_t("Add new row"))
.mousedown(function () {
// FIXME: needs to be an official API somehow
if (self.view.editor.is_editing()) {
self.view.__ignore_blur = true;
}
})
.click(function (e) {
e.preventDefault();
e.stopPropagation();
// FIXME: there should also be an API for that one
if (self.view.editor.form.__blur_timeout) {
clearTimeout(self.view.editor.form.__blur_timeout);
self.view.editor.form.__blur_timeout = false;
}
self.view.ensure_saved().done(function () {
self.view.do_add_record();
});
}));
var $padding = this.$current.find('tr:not([data-id]):first');
var $newrow = $('<tr>').append($cell);
if ($padding.length) {
$padding.replaceWith($newrow);
} else {
this.$current.replaceWith($newrow)
}
}
});
}
首先我们创建新模块,下面给出的是新模块的文件结构。
Module_Name
static
src
js
File_Name.js
views
File_Name.xml
__openerp__.py
Module_Name-&GT;&则须─GT; File_Name.xml
现在我们在基础odoo 9模块中添加custome js,这样我们就可以创建xml文件并继承基本文件并添加我们的客户js,
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!-- Include External/Custom/Own JS File. And Order Maintain. -->
<script type="text/javascript" src="/Module_Name/static/src/js/File_Name.js"></script>
</xpath>
</template>
</data>
</openerp>
Module_Name-&GT; static-&GT; SRC-&GT; js-&GT; File_Name.js
现在我们继承了form_relation_widget.js js并修改了这个方法,
odoo.define('Module_Name.File_Name', function (require) {
"use strict";
var core = require('web.core');
var ListView = require('web.ListView');
var _t = core._t;
var _lt = core._lt;
// Include "web.form_relational"
var form_relational = require('web.form_relational');
// Include X2ManyList Functionality and Modify X2ManyList Functionality
var form_relational = form_relational.X2ManyList.include({
pad_table_to: function (count) {
if (!this.view.is_action_enabled('create') || this.view.x2m.get('effective_readonly')) {
this._super(count);
return;
}
this._super(count > 0 ? count - 1 : 0);
var self = this;
var columns = _(this.columns).filter(function (column) {
return column.invisible !== '1';
}).length;
if (this.options.selectable) { columns++; }
if (this.options.deletable) { columns++; }
var $cell = $('<td>', {
colspan: columns,
'class': 'oe_form_field_x2many_list_row_add'
}).append(
$('<a>', {href: '#'}).text(_t("Add new row"))
.click(function (e) {
e.preventDefault();
e.stopPropagation();
// FIXME: there should also be an API for that one
if (self.view.editor.form.__blur_timeout) {
clearTimeout(self.view.editor.form.__blur_timeout);
self.view.editor.form.__blur_timeout = false;
}
self.view.save_edition().done(function () {
self.view.do_add_record();
});
}));
var $padding = this.$current.find('tr:not([data-id]):first');
var $newrow = $('<tr>').append($cell);
if ($padding.length) {
$padding.replaceWith($newrow);
} else {
this.$current.replaceWith($newrow);
}
},
});
});
Module_Name-&gt; openerp .py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Module Name',
'version': '1.0',
'category': '',
'sequence': 1,
'summary': '',
'description': """ Give the Description of Module """,
'website': '',
'depends': ['web'],
'data': [
'views/File_Name.xml'
],
'demo': [],
'css': [],
'js' : [],
'installable': True,
'auto_install': False,
'application': True,
}
odoo_v9-&gt; web-&gt; static-&gt; src-&gt; js-&gt; views-&gt; form_relation_widget.js
在基础js(odoo9模块)form_relation_widget.js中添加X2ManyList:X2ManyList这一行
return {
FieldMany2ManyTags: FieldMany2ManyTags,
AbstractManyField: AbstractManyField,
X2ManyList : X2ManyList, ////Add this line in this file
};
我希望我的回答很有帮助。 如果有任何疑问请评论。
答案 1 :(得分:1)
一个选项可能是你进入调试模式。
然后,转到配置 - &gt; 申请条款 - &gt; 同步条款。在下拉语言中,选择英语并等到完成。
转到翻译的条款,在搜索字段中写下&#34;添加项目&#34;并替换翻译价值列中的文字。
值得一提的是,此更改将存储在数据库中,并且所有one2many关系都将受到影响。
答案 2 :(得分:0)
此字符串由JavaScript code提供。因此,您必须扩展js小部件以更改名称。