[MERGE] get the notifications from openerp
bzr revid: stw@openerp.com-20121008105034-6xu2xrnun8rm2g8x
This commit is contained in:
commit
b641983fbf
|
@ -33,6 +33,7 @@ import report
|
|||
import wizard
|
||||
import res_config
|
||||
import mail_group_menu
|
||||
import update
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -13,6 +13,20 @@
|
|||
<field eval="'()'" name="args"/>
|
||||
</record>
|
||||
|
||||
<record id="ir_cron_module_update_notification" model="ir.cron">
|
||||
<field name="name">Update Notification</field>
|
||||
<field eval="True" name="active" />
|
||||
<field name="user_id" ref="base.user_root" />
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">weeks</field>
|
||||
<field name="numbercall">-1</field>
|
||||
<field eval="False" name="doall" />
|
||||
<field eval="'ir.module.module'" name="model" />
|
||||
<field eval="'update_notification'" name="function" />
|
||||
<field eval="'(None,)'" name="args" />
|
||||
<field name="priority">1000</field>
|
||||
</record>
|
||||
|
||||
<record id="mt_comment" model="mail.message.subtype">
|
||||
<field name="name">comment</field>
|
||||
</record>
|
||||
|
|
|
@ -504,7 +504,7 @@ class mail_message(osv.Model):
|
|||
if not values.get('message_id') and values.get('res_id') and values.get('model'):
|
||||
values['message_id'] = tools.generate_tracking_message_id('%(model)s-%(res_id)s' % values)
|
||||
newid = super(mail_message, self).create(cr, uid, values, context)
|
||||
self._notify(cr, 1, newid, context=context)
|
||||
self._notify(cr, SUPERUSER_ID, newid, context=context)
|
||||
return newid
|
||||
|
||||
def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import logging
|
||||
import sys
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
import pooler
|
||||
import release
|
||||
from osv import osv, fields
|
||||
from tools.translate import _
|
||||
from tools.safe_eval import safe_eval
|
||||
from tools.config import config
|
||||
from tools import misc
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
"""
|
||||
Time interval that will be used to determine up to which date we will
|
||||
check the logs to see if a message we just received was already logged.
|
||||
@type: datetime.timedelta
|
||||
"""
|
||||
_PREVIOUS_LOG_CHECK = datetime.timedelta(days=365)
|
||||
|
||||
def get_sys_logs(cr, uid):
|
||||
"""
|
||||
Utility method to send a publisher warranty get logs messages.
|
||||
"""
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
||||
dbuuid = pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
|
||||
db_create_date = pool.get('ir.config_parameter').get_param(cr, uid, 'database.create_date')
|
||||
limit_date = datetime.datetime.now()
|
||||
limit_date = limit_date - datetime.timedelta(15)
|
||||
limit_date_str = limit_date.strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
nbr_users = pool.get("res.users").search(cr, uid, [], count=True)
|
||||
nbr_active_users = pool.get("res.users").search(cr, uid, [("date", ">=", limit_date_str)], count=True)
|
||||
nbr_share_users = False
|
||||
nbr_active_share_users = False
|
||||
if "share" in pool.get("res.users")._all_columns:
|
||||
nbr_share_users = pool.get("res.users").search(cr, uid, [("share", "=", True)], count=True)
|
||||
nbr_active_share_users = pool.get("res.users").search(cr, uid, [("share", "=", True), ("date", ">=", limit_date_str)], count=True)
|
||||
user = pool.get("res.users").browse(cr, uid, uid)
|
||||
msg = {
|
||||
"dbuuid": dbuuid,
|
||||
"nbr_users": nbr_users,
|
||||
"nbr_active_users": nbr_active_users,
|
||||
"nbr_share_users": nbr_share_users,
|
||||
"nbr_active_share_users": nbr_active_share_users,
|
||||
"dbname": cr.dbname,
|
||||
"db_create_date": db_create_date,
|
||||
"version": release.version,
|
||||
"language": user.lang,
|
||||
}
|
||||
msg.update(pool.get("res.company").read(cr,uid,[1],["name","email","phone"])[0])
|
||||
|
||||
add_arg = {"timeout":30} if sys.version_info >= (2,6) else {}
|
||||
arguments = {'arg0': msg, "action": "update",}
|
||||
arguments_raw = urllib.urlencode(arguments)
|
||||
|
||||
url = config.get("publisher_warranty_url")
|
||||
uo = urllib2.urlopen(url, arguments_raw, **add_arg)
|
||||
result = {}
|
||||
try:
|
||||
submit_result = uo.read()
|
||||
result = safe_eval(submit_result)
|
||||
finally:
|
||||
uo.close()
|
||||
return result
|
||||
|
||||
class publisher_warranty_contract(osv.osv):
|
||||
_name = "publisher_warranty.contract"
|
||||
|
||||
def update_notification(self, cr, uid, ids, cron_mode=True, context=None):
|
||||
"""
|
||||
Send a message to OpenERP's publisher warranty server to check the
|
||||
validity of the contracts, get notifications, etc...
|
||||
|
||||
@param cron_mode: If true, catch all exceptions (appropriate for usage in a cron).
|
||||
@type cron_mode: boolean
|
||||
"""
|
||||
try:
|
||||
try:
|
||||
result = get_sys_logs(cr, uid)
|
||||
except Exception:
|
||||
if cron_mode: # we don't want to see any stack trace in cron
|
||||
return False
|
||||
_logger.debug("Exception while sending a get logs messages", exc_info=1)
|
||||
raise osv.except_osv(_("Error"), _("Error during communication with the publisher warranty server."))
|
||||
limit_date = (datetime.datetime.now() - _PREVIOUS_LOG_CHECK).strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT)
|
||||
# old behavior based on res.log; now on mail.message, that is not necessarily installed
|
||||
proxy = self.pool.get('mail.message')
|
||||
|
||||
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'group_all_employees')
|
||||
|
||||
for message in result["messages"]:
|
||||
values = {
|
||||
'body' : message,
|
||||
'model' : 'mail.group',
|
||||
'res_id' : res_id,
|
||||
'user_id' : False,
|
||||
}
|
||||
proxy.create(cr, uid, values, context=context)
|
||||
except Exception:
|
||||
if cron_mode:
|
||||
return False # we don't want to see any stack trace in cron
|
||||
else:
|
||||
raise
|
||||
return True
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
Loading…
Reference in New Issue