[MERGE] forward port of branch saas-5 up to 9363bc9
[odoo/odoo.git] / openerp / addons / base / ir / ir_cron.py
index 98d492c..b16ac82 100644 (file)
@@ -296,4 +296,20 @@ class ir_cron(osv.osv):
         res = super(ir_cron, self).unlink(cr, uid, ids, context=context)
         return res
 
+    def try_write(self, cr, uid, ids, values, context=None):
+        try:
+            with cr.savepoint():
+                cr.execute("""SELECT id FROM "%s" WHERE id IN %%s FOR UPDATE NOWAIT""" % self._table,
+                           (tuple(ids),), log_exceptions=False)
+        except psycopg2.OperationalError:
+            pass
+        else:
+            return super(ir_cron, self).write(cr, uid, ids, values, context=context)
+        return False
+
+    def toggle(self, cr, uid, ids, model, domain, context=None):
+        active = bool(self.pool[model].search_count(cr, uid, domain, context=context))
+
+        return self.try_write(cr, uid, ids, {'active': active}, context=context)
+
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: