From 523f3a0e685c7d855071a3aa27d7f5b9562cd5de Mon Sep 17 00:00:00 2001 From: "Antoine Prieels (ANP)" Date: Thu, 22 Nov 2018 15:45:30 +0000 Subject: [PATCH] [IMP] crm_reveal: Usability Improvements - Rename labels and reorder fields - Add support for states - Add contact_filter_type - Add filter_on_size closes odoo/odoo#28968 --- addons/crm_reveal/i18n/crm_reveal.pot | 155 ++++++++++++------- addons/crm_reveal/models/crm_reveal_rule.py | 57 ++++--- addons/crm_reveal/models/crm_reveal_view.py | 4 +- addons/crm_reveal/models/ir.py | 3 +- addons/crm_reveal/views/crm_reveal_views.xml | 63 ++++---- 5 files changed, 167 insertions(+), 115 deletions(-) diff --git a/addons/crm_reveal/i18n/crm_reveal.pot b/addons/crm_reveal/i18n/crm_reveal.pot index 16fc4824ff7..b1f34596c8a 100644 --- a/addons/crm_reveal/i18n/crm_reveal.pot +++ b/addons/crm_reveal/i18n/crm_reveal.pot @@ -4,10 +4,10 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server saas~11.5\n" +"Project-Id-Version: Odoo Server 13.0alpha1+e\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-10-02 10:05+0000\n" -"PO-Revision-Date: 2018-10-02 10:05+0000\n" +"POT-Creation-Date: 2018-12-04 09:24+0000\n" +"PO-Revision-Date: 2018-12-04 09:24+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -34,6 +34,11 @@ msgstr "" msgid "(Time Now)" msgstr "" +#. module: crm_reveal +#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form +msgid "1 credit is consumed per visitor matching the website traffic conditions and whose company can be identified.
" +msgstr "" + #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_1 msgid "3D Printing" @@ -64,11 +69,6 @@ msgstr "" msgid " Opportunities " msgstr "" -#. module: crm_reveal -#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form -msgid " people " -msgstr "" - #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_2 msgid "Accounting" @@ -239,6 +239,11 @@ msgstr "" msgid "Chemicals" msgstr "" +#. module: crm_reveal +#: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__lead_for +msgid "Choose whether to track companies only or companies and their contacts" +msgstr "" + #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_23 msgid "Civil Engineering" @@ -292,7 +297,17 @@ msgstr "" #. module: crm_reveal #: selection:crm.reveal.rule,lead_for:0 -msgid "Companies + Contacts" +msgid "Companies and their Contacts" +msgstr "" + +#. module: crm_reveal +#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__company_size_min +msgid "Company Size" +msgstr "" + +#. module: crm_reveal +#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__company_size_max +msgid "Company Size Max" msgstr "" #. module: crm_reveal @@ -412,11 +427,6 @@ msgstr "" msgid "Created on" msgstr "" -#. module: crm_reveal -#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__calculate_credits -msgid "Credit Used" -msgstr "" - #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_222 msgid "Data Processing & Outsourced Services" @@ -537,7 +547,7 @@ msgid "Energy Equipment & Services" msgstr "" #. module: crm_reveal -#: code:addons/crm_reveal/models/crm_reveal_rule.py:73 +#: code:addons/crm_reveal/models/crm_reveal_rule.py:74 #, python-format msgid "Enter Valid Regex." msgstr "" @@ -557,11 +567,6 @@ msgstr "" msgid "Events" msgstr "" -#. module: crm_reveal -#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__extra_contacts -msgid "Extra Contacts" -msgstr "" - #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_45 msgid "Eyewear" @@ -577,6 +582,21 @@ msgstr "" msgid "Family Services" msgstr "" +#. module: crm_reveal +#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__contact_filter_type +msgid "Filter On" +msgstr "" + +#. module: crm_reveal +#: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__filter_on_size +msgid "Filter companies based on their size." +msgstr "" + +#. module: crm_reveal +#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__filter_on_size +msgid "Filter on Size" +msgstr "" + #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_48 msgid "Finance" @@ -642,6 +662,11 @@ msgstr "" msgid "Forums" msgstr "" +#. module: crm_reveal +#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form +msgid "From" +msgstr "" + #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_56 msgid "Fundraising" @@ -802,11 +827,6 @@ msgstr "" msgid "IT Services" msgstr "" -#. module: crm_reveal -#: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__lead_for -msgid "If you track company data, one credit will be consumed per lead/opportunity created. If you track company and contacts data, two credits will be consumed. Such data will be visible in the lead/opportunity." -msgstr "" - #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_66 msgid "Import & Export" @@ -838,13 +858,13 @@ msgid "Industrials & Manufacturing" msgstr "" #. module: crm_reveal -#: model:ir.model,name:crm_reveal.model_crm_reveal_industry -msgid "Industry Tag" +#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__industry_tag_ids +msgid "Industries" msgstr "" #. module: crm_reveal -#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__industry_tag_ids -msgid "Industry Tags" +#: model:ir.model,name:crm_reveal.model_crm_reveal_industry +msgid "Industry Tag" msgstr "" #. module: crm_reveal @@ -1000,12 +1020,6 @@ msgstr "" msgid "Leave empty to always match. Odoo will not create lead if no match" msgstr "" -#. module: crm_reveal -#: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__company_size_max -#: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__company_size_min -msgid "Leave it as 0 if you don't want to use this filter." -msgstr "" - #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_79 msgid "Legal Services" @@ -1036,6 +1050,11 @@ msgstr "" msgid "Machinery" msgstr "" +#. module: crm_reveal +#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form +msgid "Make sure you know if you have to be GDPR compliant for storing personal data." +msgstr "" + #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_188 msgid "Marine" @@ -1066,14 +1085,9 @@ msgstr "" msgid "Materials" msgstr "" -#. module: crm_reveal -#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__company_size_max -msgid "Max Company Size" -msgstr "" - #. module: crm_reveal #: sql_constraint:crm.reveal.rule:0 -msgid "Maximum 5 extra contacts are allowed!" +msgid "Maximum 5 contacts are allowed!" msgstr "" #. module: crm_reveal @@ -1106,11 +1120,6 @@ msgstr "" msgid "Military" msgstr "" -#. module: crm_reveal -#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__company_size_min -msgid "Min Company Size" -msgstr "" - #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_89 msgid "Mining & Metals" @@ -1162,12 +1171,6 @@ msgstr "" msgid "Networking" msgstr "" -#. module: crm_reveal -#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form -msgid "No credit is consumed if the company is not found.
\n" -" 1 credit is consumed if the company is found.
" -msgstr "" - #. module: crm_reveal #: model_terms:ir.actions.act_window,help:crm_reveal.crm_reveal_rule_action msgid "No rule found" @@ -1183,6 +1186,11 @@ msgstr "" msgid "Not Found" msgstr "" +#. module: crm_reveal +#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__extra_contacts +msgid "Number of Contacts" +msgstr "" + #. module: crm_reveal #: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__leads_count msgid "Number of Generated Leads" @@ -1203,6 +1211,11 @@ msgstr "" msgid "Only visitors of following countries will be converted into leads/opportunities (using GeoIP)." msgstr "" +#. module: crm_reveal +#: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__state_ids +msgid "Only visitors of following states will be converted into leads/opportunities." +msgstr "" + #. module: crm_reveal #: selection:crm.reveal.rule,lead_type:0 msgid "Opportunity" @@ -1435,6 +1448,11 @@ msgstr "" msgid "Road & Rail" msgstr "" +#. module: crm_reveal +#: selection:crm.reveal.rule,contact_filter_type:0 +msgid "Role" +msgstr "" + #. module: crm_reveal #: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_role__name msgid "Role Name" @@ -1491,6 +1509,7 @@ msgid "Semiconductors & Semiconductor Equipment" msgstr "" #. module: crm_reveal +#: selection:crm.reveal.rule,contact_filter_type:0 #: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__seniority_id msgid "Seniority" msgstr "" @@ -1555,6 +1574,11 @@ msgstr "" msgid "State" msgstr "" +#. module: crm_reveal +#: model:ir.model.fields,field_description:crm_reveal.field_crm_reveal_rule__state_ids +msgid "States" +msgstr "" + #. module: crm_reveal #: model:crm.reveal.industry,name:crm_reveal.crm_reveal_industry_128 msgid "Stores" @@ -1622,7 +1646,7 @@ msgstr "" #. module: crm_reveal #: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__extra_contacts -msgid "This is the number of extra contacts to track if their role and seniority match your criteria.Their details will show up in the history thread of generated leads/opportunities. One credit is consumed per tracked contact." +msgid "This is the number of contacts to track if their role/seniority match your criteria. Their details will show up in the history thread of generated leads/opportunities. One credit is consumed per tracked contact." msgstr "" #. module: crm_reveal @@ -1680,6 +1704,11 @@ msgstr "" msgid "URL Expression" msgstr "" +#. module: crm_reveal +#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form +msgid "Up to" +msgstr "" + #. module: crm_reveal #: model:ir.model.fields,help:crm_reveal.field_crm_reveal_rule__sequence msgid "Used to order the rules with same URL and countries. Rules with a lower sequence number will be processed first." @@ -1735,6 +1764,11 @@ msgstr "" msgid "Wireless Telecommunication Services" msgstr "" +#. module: crm_reveal +#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form +msgid "additional credit(s) are consumed if the company matches this rule." +msgstr "" + #. module: crm_reveal #: model:crm.reveal.role,name:crm_reveal.crm_reveal_role_1 msgid "ceo" @@ -1750,11 +1784,6 @@ msgstr "" msgid "consulting" msgstr "" -#. module: crm_reveal -#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form -msgid "credits are consumed if the company matches the rule." -msgstr "" - #. module: crm_reveal #: model:crm.reveal.role,name:crm_reveal.crm_reveal_role_4 msgid "customer_service" @@ -1775,6 +1804,11 @@ msgstr "" msgid "education" msgstr "" +#. module: crm_reveal +#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form +msgid "employees" +msgstr "" + #. module: crm_reveal #: model:crm.reveal.role,name:crm_reveal.crm_reveal_role_6 msgid "engineering" @@ -1870,3 +1904,8 @@ msgstr "" msgid "sale" msgstr "" +#. module: crm_reveal +#: model_terms:ir.ui.view,arch_db:crm_reveal.crm_reveal_rule_form +msgid "to" +msgstr "" + diff --git a/addons/crm_reveal/models/crm_reveal_rule.py b/addons/crm_reveal/models/crm_reveal_rule.py index 52e66972700..ee56b4dd521 100644 --- a/addons/crm_reveal/models/crm_reveal_rule.py +++ b/addons/crm_reveal/models/crm_reveal_rule.py @@ -29,25 +29,26 @@ class CRMRevealRule(models.Model): # Website Traffic Filter country_ids = fields.Many2many('res.country', string='Countries', help='Only visitors of following countries will be converted into leads/opportunities (using GeoIP).') + state_ids = fields.Many2many('res.country.state', string='States', help='Only visitors of following states will be converted into leads/opportunities.') regex_url = fields.Char(string='URL Expression', help='Regex to track website pages. Leave empty to track the entire website, or / to target the homepage. Example: /page* to track all the pages which begin with /page') sequence = fields.Integer(help='Used to order the rules with same URL and countries. ' 'Rules with a lower sequence number will be processed first.') # Company Criteria Filter - industry_tag_ids = fields.Many2many('crm.reveal.industry', string='Industry Tags', help='Leave empty to always match. Odoo will not create lead if no match') - company_size_min = fields.Integer(string='Min Company Size', help="Leave it as 0 if you don't want to use this filter.") - company_size_max = fields.Integer(string='Max Company Size', help="Leave it as 0 if you don't want to use this filter.") + industry_tag_ids = fields.Many2many('crm.reveal.industry', string='Industries', help='Leave empty to always match. Odoo will not create lead if no match') + filter_on_size = fields.Boolean(string="Filter on Size", default=True, help="Filter companies based on their size.") + company_size_min = fields.Integer(string='Company Size', default=0) + company_size_max = fields.Integer(default=1000) # Contact Generation Filter + contact_filter_type = fields.Selection([('role', 'Role'), ('seniority', 'Seniority')], string="Filter On", required=True, default='role') preferred_role_id = fields.Many2one('crm.reveal.role', string='Preferred Role') other_role_ids = fields.Many2many('crm.reveal.role', string='Other Roles') seniority_id = fields.Many2one('crm.reveal.seniority', string='Seniority') - extra_contacts = fields.Integer(string='Extra Contacts', help='This is the number of extra contacts to track if their role and seniority match your criteria.Their details will show up in the history thread of generated leads/opportunities. One credit is consumed per tracked contact.') - - calculate_credits = fields.Integer(compute='_compute_credit_count', string='Credit Used', readonly=True) + extra_contacts = fields.Integer(string='Number of Contacts', help='This is the number of contacts to track if their role/seniority match your criteria. Their details will show up in the history thread of generated leads/opportunities. One credit is consumed per tracked contact.', default=1) # Lead / Opportunity Data - lead_for = fields.Selection([('companies', 'Companies'), ('people', 'Companies + Contacts')], string='Data Tracking', required=True, default='companies', help='If you track company data, one credit will be consumed per lead/opportunity created. If you track company and contacts data, two credits will be consumed. Such data will be visible in the lead/opportunity.') + lead_for = fields.Selection([('companies', 'Companies'), ('people', 'Companies and their Contacts')], string='Data Tracking', required=True, default='companies', help='Choose whether to track companies only or companies and their contacts') lead_type = fields.Selection([('lead', 'Lead'), ('opportunity', 'Opportunity')], string='Type', required=True, default='opportunity') suffix = fields.Char(string='Suffix', help='This will be appended in name of generated lead so you can identify lead/opportunity is generated with this rule') team_id = fields.Many2one('crm.team', string='Sales Channel') @@ -61,7 +62,7 @@ class CRMRevealRule(models.Model): # This limits the number of extra contact. # Even if more than 5 extra contacts provided service will return only 5 contacts (see service module for more) _sql_constraints = [ - ('limit_extra_contacts', 'check(extra_contacts >= 0 and extra_contacts <= 5)', 'Maximum 5 extra contacts are allowed!'), + ('limit_extra_contacts', 'check(extra_contacts >= 1 and extra_contacts <= 5)', 'Maximum 5 contacts are allowed!'), ] @api.constrains('regex_url') @@ -89,16 +90,6 @@ class CRMRevealRule(models.Model): self.clear_caches() # Clear the cache in order to recompute _get_active_rules return super(CRMRevealRule, self).unlink() - @api.depends('extra_contacts', 'lead_for') - def _compute_credit_count(self): - """ Computes maximum IAP credit can be consumed per lead """ - credit = 1 - if self.lead_for == 'people': - credit += 1 - if self.extra_contacts: - credit += self.extra_contacts - self.calculate_credits = credit - def _compute_leads_count(self): leads = self.env['crm.lead'].read_group([ ('reveal_rule_id', 'in', self.ids) @@ -133,12 +124,14 @@ class CRMRevealRule(models.Model): { 'id': 0, 'url': ***, - 'country_codes': ['BE', 'US'] + 'country_codes': ['BE', 'US'], + 'state_codes': [('BE', False), ('US', 'NY'), ('US', 'CA')] }, { 'id': 1, 'url': ***, - 'country_codes': ['BE'] + 'country_codes': ['BE'], + 'state_codes': [('BE', False)] } ] } @@ -154,10 +147,21 @@ class CRMRevealRule(models.Model): elif regex_url == '/': regex_url = '.*/$' # for home countries = rule.country_ids.mapped('code') + + # First apply rules for any state in countries + states = [(country_id.code, False) for country_id in rule.country_ids] + if rule.state_ids: + for state_id in rule.state_ids: + if (state_id.country_id.code, False) in states: + # Remove country because rule doesn't apply to any state + states.remove((state_id.country_id.code, False)) + states += [(state_id.country_id.code, state_id.code)] + rules.append({ 'id': rule.id, 'regex': regex_url, - 'country_codes': countries + 'country_codes': countries, + 'state_codes': states }) for country in countries: country_rules = self._add_to_country(country_rules, country, len(rules) - 1) @@ -175,16 +179,19 @@ class CRMRevealRule(models.Model): country_rules[country].append(rule_index) return country_rules - def _match_url(self, url, country_code, rules_excluded): + def _match_url(self, url, country_code, state_code, rules_excluded): """ Return the matching rule based on the country and URL. """ all_rules = self._get_active_rules() rules_id = all_rules['country_rules'].get(country_code, []) + rules_matched = [] for rule_index in rules_id: rule = all_rules['rules'][rule_index] - if str(rule['id']) not in rules_excluded and re.search(rule['regex'], url): + if ((country_code, state_code) in rule['state_codes'] or (country_code, False) in rule['state_codes'])\ + and str(rule['id']) not in rules_excluded\ + and re.search(rule['regex'], url): rules_matched.append(rule) return rules_matched @@ -274,6 +281,7 @@ class CRMRevealRule(models.Model): 'rule_id': rule.id, 'lead_for': rule.lead_for, 'countries': rule.country_ids.mapped('code'), + 'filter_on_size': rule.filter_on_size, 'company_size_min': rule.company_size_min, 'company_size_max': rule.company_size_max, 'industry_tags': rule.industry_tag_ids.mapped('reveal_id'), @@ -281,10 +289,11 @@ class CRMRevealRule(models.Model): } if rule.lead_for == 'people': data.update({ + 'contact_filter_type': rule.contact_filter_type, 'preferred_role': rule.preferred_role_id.reveal_id or '', 'other_roles': rule.other_role_ids.mapped('reveal_id'), 'seniority': rule.seniority_id.reveal_id or '', - 'extra_contacts': rule.extra_contacts + 'extra_contacts': rule.extra_contacts - 1 }) rule_payload[rule.id] = data return rule_payload diff --git a/addons/crm_reveal/models/crm_reveal_view.py b/addons/crm_reveal/models/crm_reveal_view.py index 8da0f4fbe07..3159bc30b4f 100644 --- a/addons/crm_reveal/models/crm_reveal_view.py +++ b/addons/crm_reveal/models/crm_reveal_view.py @@ -40,9 +40,9 @@ class CRMRevealView(models.Model): domain.append(('create_date', '<', fields.Datetime.to_string(datetime.date.today() - relativedelta(weeks=weeks_valid)))) self.search(domain).unlink() - def _create_reveal_view(self, url, ip_address, country_code, rules_excluded): + def _create_reveal_view(self, url, ip_address, country_code, state_code, rules_excluded): # we are avoiding reveal if reveal_view already created for this IP - rules = self.env['crm.reveal.rule']._match_url(url, country_code, rules_excluded) + rules = self.env['crm.reveal.rule']._match_url(url, country_code, state_code, rules_excluded) if rules: query = """ INSERT INTO crm_reveal_view (reveal_ip, reveal_rule_id, reveal_state, create_date) diff --git a/addons/crm_reveal/models/ir.py b/addons/crm_reveal/models/ir.py index fcc3eac46c7..ef514a052ad 100644 --- a/addons/crm_reveal/models/ir.py +++ b/addons/crm_reveal/models/ir.py @@ -19,13 +19,14 @@ class IrHttp(models.AbstractModel): # created from another module, e.g. website_form if not lead_id: country_code = 'geoip' in request.session and request.session['geoip'].get('country_code') + state_code = 'geoip' in request.session and request.session['geoip'].get('region') if country_code: try: url = request.httprequest.url ip_address = request.httprequest.remote_addr rules_excluded = (request.httprequest.cookies.get('rule_ids') or '').split(',') before = time.time() - new_rules_excluded = request.env['crm.reveal.view'].sudo()._create_reveal_view(url, ip_address, country_code, rules_excluded) + new_rules_excluded = request.env['crm.reveal.view'].sudo()._create_reveal_view(url, ip_address, country_code, state_code, rules_excluded) # even when we match, no view may have been created if this is a duplicate _logger.info('Reveal process time: [%s], match rule: [%s?], country code: [%s], ip: [%s]', time.time() - before, new_rules_excluded == rules_excluded, country_code, diff --git a/addons/crm_reveal/views/crm_reveal_views.xml b/addons/crm_reveal/views/crm_reveal_views.xml index 45bc19b2f1f..537f0a631e1 100644 --- a/addons/crm_reveal/views/crm_reveal_views.xml +++ b/addons/crm_reveal/views/crm_reveal_views.xml @@ -23,48 +23,51 @@ -
- -
-
+
- - - - - - - - - - +
+
+ + + + + + + + + +
+
+ + +
+
-