我正在尝试在标题按钮(工作流程按钮)上触发 JavaScript 事件。
这是我的js
var _t = instance.web._t, QWeb = instance.web.qweb;
instance.web.FormView.include({
init: function() {
this._super.apply(this, arguments);
},
events: {
"click .resume_consultation": "resume_consultation",
},
resume_consultation : function(ev) {
ev.preventDefault();
ev.stopPropagation();
}
})
按钮的 xml
<header>
<button type="object" class="resume_consultation"
name="testonly"
string="Test Only"/>
</header>
python
@api.multi
def testonly(self):
return False
事件未被调用。但我知道 FormView 中的 init
被执行。只是事件没有。
有人知道如何为工作流程按钮执行此操作吗?
最佳答案
首先添加以下代码的 js 文件:
odoo.define('Modulename.filename', function (require) {
"use strict";
var form_widget = require('web.form_widgets');
var core = require('web.core');
var _t = core._t;
var QWeb = core.qweb;
form_widget.WidgetButton.include({
on_click: function() {
if(this.node.attrs.custom === "click"){
//code//
}
this._super();
},
});
});
之后在 xml 中添加你的 js 文件:
<?xml version="1.0" encoding="utf-8"?> <odoo>
<template id="assets_backend" name="project assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/product_pack/static/src/js/product_pack.js"></script>
</xpath>
</template> </odoo>
在 py 文件中定义点击事件函数的 ather
class SalePetOrder(models.Model):
_inherit = "xyz"
def java_script(self):
return {"hello": "world"}
在 xml 中定义函数后:
<data>
<header>
<button name="java_script" string="Java Script" type="object" custom="click"/>
</header>
</data>
是的,在您的 manifest/openerp 文件中定义您的 js 文件和 xml 文件。
希望对你有帮助。
关于Odoo 标题按钮上的 JavaScript 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46956567/