1 # -*- coding: utf-8 -*-
10 from osv import osv, fields
11 from tools.translate import _
12 from tools.safe_eval import safe_eval
13 from tools.config import config
14 from tools import misc
16 _logger = logging.getLogger(__name__)
19 Time interval that will be used to determine up to which date we will
20 check the logs to see if a message we just received was already logged.
21 @type: datetime.timedelta
23 _PREVIOUS_LOG_CHECK = datetime.timedelta(days=365)
25 def get_sys_logs(self, cr, uid):
27 Utility method to send a publisher warranty get logs messages.
29 pool = pooler.get_pool(cr.dbname)
31 dbuuid = pool.get('ir.config_parameter').get_param(cr, uid, 'database.uuid')
32 db_create_date = pool.get('ir.config_parameter').get_param(cr, uid, 'database.create_date')
33 limit_date = datetime.datetime.now()
34 limit_date = limit_date - datetime.timedelta(15)
35 limit_date_str = limit_date.strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT)
36 nbr_users = pool.get("res.users").search(cr, uid, [], count=True)
37 nbr_active_users = pool.get("res.users").search(cr, uid, [("date", ">=", limit_date_str)], count=True)
38 nbr_share_users = False
39 nbr_active_share_users = False
40 if "share" in pool.get("res.users")._all_columns:
41 nbr_share_users = pool.get("res.users").search(cr, uid, [("share", "=", True)], count=True)
42 nbr_active_share_users = pool.get("res.users").search(cr, uid, [("share", "=", True), ("date", ">=", limit_date_str)], count=True)
43 user = pool.get("res.users").browse(cr, uid, uid)
45 web_base_url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url', 'False')
48 "nbr_users": nbr_users,
49 "nbr_active_users": nbr_active_users,
50 "nbr_share_users": nbr_share_users,
51 "nbr_active_share_users": nbr_active_share_users,
53 "db_create_date": db_create_date,
54 "version": release.version,
55 "language": user.lang,
56 "web_base_url": web_base_url,
58 msg.update(pool.get("res.company").read(cr,uid,[1],["name","email","phone"])[0])
60 add_arg = {"timeout":30} if sys.version_info >= (2,6) else {}
61 arguments = {'arg0': msg, "action": "update",}
62 arguments_raw = urllib.urlencode(arguments)
64 url = config.get("publisher_warranty_url")
66 uo = urllib2.urlopen(url, arguments_raw, **add_arg)
69 submit_result = uo.read()
70 result = safe_eval(submit_result)
75 class publisher_warranty_contract(osv.osv):
76 _name = "publisher_warranty.contract"
78 def update_notification(self, cr, uid, ids, cron_mode=True, context=None):
80 Send a message to OpenERP's publisher warranty server to check the
81 validity of the contracts, get notifications, etc...
83 @param cron_mode: If true, catch all exceptions (appropriate for usage in a cron).
84 @type cron_mode: boolean
88 result = get_sys_logs(self, cr, uid)
90 if cron_mode: # we don't want to see any stack trace in cron
92 _logger.debug("Exception while sending a get logs messages", exc_info=1)
93 raise osv.except_osv(_("Error"), _("Error during communication with the publisher warranty server."))
94 limit_date = (datetime.datetime.now() - _PREVIOUS_LOG_CHECK).strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT)
95 # old behavior based on res.log; now on mail.message, that is not necessarily installed
96 proxy = self.pool.get('mail.message')
98 model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'group_all_employees')
100 for message in result["messages"]:
103 'model' : 'mail.group',
107 proxy.create(cr, uid, values, context=context)
110 return False # we don't want to see any stack trace in cron
115 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: