# 一、直接在tree根元素中新增。这种有个限制就是必须要勾选一或多条记录的时候按钮才会显示
# 然后在编写处理方法
@api.model
def tests(self, select_ids):
pass
# 二、如果你要按钮一直显示的话
# 1.tree_button_template.xml
<?xml version="1.0" encoding="UTF-8"?>
"sync_import_base_partinfo" xml:space="preserve">
"ListView.buttons">
".o_list_buttons" t-operation="append">
if="widget and widget.modelName == 'shipyard.parttype'">
# 2.tree_button.js
odoo.define('shipyard_parttype.list_sync_import_base_partinfo_button_create', function (require) {
"use strict";
var ListView = require('web.ListView');
var viewRegistry = require('web.view_registry');
var ListController = require('web.ListController');
ListController.include({
renderButtons: function ($node) {
this._super.apply(this, arguments);
if (this.$buttons) {
# .o_list_tender_bt_sync_equip该选择器是上边template中的
this.$buttons.on('click', '.o_list_tender_bt_sync_equip', this._sync_import_base_partinfo.bind(this));
}
},
_sync_import_base_partinfo: function () {
var self = this;
var records = this.getSelectedIds();
self._rpc({ # rpc不明白可以往上翻其他小节
model: 'shipyard.parttype', # 模块
method: 'import_partitem', # 调用的方法
args: [records]
},
[]
);
}
});
})
;
# 3.定义python处理
@api.model
def import_partitem(self, pids): # pids为tree列表中勾选记录的id列表
pass
# 4.将js和xml加入到资源中去
"assets_end" inherit_id="web.assets_backend">
"." position="inside">