4
votes

How in custom module change text 'Add an item' to 'Add new row"?

Any simple solution?

3

3 Answers

2
votes

Hello Pointer,

Using odoo 8

Try this below code,

your_module_name/view/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)
            }
        }
    });
}

Using odoo9

First we create new module and given below is file structure of new module.

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

Module_Name->views->File_Name.xml
Now we add the custome js in base odoo 9 module so we are create xml file and inherit base file and add our 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>

Module_Name->static->src->js->File_Name.js
Now we are inherit base form_relation_widget.js js and modify this method,

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->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->web->static->src->js->views->form_relation_widget.js

Add X2ManyList : X2ManyList this line in base js (odoo9 module) form_relation_widget.js

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

I hope my answer is helpful. If any query so comment please.

1
votes

An option could be that you enter on debug mode.

Then, go to Configuration -> Application Terms -> Synchronize Terms. In the dropdown Language, select English and wait until finish.

Go to Translated Terms, in the search field write "Add an item" and replace the text that is in Translation Value column.

It's worth say, this change will stored in the DB and all one2many relations will be affected.

0
votes

This string is provided by JavaScript code. So you have to extend the js widget to change the name.