odoo10學習筆記十六 定時任務

2022-09-17 09:00:16 字數 1674 閱讀 3119

一:定義定時器資料模型

模型中定義需要用到的字段、定時方法

from odoo import models, fields, api, exceptions

import logging

from datetime import datetime

_logger = logging.getlogger(__name__)

class scheduler(models.model):

_name = 'scheduler.demo'

#需要用到的字段

name = fields.char(required=true)

numberofupdates = fields.integer('number of updates')

lastmodified = fields.datetime('last updated')

#定時方法

def process_demo_scheduler_queue(self):

scheduler_line_ids = self.env['scheduler.demo'].search()

for scheduler_line in scheduler_line_ids:

_logger.info('line:' + scheduler_line.name)

scheduler_line.numberofupdates += 1

scheduler_line.lastmodified = datetime.utcnow()

二:建立定時器檢視

scheduler.demo.form

scheduler.demo

scheduler.demo.tree

scheduler.demo

demo scheduler

2minutes

-1 計畫任務demo

scheduler.demo

tree,form

其中,定義定時器任務的標籤有以下重要字段:

name:

定時任務名稱

user_id:

執行定時任務的使用者,不同的使用者是有不同許可權的,為了保證能有足夠許可權執行定時任務,一般這裡就是base.user_root

interval_number:

任務執行的頻次,和interval_type欄位一起決定了任務執行的間隔時間,比如這裡為interval_number為2,interval_type為minutes,就是任務每2分鐘執行一次。

interval_type:

任務執行頻次的單位,可選項有: minutes,hours,days,work_days,weeks,months,意思很好理解,work_days是星期幾執行。

numbercall:

迴圈執行的次數,比如你填10,那麼任務執行10次後將不再執行,這裡-1代表一直執行下去。

doall:

如果在伺服器重啟期間錯過了執行時機,是否再次補充執行。

model:

任務方法所在模組

function:

任務方法,與model一起決定了任務時機到來時,呼叫哪個方法執行。

三:註冊定時器

在init中import定時器模型;

在manifest中引入定時器視**件

odoo學習筆記十六 定時任務

一 定義定時器資料模型 模型中定義需要用到的字段 定時方法 from odoo import models,fields,api,exceptions import logging from datetime import datetime logger logging.getlogger name...

odoo10學習筆記十 Actions

actions定義了系統對於使用者的操作的響應 登入 按鈕 選擇專案等。一 視窗action ir.actions.act window 最常用的action型別,用於將model的資料展示出來。字段列表 1.res model 需要在view裡顯示資料的model 2.views 乙個 view ...

Linux學習筆記 定時任務設定

定時任務通常用於處理需要定期執行的系統維護任務,比如日誌清理,系統檢查等,通過crontab和at,命令可以實現。u user指定執行此任務的使用者是誰,如果不設定,預設是當前登入使用者,該選項只有root使用者才能使用 l 顯示當前使用者的任務 r 刪除當前使用者的任務 e 更改使用者的任務要使用...