summaryrefslogtreecommitdiff
path: root/addons/fetchmail/fetchmail.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2014-09-04 17:51:42 +0200
committerChristophe Simonis <chs@odoo.com>2014-09-04 17:51:42 +0200
commit9363bc9182b3eb70980b3a80e3ea2d4809f44840 (patch)
treee30c6c89fb35ca558e904abb33070ba3a807ec40 /addons/fetchmail/fetchmail.py
parent05683f05b535cab94f9e01dae1f4701428c38020 (diff)
parent3d80dc2bbfcda08e787159d2711ac0dc56f81ad6 (diff)
[MERGE] forward port of branch saas-3 up to 3d80dc2
Diffstat (limited to 'addons/fetchmail/fetchmail.py')
-rw-r--r--addons/fetchmail/fetchmail.py34
1 files changed, 20 insertions, 14 deletions
diff --git a/addons/fetchmail/fetchmail.py b/addons/fetchmail/fetchmail.py
index 565996bf961..37a0f165435 100644
--- a/addons/fetchmail/fetchmail.py
+++ b/addons/fetchmail/fetchmail.py
@@ -251,27 +251,33 @@ openerp_mailgate: "|/path/to/openerp-mailgate.py --host=localhost -u %(uid)d -p
server.write({'date': time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)})
return True
- def cron_update(self, cr, uid, context=None):
- if context is None:
- context = {}
- if not context.get('fetchmail_cron_running'):
- # Enabled/Disable cron based on the number of 'done' server of type pop or imap
- ids = self.search(cr, uid, [('state','=','done'),('type','in',['pop','imap'])])
- try:
- cron_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'fetchmail', 'ir_cron_mail_gateway_action')[1]
- self.pool.get('ir.cron').write(cr, 1, [cron_id], {'active': bool(ids)})
- except ValueError:
- # Nevermind if default cron cannot be found
- pass
+ def _update_cron(self, cr, uid, context=None):
+ if context and context.get('fetchmail_cron_running'):
+ return
+
+ try:
+ cron = self.pool['ir.model.data'].get_object(
+ cr, uid, 'fetchmail', 'ir_cron_mail_gateway_action', context=context)
+ except ValueError:
+ # Nevermind if default cron cannot be found
+ return
+
+ # Enabled/Disable cron based on the number of 'done' server of type pop or imap
+ cron.toggle(model=self._name, domain=[('state','=','done'), ('type','in',['pop','imap'])])
def create(self, cr, uid, values, context=None):
res = super(fetchmail_server, self).create(cr, uid, values, context=context)
- self.cron_update(cr, uid, context=context)
+ self._update_cron(cr, uid, context=context)
return res
def write(self, cr, uid, ids, values, context=None):
res = super(fetchmail_server, self).write(cr, uid, ids, values, context=context)
- self.cron_update(cr, uid, context=context)
+ self._update_cron(cr, uid, context=context)
+ return res
+
+ def unlink(self, cr, uid, ids, context=None):
+ res = super(fetchmail_server, self).unlink(cr, uid, ids, context=context)
+ self._update_cron(cr, uid, context=context)
return res
class mail_mail(osv.osv):