diff --git a/contact_search_form/__manifest__.py b/contact_search_form/__manifest__.py index 4dd4b21..65b9976 100644 --- a/contact_search_form/__manifest__.py +++ b/contact_search_form/__manifest__.py @@ -1,24 +1,28 @@ -############################################################################## +##################################################################### # # IT IS AG, software solutions: http://www.itis.de # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html # -############################################################################## +##################################################################### { 'name': "Contact Search Form", 'summary': """ - View for Data Protection Officer (DPO) to look up Customer Data. Odoo models can be searched for specified string. - To access contact search in contacts view, user must activate 'Data Protection Officer' checkbox in Technical Settings. + View for Data Protection Officer (DPO) to look up Customer Data. + Odoo models can be searched for specified string. + To access contact search in contacts view, user must activate + 'Data Protection Officer' checkbox + in Technical Settings. """, 'author': "IT IS AG, Odoo Community Association (OCA)", 'website': "https://github.com/OCA/data-protection", # Categories can be used to filter modules in modules listing - # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml + # Check https://github.com/odoo/odoo/blob/master/ + # openerp/addons/base/module/module_data.xml # for the full list 'version': '11.0.1.0.0', 'license': 'AGPL-3', diff --git a/contact_search_form/models/contact_search.py b/contact_search_form/models/contact_search.py index 17f636d..67662f3 100644 --- a/contact_search_form/models/contact_search.py +++ b/contact_search_form/models/contact_search.py @@ -9,7 +9,8 @@ class SearchLine(models.Model): model_id = fields.Many2one('ir.model', string="Found in Model") record_id = fields.Integer(string="Record ID") search_id = fields.Many2one("dpo.view", string="Search Terms") - record_name = fields.Char(string="Record Name", compute="_compute_record_name") + record_name = fields.Char(string="Record Name", + compute="_compute_record_name") @api.multi def open_record(self): @@ -26,7 +27,8 @@ class SearchLine(models.Model): @api.one def _compute_record_name(self): for record in self: - record_object = self.env[self.model_id.model].search([('id', '=', int(self.record_id))]) + record_object = self.env[self.model_id.model].\ + search([('id', '=', int(self.record_id))]) try: record.record_name = record_object.name except: @@ -36,22 +38,34 @@ class ItisDpoView(models.Model): _name = "dpo.view" name = fields.Char(string="Search Term") - model_ids = fields.Many2many('ir.model', 'dpo_view_ir_model_rel', string="Search in Model") - search_lines = fields.One2many('search.line', 'search_id', string='Search Result') + model_ids = fields.Many2many('ir.model', + 'dpo_view_ir_model_rel', + string="Search in Model") + search_lines = fields.One2many('search.line', + 'search_id', + string='Search Result') @api.multi def search_string(self): - search_line_ids = self.env['search.line'].search([('search_id', '=', self.id)]) + search_line_ids = self.env['search.line'].search([('search_id', + '=', + self.id)]) search_line_ids.unlink() final_list = [] for model_id in self.model_ids: field_list = [] found_match = {} for field_id in model_id.field_id: - if field_id.ttype in ['char', 'html', 'text'] and field_id.store: + if field_id.ttype in ['char', 'html', 'text'] \ + and field_id.store: field_list.append(field_id.name) for field in field_list: - records = self.env[model_id.model].search([(field, 'ilike', self.name), (field, '!=', '')]) + records = self.env[model_id.model].search([(field, + 'ilike', + self.name), + (field, + '!=', + '')]) for rec in records: temp_list = found_match.get(rec.id, False) if temp_list: diff --git a/website_contact_extend/__manifest__.py b/website_contact_extend/__manifest__.py index 90cdab6..3a0a33e 100644 --- a/website_contact_extend/__manifest__.py +++ b/website_contact_extend/__manifest__.py @@ -1,18 +1,20 @@ -############################################################################## +################################################################### # # IT IS AG, software solutions: http://www.itis.de # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html # -############################################################################## +################################################################### { 'name': "Website Contact Form Extend", 'summary': """ - Extended Website Contact View to give Customer the option on how to be contacted. + Extended Website Contact View to give Customer the option + on how to be contacted. - Customer can verifiy his email address with a verification link. Following that the mode of future contact can be chosen and + Customer can verifiy his email address with a verification link. + Following that the mode of future contact can be chosen and a GDPR information request can be submitted. """, @@ -21,7 +23,8 @@ 'website': "https://github.com/OCA/data-protection", # Categories can be used to filter modules in modules listing - # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml + # Check https://github.com/odoo/odoo/blob/master/openerp/ + # addons/base/module/module_data.xml # for the full list 'version': '11.0.1.0.0', 'license': 'AGPL-3', diff --git a/website_contact_extend/controllers/myfilter.py b/website_contact_extend/controllers/myfilter.py index 5fd749c..bc0e1bf 100644 --- a/website_contact_extend/controllers/myfilter.py +++ b/website_contact_extend/controllers/myfilter.py @@ -8,10 +8,15 @@ import json class VerifyController(http.Controller): - @http.route('/verify_email', type='http', auth="public", methods=['GET'], website=True) + @http.route('/verify_email', + type='http', + auth="public", + methods=['GET'], + website=True) def verify_email(self, **kwargs): if kwargs: - link_data = base64.b64decode(kwargs.get("data")).decode("utf-8").split("####") + link_data = base64.b64decode(kwargs.get("data")).decode("utf-8")\ + .split("####") email = link_data[0] contact_name = link_data[1] email_name = link_data[2] @@ -25,9 +30,10 @@ class VerifyController(http.Controller): diff = today - link if diff.days > 5 or diff.days < 0: return "
Not valid!
" \ - "The link you entered is either not valid or expired." \ + "The link you entered is either not valid or expired."\ "
Please request a new link.
" - partner = request.env['res.partner'].sudo().search([('email', '=', email), ('name', '=', contact_name)]) + partner = request.env['res.partner'].sudo().search\ + ([('email', '=', email), ('name', '=', contact_name)]) if partner: for part in partner: part.is_verified = True @@ -44,20 +50,29 @@ class VerifyController(http.Controller): part.letter_contact = True else: part.letter_contact = False - template = request.env.ref('website_contact_extend.confirmation_email_template').sudo().send_mail(part.id) - return "
Thank You! Your email address has been verified!
" + template = request.env.ref('website_contact_extend.' + 'confirmation_email_template')\ + .sudo().send_mail(part.id) + return "
" \ + "Thank You! Your email address has been verified!" \ + "
" else: return "
Not valid!
" \ - "The link you entered is either not valid or expired." \ + "The link you entered is either not valid or expired."\ "
Please request a new link.
" class MyFilter(parent_controller.WebsiteForm): - @http.route('/website_form/', type='http', auth="public", methods=['POST'], website=True) + @http.route('/website_form/', + type='http', + auth="public", + methods=['POST'], + website=True) def website_form(self, model_name, **kwargs): - model_record = request.env['ir.model'].sudo().search([('model', '=', model_name), - ('website_form_access', '=', True)]) + model_record = request.env['ir.model'].sudo()\ + .search([('model', '=', model_name), + ('website_form_access', '=', True)]) if not model_record: return json.dumps(False) # need_send_email = False @@ -74,28 +89,19 @@ class MyFilter(parent_controller.WebsiteForm): contact_type = field_value if field_name == "send_mail" and field_value == "send_mail": send_mail = True - if field_name == "phone_contact" and field_value == "phone_contact": + if field_name == "phone_contact" \ + and field_value == "phone_contact": phone_contact = True - if field_name == "letter_contact" and field_value == "letter_contact": + if field_name == "letter_contact" \ + and field_value == "letter_contact": letter_contact = True - if field_name == "email_contact" and field_value == "email_contact": + if field_name == "email_contact" \ + and field_value == "email_contact": email_contact = True index += 1 contact_name = data.get("record").get("contact_name") email_from = data.get("record").get("email_from") - # if data.get("record",False): - # partner_records = request.env['res.partner'].sudo().search([('name', '=', contact_name), - # ('email', '=', email_from)]) - # for partner_record in partner_records: - # if partner_record: - # if partner_record.is_verified: - # partner_record.contact_type = contact_type - # partner_record.phone_contact = phone_contact - # partner_record.email_contact = email_contact - # partner_record.letter_contact = letter_contact - # if not partner_record.is_verified: - # need_send_email = True # If we encounter an issue while extracting data except ValidationError as e: @@ -103,26 +109,38 @@ class MyFilter(parent_controller.WebsiteForm): return json.dumps({'error_fields': e.args[0]}) try: - id_record = self.insert_record(request, model_record, data['record'], data['custom'], data.get('meta')) + id_record = self.insert_record(request, + model_record, + data['record'], + data['custom'], + data.get('meta')) if id_record: - self.insert_attachment(model_record, id_record, data['attachments']) + self.insert_attachment(model_record, + id_record, + data['attachments']) if id_record and send_mail and model_name == "crm.lead": - crm_lead_obj = request.env['crm.lead'].sudo().search([('id', '=', id_record)]) + crm_lead_obj = request.env['crm.lead'].sudo()\ + .search([('id', '=', id_record)]) email_data = crm_lead_obj.email_from + "####" +\ crm_lead_obj.contact_name + "####" +\ str(email_contact) + "####" +\ str(phone_contact) + "####" +\ str(letter_contact)+"####" +\ str(crm_lead_obj.create_date) - ency_email = base64.b64encode(email_data.encode()).decode("utf-8") + ency_email = base64.b64encode(email_data.encode())\ + .decode("utf-8") action_url = '%s/verify_email/?data=%s' % ( - request.env['ir.config_parameter'].sudo().get_param('web.base.url'), + request.env['ir.config_parameter']. + sudo().get_param('web.base.url'), ency_email, ) if crm_lead_obj: crm_lead_obj.email_link = action_url - template = request.env.ref('website_contact_extend.verification_email_template').send_mail(id_record) - # Some fields have additional SQL constraints that we can't check generically + template = request.env.ref('website_contact_extend.' + 'verification_email_template')\ + .send_mail(id_record) + # Some fields have additional SQL constraints + # that we can't check generically # Ex: crm.lead.probability which is a float between 0 and 1 # TODO: How to get the name of the erroneous field ? except IntegrityError: diff --git a/website_contact_extend/models/res_partner.py b/website_contact_extend/models/res_partner.py index 8e370ed..b6c4c45 100644 --- a/website_contact_extend/models/res_partner.py +++ b/website_contact_extend/models/res_partner.py @@ -23,4 +23,4 @@ class ResContacts(models.Model): class CrmLead(models.Model): _inherit = "crm.lead" - email_link = fields.Char("Email verification link") \ No newline at end of file + email_link = fields.Char("Email verification link")