你可以在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
。另一方面,您必須添加此模板或類似的內容來顯示錶單。在文件中添加您__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>
通知的qweb節我模塊的名稱是在例如custom_edit_button
感謝回答是基於現有到期日正是我試圖('validity_date') 'sale.order'上的字段,只有在到期日超過當前日期時才啓用編輯模式。 – 111sree
嗯,我認爲你不能這樣做,因爲編輯按鈕出現時你沒有記錄的ID。另一種選擇是在每個字段或組或字段中使用'attrs'屬性。 – ChesuCR
我更新了我的答案,檢查它是否對您有用 – ChesuCR