Browse Source

Merge c4d3c8e524 into 695c8eecb5

pull/22/merge
Florian 3 years ago
committed by GitHub
parent
commit
a6efc02798
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      privacy_right_to_be_forgotten/README.rst
  2. 23
      privacy_right_to_be_forgotten/tests/common.py
  3. 30
      privacy_right_to_be_forgotten/tests/test_privacy_right_to_be_forgotten.py
  4. 26
      privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py

3
privacy_right_to_be_forgotten/README.rst

@ -51,7 +51,8 @@ Images
Contributors
------------
* George Daramouskas <gdaramouskas@therp.nl>
* George Daramouskas <gdaramouskas@therp.nl>
* Florian da Costa <florian.dacosta@akretion.com>
Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list <mailto:community@mail.odoo.com>`_ or the `appropriate specialized mailinglist <https://odoo-community.org/groups>`_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues.

23
privacy_right_to_be_forgotten/tests/common.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import SingleTransactionCase
from ..wizards.res_partner_gdpr import FIELDS_GDPR
class TestPrivacyGdpr(SingleTransactionCase):
def _create_test_customer(self):
vals = {}
for field in FIELDS_GDPR:
if field == 'name':
vals.update({field: 'Name'})
else:
vals.update({field: False})
return self.env['res.partner'].create(vals)
def _gdpr_cleanup(self, customer):
wiz = self.env['res.partner.gdpr'].create({
'partner_ids': [(6, False, customer.ids)]})
self.assertTrue(wiz.fields, True)
wiz.action_gdpr_res_partner_cleanup()

30
privacy_right_to_be_forgotten/tests/test_privacy_right_to_be_forgotten.py

@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Therp BV <https://therp.nl>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import SingleTransactionCase
from .common import TestPrivacyGdpr
from ..wizards.res_partner_gdpr import FIELDS_GDPR
CLEANUP_STRING = '*** GDPR removed ***'
class TestPrivacyGdpr(SingleTransactionCase):
class TestPrivacyGdprPartner(TestPrivacyGdpr):
at_install = False
post_install = True
@ -18,20 +16,14 @@ class TestPrivacyGdpr(SingleTransactionCase):
self._gdpr_cleanup(customer)
for field in FIELDS_GDPR:
attr = getattr(customer, field)
if attr:
if attr and isinstance(attr, basestring):
self.assertTrue(res_partner_gdpr._get_remove_text() in attr)
def _create_test_customer(self):
vals = {}
for field in FIELDS_GDPR:
if field == 'name':
vals.update({field: 'Name'})
else:
vals.update({field: False})
return self.env['res.partner'].create(vals)
def _gdpr_cleanup(self, customer):
wiz = self.env['res.partner.gdpr'].create({
'partner_ids': [(6, False, customer.ids)]})
self.assertTrue(wiz.fields, True)
wiz.action_gdpr_res_partner_cleanup()
def test_child_removal(self):
res_partner_gdpr = self.env['res.partner.gdpr']
customer = self._create_test_customer()
child = self.env['res.partner'].create({
'parent_id': customer.id,
'name': 'Child Partner'})
self._gdpr_cleanup(customer)
self.assertTrue(res_partner_gdpr._get_remove_text() in child.name)

26
privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py

@ -18,6 +18,7 @@ FIELDS_GDPR = [
'email',
'title',
'child_ids',
'comment',
]
@ -51,18 +52,31 @@ class ResPartnerGdpr(models.TransientModel):
@api.multi
def _pre_gdpr_cleanup(self):
if 'child_ids' in self.fields.mapped('name'):
childs = self.partner_ids.mapped('child_ids')
all_partners = self.partner_ids | childs
self.partner_ids = all_partners.ids
pass
@api.multi
def _gdpr_cleanup(self):
self.ensure_one()
@api.model
def _do_gdpr_cleanup(self, fields, records):
vals = {}
for field in self.fields:
if field.ttype in ['many2many', 'many2one', 'one2many', 'binary']:
for field in fields:
if field.ttype in ['many2one', 'binary']:
vals.update({field.name: False})
elif field.ttype in ['many2many']:
vals.update({field.name: [(5, _, _)]})
# To improve...
elif field.ttype in ['one2many']:
continue
else:
vals.update({field.name: self._get_remove_text()})
self.partner_ids.write(vals)
records.write(vals)
@api.multi
def _gdpr_cleanup(self):
self.ensure_one()
self._do_gdpr_cleanup(self.fields, self.partner_ids)
@api.multi
def _post_gdpr_cleanup(self):

Loading…
Cancel
Save