openerp学习笔记 计划动作、计划执行(维护计划)
阅读原文时间:2023年07月12日阅读:3

示例代码:

data/scheduler.xml


                        自动更新服务卡过期状态                                     12             hours             -1                                                             0**            

service_card.py

#自动更新服务卡过期状态,每天早上自动执行一次    def
process_change_state(self, cr, uid, ids=None,
context=None):
       
service_card_ids=self.search(cr,uid,[("state","=",'1')],
context=context)
        if
service_card_ids:
           
DATE_FORMAT =
"%Y-%m-%d"
           
try:
               
for rec in self.browse(cr, uid, service_card_ids,
context=context):
                   
if  rec.remaining_times == 0:
#已用完
                       
self.write(cr, uid, rec.id,
{'state':'2'})
                   
elif rec.due_date < datetime.datetime.strftime(datetime.date.today(),
DATE_FORMAT):
#已过期
                       
self.write(cr, uid, rec.id,
{'state':'3'})
           
except
Exception:
                
_logger.exception("更新服务卡过期状态出现异常!(dispatch.service_card.process_change_state)")
       
return False

backup_data.xml


    ** **                    自动备份数据库                                     **8 **            **hours **            -1             ** **                                                0            

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章