Browse Source

GDPR Modules for OCA V11

- rework of search function to use ORM methods
- Changed Search View menu from configuration to separate menu in contacts
pull/10/head
ITISAG-OCA 6 years ago
parent
commit
1879f6d07e
  1. 0
      contact_search_form/__init__.py
  2. 0
      contact_search_form/__manifest__.py
  3. 0
      contact_search_form/i18n/de.po
  4. 0
      contact_search_form/i18n/en_US.po
  5. 0
      contact_search_form/models/__init__.py
  6. 79
      contact_search_form/models/contact_search.py
  7. 1
      contact_search_form/security/gdpr_security.xml
  8. 10
      contact_search_form/views/contact_search.xml

0
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

79
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+"."))
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)

1
contact_search_form/security/gdpr_security.xml

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="group_dpo" model="res.groups">
<field name="name">Data Protection Officer</field>
<field name="category_id" ref="base.module_category_hidden"/>

10
contact_search_form/views/contact_search.xml

@ -57,11 +57,17 @@
<!--</field>-->
</record>
<menuitem id="menu_customer_info_base"
name="Contact Search"
parent="contacts.menu_contacts"
sequence="20"
groups="contact_search_form.group_dpo"/>
<menuitem id="menu_customer_info"
name="Contact Search"
action="action_dpo_view_itis"
parent="contacts.res_partner_menu_config"
sequence="20"
parent="menu_customer_info_base"
sequence="21"
groups="contact_search_form.group_dpo"/>
<record id="search_line_tree_view_itis" model="ir.ui.view">

Loading…
Cancel
Save