代码之家  ›  专栏  ›  技术社区  ›  Pointer

在树状视图odoo 9中更改文本“添加项目”

  •  4
  • Pointer  · 技术社区  · 8 年前

    如何在自定义模块中将文本“添加项目”更改为“添加新行”?

    3 回复  |  直到 8 年前
        1
  •  2
  •   Er CEO Vora Mayur    8 年前

    您好,指针,

    试试下面的代码,

    您的\u module\u name/view/custome\u file\u 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>
    

    openerp.fm_sale_order_ext_ept = function(instance) {
        change_tree_view_add_item_name(instance);
    }
    

    your\u module\u name/src/js/custome\u view\u 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)
                }
            }
        });
    }
    

    使用odoo9

    首先,我们创建新模块,下面给出了新模块的文件结构。

    Module_Name
        static
                src
                    js
                        File_Name.js
        views
                File_Name.xml
        __openerp__.py
    


    现在,我们在base odoo 9模块中添加了custome js,因此我们要创建xml文件并继承base file,然后添加custome 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>
    


    现在我们继承基本form\u relation\u小部件。并修改此方法,

    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);
                }
            },
        });
    
    });
    

    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,
    }
    

    在基本js(odoo9模块)form\u relation\u widget.js中添加X2ManyList:X2ManyList此行

    return {
        FieldMany2ManyTags: FieldMany2ManyTags,
        AbstractManyField: AbstractManyField,
        X2ManyList : X2ManyList,  ////Add this line in this file
    };
    

    我希望我的回答有帮助。 如果有任何疑问,请评论。

        2
  •  1
  •   VIX    8 年前

    然后,转到 配置 申请条款 -&燃气轮机; 同步术语

    翻译后的术语

    值得一提的是,此更改将存储在DB中,所有one2many关系都将受到影响。

        3
  •  0
  •   CZoellner    8 年前

    此字符串由提供 JavaScript code