From 1e4152b25559fd2efd79cce9f90f222e7231a21d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Rahir?= Date: Wed, 17 Jul 2019 14:56:40 +0000 Subject: [PATCH] [FIX] crm_reveal: warn user on missing GeoIP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GeoIP lib is necessary for this module to run but there is zero documentation on that specificity. This commit adds a bus notification to inform the user of the absence of the package through the webclient notification system. closes odoo/odoo#34968 Signed-off-by: Rémi Rahir (rar) --- addons/crm_reveal/models/crm_reveal_rule.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/crm_reveal/models/crm_reveal_rule.py b/addons/crm_reveal/models/crm_reveal_rule.py index 52e66972700..39491ce3dd3 100644 --- a/addons/crm_reveal/models/crm_reveal_rule.py +++ b/addons/crm_reveal/models/crm_reveal_rule.py @@ -8,7 +8,7 @@ import re from dateutil.relativedelta import relativedelta from math import floor, log10 -from odoo import api, fields, models, tools, _ +from odoo import api, fields, models, tools, _, _geoip_resolver from odoo.addons.iap import jsonrpc from odoo.addons.crm.models import crm_stage from odoo.exceptions import ValidationError @@ -72,9 +72,18 @@ class CRMRevealRule(models.Model): except Exception: raise ValidationError(_('Enter Valid Regex.')) + @api.model + def _assert_geoip(self): + if not _geoip_resolver: + message = _('Lead Generation requires a GeoIP resolver which could not be found on your system. Please consult https://pypi.org/project/GeoIP/.') + self.env['bus.bus'].sendone( + (self._cr.dbname, 'res.partner', self.env.user.partner_id.id), + {'type': 'simple_notification', 'title': _('Missing Library'), 'message': message, 'sticky': True, 'warning': True}) + @api.model def create(self, vals): self.clear_caches() # Clear the cache in order to recompute _get_active_rules + self._assert_geoip() return super(CRMRevealRule, self).create(vals) def write(self, vals): @@ -83,6 +92,7 @@ class CRMRevealRule(models.Model): } if set(vals.keys()) & fields_set: self.clear_caches() # Clear the cache in order to recompute _get_active_rules + self._assert_geoip() return super(CRMRevealRule, self).write(vals) def unlink(self):