js文件: tree_button.js
odoo.define('my_test.my.action.tree.button',function(require){
"use strict";
let ListController = require('web.ListController');
ListController.include({
renderButtons: function($node){
let $buttons = this._super.apply(this, arguments);
let tree_model =this.modelName;
if (tree_model === 'my.action'){
let but2 = "<button type=\"button\" t-if=\"widget.modelName == 'my.action'\" class=\"oe_highlight\">测试按钮</button>";
let button2 = $(but2).click(this.proxy('my_action_test'));
this.$buttons.prepend(button2);
}
return $buttons;
},
my_action_test :function(){
return this._rpc({
model: this.modelName,
method: 'my_action_test',
}).then(function (result) {
self.data = result;
});
},
});
});
引用js文件: add_button.xml
<odoo>
<template id="tree_button_test" inherit_id="web.assets_backend" name="bicon_wms_base_assets_1">
<xpath expr="." position="inside">
<script type="text/javascript" src="/my_test/static/src/tree_button.js"></script>
</xpath>
</template>
</odoo>
引用addbutton.xml文件: _manifest.py
'data': [
...
'views/add_button.xml',
...
],
相应的模块里面写
class MyAction(models.Model):
_name = 'my.action'
_description = '测试'
user_id = fields.Many2one('res.users', string='业务员')
count = fields.Float(string='销售合计')
order_line = fields.One2many('my.action.line', 'line_id')
def my_action_test(self):
self.env['my.action'].create({
'user_id': self.env.uid,
'count': 100
})
|