diff --git a/__init__.py b/__init__.py index c7a6ca6..0f7cb6b 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +1,2 @@ # -*- coding: utf-8 -*- -import controllers import models \ No newline at end of file diff --git a/__openerp__.py b/__openerp__.py index 6857423..7f96fbc 100644 --- a/__openerp__.py +++ b/__openerp__.py @@ -1,12 +1,12 @@ { 'name' : 'Check mail immediately', - 'version' : '0.1', + 'version' : '1.0', 'author' : 'Ivan Yelizariev', 'category' : 'Base', 'website' : 'https://yelizariev.github.io', 'depends' : ['base', 'web', 'fetchmail', 'mail'], 'data': [ - 'views.xml', + 'views.xml', 'security/ir.model.access.csv' ], 'qweb': [ "static/src/xml/main.xml", diff --git a/models.py b/models.py index a9e0a3a..1e934ed 100644 --- a/models.py +++ b/models.py @@ -1,6 +1,11 @@ # -*- coding: utf-8 -*- +import math +import datetime import psycopg2 +from openerp.osv import orm +from openerp.tools.translate import _ + from openerp.tools.safe_eval import safe_eval from openerp import models, fields, api @@ -11,19 +16,28 @@ class FetchMailServer(models.Model): _last_updated = None - run_time = fields.Datetime(string="Launch time", compute='_run_time') + run_time = fields.Char(string="Launch time", compute='_run_time') @classmethod def _update_time(cls): - cls._last_updated = fields.Datetime.now() + cls._last_updated = datetime.datetime.now() @api.one def _run_time(self): - self.run_time = self._last_updated + if self._last_updated: + self.run_time = str(int((datetime.datetime.now() - self._last_updated).total_seconds() / 60)) + else: + self._last_updated = datetime.datetime.now() + self.run_time = '0' @api.model def _fetch_mails(self): + super(FetchMailServer, self)._fetch_mails() + + if self._last_updated and (datetime.datetime.now() - self._last_updated) < datetime.timedelta(0,5): + raise orm.except_orm( _('Error'), _('Task can be started no earlier than 5 seconds.')) + self._update_time() @@ -50,7 +64,6 @@ class FetchMailImmediately(models.Model): (fetchmail_task_id,), log_exceptions=False) # Got the lock on the job row, run its code - fetchmail_model._fetch_mails() except psycopg2.OperationalError as e: @@ -60,4 +73,4 @@ class FetchMailImmediately(models.Model): _('Error'), _('Another process/thread is already busy ' 'executing this job')) - raise \ No newline at end of file + raise diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv new file mode 100644 index 0000000..e94eb3b --- /dev/null +++ b/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_fetchmail_server,fetchmail.server,model_fetchmail_server,base.group_user,1,1,1,1 diff --git a/static/src/js/main.js b/static/src/js/main.js index d797563..9471ed0 100755 --- a/static/src/js/main.js +++ b/static/src/js/main.js @@ -2,8 +2,6 @@ openerp.mail_check_immediately = function(instance, local) { instance.mail.Wall.include({ start: function() { - var _this = this; - this._super(); this.get_last_update_time(); this.get_time_loop() diff --git a/static/src/xml/main.xml b/static/src/xml/main.xml index 941f1e5..4ef0b9d 100755 --- a/static/src/xml/main.xml +++ b/static/src/xml/main.xml @@ -5,9 +5,9 @@