Browse Source

Done.

pull/1/head
s0x90 10 years ago
parent
commit
78375c9de8
  1. 1
      __init__.py
  2. 4
      __openerp__.py
  3. 21
      models.py
  4. 2
      security/ir.model.access.csv
  5. 2
      static/src/js/main.js
  6. 6
      static/src/xml/main.xml

1
__init__.py

@ -1,3 +1,2 @@
# -*- coding: utf-8 -*-
import controllers
import models

4
__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",

21
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:

2
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

2
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()

6
static/src/xml/main.xml

@ -5,9 +5,9 @@
<td t-att-colspan="colspan or '3'">
<div class="oe_view_manager_fetch_mail_imm">
<span>Last</span>
<a href="#" class="oe_fetch_new_mails"
name="get_fetchmail_obj" type="object">update:</a>
<span class="oe_view_manager_fetch_mail_imm_field">N</span><span> min ago</span>
<a href="#" class="oe_fetch_new_mails">update:</a>
<span class="oe_view_manager_fetch_mail_imm_field">0</span>
<span> minutes ago</span>
</div>
</td>
<td></td>

Loading…
Cancel
Save