简体   繁体   English

如何在Odoo中的JavaScript上扩展此功能(编辑按钮)?

[英]How can I extend this function (edit button) on JavaScript within Odoo?

I would like to create a module which controls edit button on certain conditions. 我想创建一个在某些情况下控制“编辑”按钮的模块。 I tried the following code in js but I got no effect. 我在js中尝试了以下代码,但没有任何效果。 So I would like to know how to extend a function in js. 所以我想知道如何在js中扩展功能。

formView.include({
    init:function(){

        var edits = new Model('sale.order');
        edits.query(['validity_date']);
        console.log(validity_date)
        },
    on_button_edit: function(){
        this._super();

You can write something like this in the js file. 您可以在js文件中编写类似的内容。 I wrote some examples to help you. 我写了一些例子来帮助您。

openerp.custom_edit_button = function (instance) {
    var _t = instance.web._t;   

    instance.web.FormView.include({
        init: function() {
            console.log('JS loaded')  
            this._super.apply(this, arguments);   
        },  

        to_edit_mode: function(){
            // examples of useful methods
            var field_values = this.get_fields_values();
            var ids = this.get_selected_ids();
            var id = field_values['id'];
            var date = field_values['date'];
            var model = this.model;

            console.log(field_values)
            console.log(ids)
            console.log(id)
            console.log(model)
            console.log(date)
            console.log(Date.today())

            date_to_compare = new Date(date);
            console.log(date_to_compare)

            if(date_to_compare < Date.today()){
                error = this.error;
                var QWeb = instance.web.qweb;
                var dialog = new instance.web.Dialog(this, { 
                    title: _t("Set new expiry date"), 
                    width: '30%', 
                    size: 'medium',
                    /*dialogClass: 'oe_act_window',*/
                    buttons: [ 
                          { text: _t("OK"), click: function() { self.set_new_expiry_date(); }}, 
                          { text: _t("Close"), click: function() { dialog.close(); return; }
                          },                          
                      ],
                }, QWeb.render('custom_edit_button.expiry_date_form', {error: error})).open();

            }

            this._super();
        }
    });
}

So, if the expiry date is in the past, the form is going to appear to change it. 因此,如果到期日期是过去的日期,则该表格似乎将对其进行更改。 You must define the method set_new_expiry_date as well. 您还必须定义方法set_new_expiry_date And on the other hand you must add this template, or something similar to show the form. 另一方面,您必须添加此模板或类似的东西来显示表单。 Add the file in the qweb section of your __openerp__.py 在文件中添加您的qweb部分__openerp__.py

<templates xml:space="preserve">
    <div t-name="custom_edit_button.expiry_date_form" >
        <div class="form-group">
            <label for="date" class="control-label">New expiry date:</label>
            <input name="date" class="form-control"/>
        </div>   
    </div>
</templates>

Notice that the name of my module is custom_edit_button in the example 注意,在示例中,我的模块的名称为custom_edit_button

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从ListView中包含(或扩展)Odoo核心功能(例如Instance.web.ListView.extend) - How can I include(or extend) Odoo core function from ListView (e.g. Instance.web.ListView.extend) 如何在 Edge (Chromium) 中编辑实时 JavaScript - How can I edit live JavaScript within Edge (Chromium) 我可以用Javascript编写“扩展”继承函数吗? - Can I Write an “Extend” Inheritance Function in Javascript? 如何在JavaScript中更改要应用于其他功能的按钮的颜色? - How can I change the color of a button within JavaScript to be applied into another function? 如何扩展JavaScript对象? - How can i extend a javascript object? Odoo 13 Enterprise SaaS,我可以编辑产品搜索模块以仅使用 JavaScript 搜索产品描述吗? - Odoo 13 Enterprise SaaS, Can I edit the Product Search module to search product description using only JavaScript? 尝试扩展javascript函数时,如何避免过多的递归错误? - How can I avoid too much recursion error when trying to extend a javascript function? Odoo在Javascript中的差异扩展和包括 - Odoo difference in Javascript extend and include 如何在Javascript Odoo 10中扩展mail.Chatter小部件 - How To Extend mail.Chatter Widget in Javascript Odoo 10 如何从javascript函数中的.then内部返回值? - How can I return a value from within a .then inside a javascript function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM