openERP server action,最強大的功能,沒有之一


Jeffery9@gmail.com 出品

@jeffery-陳帆

原理

ations

OE定義了ir.actions.actions,並從中派生了眾多的子類

  • ir.actions.client
  • ir.actions.act_url
  • ir.actions.act_window
  • ir.actions.act_window_close
  • ir.actions.wizard
  • ir.actions.server

用來執行相關的動作

   

Server action

其中有一個子類 ir.actions.server ,可以用來執行服務器端的動作。

可以執行的動作有;

'state': fields.selection([

('client_action','Client Action'),

('dummy','Dummy'),

('loop','Iteration'),

('code','Python Code'),

('trigger','Trigger'),

('email','Email'),

('sms','SMS'),

('object_create','Create Object'),

('object_copy','Copy Object'),

('object_write','Write Object'),

('other','Multi Actions'),

], 'Action Type', required=True, size=32, help="Type of the Action that is to be executed"),

   

   

可以用來干各種事情

   

Automated Action Rules

模塊定義了 自動動作規則

-針對什么對象

-條件

-動作 ,即server_action定義的動作

   

何時觸發

  • 定時器觸發
  • 注入到對象的create/write方法中

   

使用場景

例如,

  • 當有任務指派時,發送通知郵件給被指派的人
  • 定時提醒
  • 接收到郵件時,創建對象實例

   

實際操作

建立server_actions.

菜單 Settings/ Technical/ Actions/ Server Actions

   

create一個新的action

object處選擇Task project.task

Action type選擇Email

其中可以選的action有很多,如下

   

定制郵件內容

  • 郵件接收人
  • 郵件主旨
  • 郵件內容

   

提示,如果不清楚object的屬性,可以點擊彈出窗口按鍵,彈出Task定義窗口

   

   

設置好相關的參數后,保存

至此,server_action設置好了。

   

設置automatic action rule以便可以觸發動作。

菜單 Settings/ Technical/ Automated Actions/ Automated Actions

   

create一個automatic action rule.

輸入規則名稱

選擇相應的對象,在此選擇task ,即project.task

   

設置conditions

目的,用來過濾哪些對象可以執行服務器動作

說明;

Timer如果不設置,則當crete/update Object時觸發服務器動作;否則,按照定時器設定的時間觸發,但是會按照trigger date設置的參數篩選相應的對象實例。

   

   

設置actions

點擊Add按鈕,在彈出窗選擇已經創建的server action或者建立新的server action.

   

提示;

可以添加多個動作,動作按sequence順序執行

   

   

注意;

Fields to change. 是指 change the fields of the object.

Add Followers,是指 為此 instance of object指派 訂閱者(但有條件,具體看代碼 ;))

   

定時任務

Automatic action rules是由 ir.cron定期執行的,如

   

   

附加說明

   

   

注入到對象創建、修改方法的代碼

   

修改create方法

   

修改write方法

   

執行動作時,修改 Fields to change 和Add Follower的相關代碼

   

   

   

總結;

   

  • 如果使用filter. 不要給 filter指定 res.user !!! 否則會有權限問題發生!!!

   

  • 如果設置了timer. 則不注入到model,不觸發動作

       

   

   

  • 如果設置了timer. 時間條件不成熟時,不觸發動作

       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM