diff --git a/mail_check_immediately/README.rst b/mail_check_immediately/README.rst new file mode 100644 index 0000000..a9dbef4 --- /dev/null +++ b/mail_check_immediately/README.rst @@ -0,0 +1,4 @@ +Check mail immediately +====================== + +Description: https://apps.odoo.com/apps/modules/8.0/mail_check_immediately/ diff --git a/mail_check_immediately/__init__.py b/mail_check_immediately/__init__.py new file mode 100644 index 0000000..89d26e2 --- /dev/null +++ b/mail_check_immediately/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +import models diff --git a/mail_check_immediately/__openerp__.py b/mail_check_immediately/__openerp__.py new file mode 100644 index 0000000..663ca66 --- /dev/null +++ b/mail_check_immediately/__openerp__.py @@ -0,0 +1,18 @@ +{ + 'name' : 'Check mail immediately', + 'version' : '1.0.1', + 'author' : 'IT-Projects LLC, Ivan Yelizariev', + 'license': 'LGPL-3', + 'category' : 'Social Network', + 'website' : 'https://twitter.com/yelizariev', + 'price': 9.00, + 'currency': 'EUR', + 'depends' : ['base', 'web', 'fetchmail', 'mail'], + 'data': [ + 'views.xml', + ], + 'qweb': [ + "static/src/xml/main.xml", + ], + 'installable': False +} diff --git a/mail_check_immediately/doc/changelog.rst b/mail_check_immediately/doc/changelog.rst new file mode 100644 index 0000000..e72d492 --- /dev/null +++ b/mail_check_immediately/doc/changelog.rst @@ -0,0 +1,9 @@ +.. _changelog: + +Changelog +========= + +`1.0.1` +------- + +- FIX: incorrectly displayed last updated time when multiple threads (--workers) \ No newline at end of file diff --git a/mail_check_immediately/models.py b/mail_check_immediately/models.py new file mode 100644 index 0000000..3306837 --- /dev/null +++ b/mail_check_immediately/models.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +import datetime + +from openerp.tools.translate import _ +from openerp import tools + +from openerp import exceptions +from openerp import models, fields, api + + +class FetchMailServer(models.Model): + _inherit = 'fetchmail.server' + _name = 'fetchmail.server' + + _last_updated = None + + run_time = fields.Datetime(string="Launch time") + + def _run_time(self): + if not self._last_updated: + self._last_updated = tools.datetime.now() + + src_tstamp_str = self._last_updated.strftime(tools.misc.DEFAULT_SERVER_DATETIME_FORMAT) + src_format = tools.misc.DEFAULT_SERVER_DATETIME_FORMAT + dst_format = tools.misc.DEFAULT_SERVER_DATETIME_FORMAT + dst_tz_name = self._context.get('tz') or self.env.user.tz + _now = tools.misc.server_to_local_timestamp(src_tstamp_str, src_format, dst_format, dst_tz_name) + + return _now + + @api.model + def _fetch_mails(self): + + if self._context.get('run_fetchmail_manually'): + # if interval less than 5 seconds + if self._last_updated and (datetime.datetime.now() - self._last_updated) < datetime.timedelta(0, 5): + raise exceptions.Warning(_('Error'), _('Task can be started no earlier than 5 seconds.')) + + super(FetchMailServer, self)._fetch_mails() + + res = self.env['fetchmail.server'].sudo().with_context(tz=self.env.user.tz).search([('state', '=', 'done')]) + if res: + res[0].run_time = self._run_time() + + +class FetchMailImmediately(models.AbstractModel): + + _name = 'fetch_mail.imm' + + @api.model + def get_last_update_time(self): + res = self.env['fetchmail.server'].sudo().with_context(tz=self.env.user.tz).search([('state', '=', 'done')]) + array = [r.run_time for r in res] + if array: + return array[0] + else: + return None + + @api.model + def run_fetchmail_manually(self): + + fetchmail_task = self.env.ref('fetchmail.ir_cron_mail_gateway_action') + fetchmail_task_id = fetchmail_task.id + fetchmail_model = self.env['fetchmail.server'].sudo() + + fetchmail_task._try_lock() + fetchmail_model.with_context(run_fetchmail_manually=True)._fetch_mails() diff --git a/mail_check_immediately/static/description/icon.png b/mail_check_immediately/static/description/icon.png new file mode 100644 index 0000000..79f7d8f Binary files /dev/null and b/mail_check_immediately/static/description/icon.png differ diff --git a/mail_check_immediately/static/description/index.html b/mail_check_immediately/static/description/index.html new file mode 100644 index 0000000..0416efa --- /dev/null +++ b/mail_check_immediately/static/description/index.html @@ -0,0 +1,47 @@ +
+
+
+

Check mail immediately

+

Keep your inbox up to date

+
+ +
+
+ +
+
+
+
+ +
+
+
+

Protect your business

+
+
+

+ Sometimes odoo mail fetching system doesn't work for really long time. It could be a real problem, if you will not notice it on time. Until this issue is fixed, you can restart odoo every time when you see that last fetching time is more than 5 minutes. +

+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
diff --git a/mail_check_immediately/static/description/issue.png b/mail_check_immediately/static/description/issue.png new file mode 100644 index 0000000..79ef713 Binary files /dev/null and b/mail_check_immediately/static/description/issue.png differ diff --git a/mail_check_immediately/static/description/screenshot.png b/mail_check_immediately/static/description/screenshot.png new file mode 100644 index 0000000..a408525 Binary files /dev/null and b/mail_check_immediately/static/description/screenshot.png differ diff --git a/mail_check_immediately/static/src/js/main.js b/mail_check_immediately/static/src/js/main.js new file mode 100755 index 0000000..20b07bd --- /dev/null +++ b/mail_check_immediately/static/src/js/main.js @@ -0,0 +1,55 @@ +openerp.mail_check_immediately = function(instance, local) { + + instance.mail.Wall.include({ + + init: function(){ + this._super.apply(this, arguments); + + var _this = this; + + this.imm_model = new instance.web.Model('fetch_mail.imm'); + this.events['click a.oe_fetch_new_mails'] = function(){ + _this.run_fetchmail_manually(); + } + }, + + start: function() { + var _this = this; + + + this._super(); + + this.get_last_fetched_time(); + + this.get_time_loop = setInterval(function(){ + _this.get_last_fetched_time() + }, 30000); + + }, + + run_fetchmail_manually: function(){ + var _this = this; + + this.imm_model.call('run_fetchmail_manually', {context: new instance.web.CompoundContext()}).then(function(){ + _this.get_last_fetched_time() + }) + }, + + get_last_fetched_time: function(){ + var _this = this; + this.imm_model.call('get_last_update_time', {context: new instance.web.CompoundContext()}).then(function(res){ + var value; + if (res) + value = $.timeago(res); + value = value || 'undefined'; + _this.$el.find('span.oe_view_manager_fetch_mail_imm_field').html(value); + }) + }, + + destroy: function(){ + clearInterval(this.get_time_loop); + this._super.apply(this, arguments); + } + + }); +}; diff --git a/mail_check_immediately/static/src/xml/main.xml b/mail_check_immediately/static/src/xml/main.xml new file mode 100755 index 0000000..0329572 --- /dev/null +++ b/mail_check_immediately/static/src/xml/main.xml @@ -0,0 +1,25 @@ + + + + + +
+ + Mails fetched: + + + + +
+ + + +
+ + + + + + + +
diff --git a/mail_check_immediately/views.xml b/mail_check_immediately/views.xml new file mode 100644 index 0000000..66ab096 --- /dev/null +++ b/mail_check_immediately/views.xml @@ -0,0 +1,9 @@ + + + + +