summaryrefslogtreecommitdiff
path: root/addons/fetchmail/fetchmail.py
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2014-09-04 18:03:24 +0200
committerChristophe Simonis <chs@odoo.com>2014-09-04 18:03:24 +0200
commit41afeec7f14a2bafb976770afe76d24e15b13df6 (patch)
tree599c293f9f4999f10e8b8bbea146c764f30f575b /addons/fetchmail/fetchmail.py
parent2d9ddce327eb818dd6631b1bf1efb50f9be22540 (diff)
parent9363bc9182b3eb70980b3a80e3ea2d4809f44840 (diff)
[MERGE] forward port of branch saas-5 up to 9363bc9
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 3a465577c96..d0690520b0e 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):