使用 cron 和新的 api odoo 自动执行操作
automate actions with cron and the new api odoo
我想自动执行一个操作,这是我正在使用的代码:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="ir_cron_scheduler_demo_action" model="ir.cron">
<field name="name">Demo scheduler</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">2</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'note.admin'" name="model"/>
<field eval="'process_demo_scheduler_queue'" name="function"/>
</record>
</data>
</openerp>
@api.model
def process_demo_scheduler_queue(self):
for note in self.env['note.admin']:
if datetime.strptime(note.date, DEFAULT_SERVER_DATETIME_FORMAT).date() == datetime.now().date():
note.write({'is_visible': True})
我想要做的是在字段 note.date == 当前日期
时将值 is_visible 设置为 True
这是服务器上的登录信息:
2016-05-25 01:20:17,658 3680 INFO test3 werkzeug: 127.0.0.1 - -
[25/May/2016 01:20:17] "POST
/web/dataset/call_kw/note.admin/message_get_subscription_data
HTTP/1.1" 200 -
但它不起作用!
已解决:
@api.model
def process_demo_scheduler_queue(self):
notes = self.search([('date', '=', fields.Date.today())])
notes.write({'is_visible': True})
你必须像下面这样写代码,
@api.model
def process_demo_scheduler_queue(self):
for note in self.env['note.admin'].search([]):
if datetime.strptime(note.date, DEFAULT_SERVER_DATETIME_FORMAT).date() == datetime.now().date():
note.write({'is_visible': True})
首先你必须搜索数据库中的所有笔记,其次尝试使用 odoo 的日期逻辑:
@api.model
def process_demo_scheduler_queue(self):
for note in self.search([]):
if note.date == openerp.fields.Date.context_today(self):
note.is_visible = True
或者更快:
@api.model
def process_demo_scheduler_queue(self):
notes = self.search([('date', '=', openerp.fields.Date.context_today(self))])
notes.write({'is_visible': True})
我想自动执行一个操作,这是我正在使用的代码:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<record id="ir_cron_scheduler_demo_action" model="ir.cron">
<field name="name">Demo scheduler</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">2</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="False" name="doall"/>
<field eval="'note.admin'" name="model"/>
<field eval="'process_demo_scheduler_queue'" name="function"/>
</record>
</data>
</openerp>
@api.model
def process_demo_scheduler_queue(self):
for note in self.env['note.admin']:
if datetime.strptime(note.date, DEFAULT_SERVER_DATETIME_FORMAT).date() == datetime.now().date():
note.write({'is_visible': True})
我想要做的是在字段 note.date == 当前日期
时将值 is_visible 设置为 True这是服务器上的登录信息:
2016-05-25 01:20:17,658 3680 INFO test3 werkzeug: 127.0.0.1 - - [25/May/2016 01:20:17] "POST /web/dataset/call_kw/note.admin/message_get_subscription_data HTTP/1.1" 200 -
但它不起作用!
已解决:
@api.model
def process_demo_scheduler_queue(self):
notes = self.search([('date', '=', fields.Date.today())])
notes.write({'is_visible': True})
你必须像下面这样写代码,
@api.model
def process_demo_scheduler_queue(self):
for note in self.env['note.admin'].search([]):
if datetime.strptime(note.date, DEFAULT_SERVER_DATETIME_FORMAT).date() == datetime.now().date():
note.write({'is_visible': True})
首先你必须搜索数据库中的所有笔记,其次尝试使用 odoo 的日期逻辑:
@api.model
def process_demo_scheduler_queue(self):
for note in self.search([]):
if note.date == openerp.fields.Date.context_today(self):
note.is_visible = True
或者更快:
@api.model
def process_demo_scheduler_queue(self):
notes = self.search([('date', '=', openerp.fields.Date.context_today(self))])
notes.write({'is_visible': True})