1.视图页面
<form delete="0" duplicate="0" edit="0" create="0" js_class="local_sync_oss"> <header> <button class="local_sync_oss" string="NAS同步照片到OSS"></button> </header>
</form>
2.JS
odoo.define('sps_service/static/src/local_sync_oss.js', function (require) {
"use strict";
var FormView = require('web.FormView');
var FormRenderer = require('web.FormRenderer');
var view_registry = require('web.view_registry');
var session = require('web.session');
var SpsServiceFormRenderer = FormRenderer.extend({
events: _.extend({}, FormRenderer.prototype.events, {
'click .local_sync_oss': 'local_sync_oss',
}),
init: function () {
this._super.apply(this, arguments);
},
// 这里可以在页面打开时提前获取一些需要的数据,和执行一些函数
start: function () {
this._super.apply(this, arguments);
let self = this
self._rpc({
model: 'res.company',
method: 'search_read',
fields: ['flow_type', 'is_all_storage', 'locality_location'],
args: [[['id', '=', session.company_id]]],
}).then(res => {
// 获取存储类型
this.flow_type = res[0].flow_type
// 获取是否配置了允许外网访问
this.is_all_storage = res[0].is_all_storage
// 获取检测是否nas的url
this.locality_location = res[0].locality_location
})
this.service_order_id = 0
// 打开页面时执行自定义的函数
this.get_service_order_id()
},
get_service_order_id: function () {
console.log("6666666666");
},
local_sync_oss: function () {
console.log("点击按钮执行的函数");
}
})
var SpsServiceFormView = FormView.extend({
jsLibs: [],
config: _.extend({}, FormView.prototype.config, {
Renderer: SpsServiceFormRenderer,
}),
});
view_registry.add('local_sync_oss', SpsServiceFormView);
return {
Renderer: SpsServiceFormRenderer,
};
})
