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, }; })