From 1879f6d07e8561abc770a35eb18f0160dd1871ae Mon Sep 17 00:00:00 2001 From: ITISAG-OCA Date: Mon, 9 Jul 2018 19:03:03 +0200 Subject: [PATCH] GDPR Modules for OCA V11 - rework of search function to use ORM methods - Changed Search View menu from configuration to separate menu in contacts --- contact_search_form/__init__.py | 0 contact_search_form/__manifest__.py | 0 contact_search_form/i18n/de.po | 0 contact_search_form/i18n/en_US.po | 0 contact_search_form/models/__init__.py | 0 contact_search_form/models/contact_search.py | 79 +++++++------------ .../security/gdpr_security.xml | 1 - contact_search_form/views/contact_search.xml | 10 ++- 8 files changed, 38 insertions(+), 52 deletions(-) mode change 100644 => 100755 contact_search_form/__init__.py mode change 100644 => 100755 contact_search_form/__manifest__.py mode change 100644 => 100755 contact_search_form/i18n/de.po mode change 100644 => 100755 contact_search_form/i18n/en_US.po mode change 100644 => 100755 contact_search_form/models/__init__.py mode change 100644 => 100755 contact_search_form/models/contact_search.py diff --git a/contact_search_form/__init__.py b/contact_search_form/__init__.py old mode 100644 new mode 100755 diff --git a/contact_search_form/__manifest__.py b/contact_search_form/__manifest__.py old mode 100644 new mode 100755 diff --git a/contact_search_form/i18n/de.po b/contact_search_form/i18n/de.po old mode 100644 new mode 100755 diff --git a/contact_search_form/i18n/en_US.po b/contact_search_form/i18n/en_US.po old mode 100644 new mode 100755 diff --git a/contact_search_form/models/__init__.py b/contact_search_form/models/__init__.py old mode 100644 new mode 100755 diff --git a/contact_search_form/models/contact_search.py b/contact_search_form/models/contact_search.py old mode 100644 new mode 100755 index efb16dc..17f636d --- a/contact_search_form/models/contact_search.py +++ b/contact_search_form/models/contact_search.py @@ -1,7 +1,6 @@ from odoo import api, fields, models, _ from odoo.exceptions import UserError - class SearchLine(models.Model): _name = "search.line" @@ -28,8 +27,10 @@ class SearchLine(models.Model): def _compute_record_name(self): for record in self: record_object = self.env[self.model_id.model].search([('id', '=', int(self.record_id))]) - record.record_name = record_object.name - + try: + record.record_name = record_object.name + except: + record.record_name = "Name" class ItisDpoView(models.Model): _name = "dpo.view" @@ -42,50 +43,30 @@ class ItisDpoView(models.Model): def search_string(self): search_line_ids = self.env['search.line'].search([('search_id', '=', self.id)]) search_line_ids.unlink() - found = False - for model in self.model_ids: - table_name = model.model.replace(".", "_") - query = '''select * from {} where ''' - params = (table_name,) - field_list = self.env['ir.model.fields'].search([('model_id.id', '=', model.id), - ('ttype', 'in', ['char', 'html', 'text']), - ('store', '=', True)]) + 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: + field_list.append(field_id.name) for field in field_list: - query = query + '''{}.{} like '%{}%' or ''' - temp = list(params) - temp.append(table_name) - temp.append(field.name) - temp.append(self.name) - params = tuple(temp) - query = query[:-3] - query += ''';''' - query = query.format(*params) - - self._cr.execute(query) - colnames = [desc[0] for desc in self._cr.description] - id_index = colnames.index("id") - rec_id = 0 - rows = self._cr.fetchall() - - if rows: - for rec in rows: - ind = 0 - rec_id = rec[id_index] - founded_col = [] - for row in rec: - if str(row).find(self.name) >= 0: - founded_col.append(colnames[ind]) - found = True - ind += 1 - fields_data = self.env['ir.model.fields'].search([('name', 'in', founded_col), - ('model_id', '=', model.id)]) - field_desc = [] - for field in fields_data: - field_desc.append(field.field_description) - create_id = self.env['search.line'].create({"field_list": str(field_desc), - "name": model.name, - "model_id": int(model.id), - "search_id": int(self.id), - "record_id": int(rec_id)}) - if not found: - raise UserError(_("No record found with "+self.name+".")) \ No newline at end of file + 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: + temp_list.append(field) + found_match[rec.id] = temp_list + else: + found_match[rec.id] = [field] + for key, value in found_match.items(): + founded_json = {} + founded_json["field_list"] = str(list(set(value))) + founded_json["name"] = str(model_id.name) + founded_json["model_id"] = model_id.id + founded_json["search_id"] = self.id + founded_json["record_id"] = key + final_list.append(founded_json) + if final_list: + for vals in final_list: + create_id = self.env['search.line'].create(vals) \ No newline at end of file diff --git a/contact_search_form/security/gdpr_security.xml b/contact_search_form/security/gdpr_security.xml index 512470e..29998b0 100755 --- a/contact_search_form/security/gdpr_security.xml +++ b/contact_search_form/security/gdpr_security.xml @@ -1,7 +1,6 @@ - Data Protection Officer diff --git a/contact_search_form/views/contact_search.xml b/contact_search_form/views/contact_search.xml index 77cb137..5779f2b 100755 --- a/contact_search_form/views/contact_search.xml +++ b/contact_search_form/views/contact_search.xml @@ -57,11 +57,17 @@ + +