我想在某些条件下创建一个控制编辑按钮的模块。我在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();
答案 0 :(得分:1)
你可以在js文件中写这样的东西。我写了一些例子来帮助你。
label1.Text= listBox1.SelectedIndex.ToString();
if ( listBox1.SelectedItem is KeyValuePair<int,DockStyle>)
{
var temp1 = (KeyValuePair<int, DockStyle>)listBox1.SelectedItem;
label3.Text = temp1.Key.ToString();
label4.Text = temp1.Value.ToString();
}
因此,如果过期日期是过去的,那么表单似乎会改变它。您还必须定义方法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
__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>