odoo.define('/hr_pay/static/src/js/sync_punch_card_record.js', function (require) { "use strict"; var Dialog = require('web.Dialog'); //引入odoo的dialog彈窗對象 var ListController = require('web.ListController'); // 引入列表控制器,用來修改tree視圖 var show_button_import = "punch.in.record"; // 指定那個模型添加:想要自定義內容的模型 var rpc = require('web.rpc'); ListController.include({ // 自定義按鈕方法 renderButtons: function ($node){ var $buttons = this._super.apply(this, arguments); var tree_model = this.modelName; // 當前模型名稱 // 如果當前模型名稱為上面定義的模型名稱 if (tree_model == show_button_import) { // 定義一個html按鈕,點擊時出發test函數 var button_01 = $("<button id='but' type='button' class='btn btn-primary '>同步打卡記錄</button>").click(this.proxy("set_time_scope")) this.$buttons.append(button_01); // 添加到已有按鈕的后面 } return $buttons; }, set_time_scope: function () { var affirm = function () { let start_time = $("#start_time").val() let end_time = $("#end_time").val() if (start_time && end_time) { console.log("成功"); rpc.query({ route: "/sync_record", params: { "start_time": start_time, "end_time": end_time, }, }).then(function (data) { if (data) { alert("同步成功!點擊后刷新頁面!") location.reload(); } }) dialog.close(); } else { alert("請填寫開始時間和結束時間!") } }; let input_text = "<div>開始時間:<input id='start_time' type='date' name='開始時間'/></div><div>結束時間:<input id='end_time' type='date' name='結束時間'/></div>" var dialog = new Dialog(this, { title: '設置時間范圍', // size: 'medium', size: 'small', // size: 'large', $content: input_text, buttons: [{ text: '確認', classes: 'btn-primary', close: false, click: affirm }, { text: '取消', close: true }] }).open(); }, }); });