Reputation: 185
I want to automate an action and here is the code that I'm using:
<?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})
What I want to do is to set the value is_visible on True when the field note.date == current date
here is the log on server:
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 -
but it is not working!
SOLVED:
@api.model
def process_demo_scheduler_queue(self):
notes = self.search([('date', '=', fields.Date.today())])
notes.write({'is_visible': True})
Upvotes: 3
Views: 2434
Reputation: 14778
First you have to search for all notes in your database, and second try to use odoo's date logic:
@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
Or maybe faster:
@api.model
def process_demo_scheduler_queue(self):
notes = self.search([('date', '=', openerp.fields.Date.context_today(self))])
notes.write({'is_visible': True})
Upvotes: 1
Reputation: 591
You have to write like below code,
@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})
Upvotes: 2