From 689472ef2c4e6a5bea16b2a9af0f6f0e491236f1 Mon Sep 17 00:00:00 2001 From: Kunjal Date: Wed, 1 Nov 2017 10:43:26 +0530 Subject: [PATCH] [FIX] : System Parameter. --- addons/mail/models/update.py | 78 +++++++++++-------- flectra/addons/base/ir/ir_config_parameter.py | 1 + flectra/tools/config.py | 3 +- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/addons/mail/models/update.py b/addons/mail/models/update.py index a653f609..599f5670 100644 --- a/addons/mail/models/update.py +++ b/addons/mail/models/update.py @@ -30,35 +30,41 @@ class PublisherWarrantyContract(AbstractModel): db_create_date = IrParamSudo.get_param('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) + limit_date_str = limit_date.strftime( + misc.DEFAULT_SERVER_DATETIME_FORMAT) nbr_users = Users.search_count([('active', '=', True)]) - nbr_active_users = Users.search_count([("login_date", ">=", limit_date_str), ('active', '=', True)]) + nbr_active_users = Users.search_count( + [("login_date", ">=", limit_date_str), ('active', '=', True)]) nbr_share_users = 0 nbr_active_share_users = 0 if "share" in Users._fields: - nbr_share_users = Users.search_count([("share", "=", True), ('active', '=', True)]) - nbr_active_share_users = Users.search_count([("share", "=", True), ("login_date", ">=", limit_date_str), ('active', '=', True)]) + nbr_share_users = Users.search_count( + [("share", "=", True), ('active', '=', True)]) + nbr_active_share_users = Users.search_count( + [("share", "=", True), ("login_date", ">=", limit_date_str), + ('active', '=', True)]) user = self.env.user - domain = [('application', '=', True), ('state', 'in', ['installed', 'to upgrade', 'to remove'])] + domain = [('application', '=', True), + ('state', 'in', ['installed', 'to upgrade', 'to remove'])] apps = self.env['ir.module.module'].sudo().search_read(domain, ['name']) - - enterprise_code = IrParamSudo.get_param('database.enterprise_code') + demo_domain = [('name', 'ilike', 'base'), ('demo', '=', True)] + demo_data_ids = self.env['ir.module.module'].sudo().search(demo_domain) + demo_data = True + if not demo_data_ids: + demo_data = False + support_code = IrParamSudo.get_param('database.support_code') web_base_url = IrParamSudo.get_param('web.base.url') - 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": self._cr.dbname, - "db_create_date": db_create_date, - "version": release.version, - "language": user.lang, - "web_base_url": web_base_url, - "apps": [app['name'] for app in apps], - "enterprise_code": enterprise_code, - } + 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": self._cr.dbname, "db_create_date": db_create_date, + "version": release.version, "language": user.lang, + "web_base_url": web_base_url, + "apps": [app['name'] for app in apps], + "support_code": support_code, + "demo_data": demo_data} if user.partner_id.company_id: company_id = user.partner_id.company_id msg.update(company_id.read(["name", "email", "phone"])[0]) @@ -89,16 +95,19 @@ class PublisherWarrantyContract(AbstractModel): """ try: # Code will be execute only if parameter value 'True' - parameter_id = self.env.ref("mail.config_update_notification") - if parameter_id and parameter_id.value != 'True': + parameter_id = self.env['ir.config_parameter'].sudo().get_param( + "send_statistics") + if parameter_id != 'True': return True try: result = self._get_sys_logs() except Exception: - if cron_mode: # we don't want to see any stack trace in cron + 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 UserError(_("Error during communication with the publisher warranty server.")) + _logger.debug("Exception while sending a get logs messages", + exc_info=1) + raise UserError(_( + "Error during communication with the publisher warranty server.")) # old behavior based on res.log; now on mail.message, that is not necessarily installed user = self.env['res.users'].sudo().browse(SUPERUSER_ID) poster = self.sudo().env.ref('mail.channel_all_employees') @@ -108,19 +117,24 @@ class PublisherWarrantyContract(AbstractModel): poster = user for message in result["messages"]: try: - poster.message_post(body=message, subtype='mt_comment', partner_ids=[user.partner_id.id]) + poster.message_post(body=message, subtype='mt_comment', + partner_ids=[user.partner_id.id]) except Exception: pass - if result.get('enterprise_info'): + if result.get('support_info'): # Update expiration date set_param = self.env['ir.config_parameter'].sudo().set_param - set_param('database.expiration_date', result['enterprise_info'].get('expiration_date')) - set_param('database.expiration_reason', result['enterprise_info'].get('expiration_reason', 'trial')) - set_param('database.enterprise_code', result['enterprise_info'].get('enterprise_code')) + set_param('database.expiration_date', + result['support_info'].get('expiration_date')) + set_param('database.expiration_reason', + result['support_info'].get('expiration_reason', + 'trial')) + set_param('database.support_code', + result['support_info'].get('support_code')) except Exception: if cron_mode: - return False # we don't want to see any stack trace in cron + return False # we don't want to see any stack trace in cron else: raise return True diff --git a/flectra/addons/base/ir/ir_config_parameter.py b/flectra/addons/base/ir/ir_config_parameter.py index 121d2410..08c6851b 100644 --- a/flectra/addons/base/ir/ir_config_parameter.py +++ b/flectra/addons/base/ir/ir_config_parameter.py @@ -20,6 +20,7 @@ _default_parameters = { "database.uuid": lambda: pycompat.text_type(uuid.uuid1()), "database.create_date": fields.Datetime.now, "web.base.url": lambda: "http://localhost:%s" % config.get('http_port'), + "send_statistics": lambda: "True", } diff --git a/flectra/tools/config.py b/flectra/tools/config.py index 0f050b42..e92f6ea1 100644 --- a/flectra/tools/config.py +++ b/flectra/tools/config.py @@ -74,7 +74,8 @@ class configmanager(object): self.options = { 'admin_passwd': 'admin', 'csv_internal_sep': ',', - 'publisher_warranty_url': 'http://services.flectrahq.com/publisher-warranty/', + 'publisher_warranty_url': + 'http://services.flectrahq.com/publisher-warranty/', 'reportgz': False, 'root_path': None, }