簡體   English   中英

如何在Odoo中的JavaScript上擴展此功能(編輯按鈕)?

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

我想創建一個在某些情況下控制“編輯”按鈕的模塊。 我在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();

您可以在js文件中編寫類似的內容。 我寫了一些例子來幫助您。

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

因此,如果到期日期是過去的日期,則該表格似乎將對其進行更改。 您還必須定義方法set_new_expiry_date 另一方面,您必須添加此模板或類似的東西來顯示表單。 在文件中添加您的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>

注意,在示例中,我的模塊的名稱為custom_edit_button

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM