From 03aaa7c06905f28a19814287aa48cc0ab96463ca Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Tue, 5 Feb 2019 18:49:34 +0100 Subject: [PATCH 1/2] Recursively erase partner childs data --- privacy_right_to_be_forgotten/README.rst | 3 +- privacy_right_to_be_forgotten/tests/common.py | 23 ++++++++++++++ .../test_privacy_right_to_be_forgotten.py | 30 +++++++------------ .../wizards/res_partner_gdpr.py | 25 ++++++++++++---- 4 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 privacy_right_to_be_forgotten/tests/common.py diff --git a/privacy_right_to_be_forgotten/README.rst b/privacy_right_to_be_forgotten/README.rst index af2efe3..8caf8c6 100644 --- a/privacy_right_to_be_forgotten/README.rst +++ b/privacy_right_to_be_forgotten/README.rst @@ -51,7 +51,8 @@ Images Contributors ------------ -* George Daramouskas +* George Daramouskas +* Florian da Costa Do not contact contributors directly about help with questions or problems concerning this addon, but use the `community mailing list `_ or the `appropriate specialized mailinglist `_ for help, and the bug tracker linked in `Bug Tracker`_ above for technical issues. diff --git a/privacy_right_to_be_forgotten/tests/common.py b/privacy_right_to_be_forgotten/tests/common.py new file mode 100644 index 0000000..e47c5dc --- /dev/null +++ b/privacy_right_to_be_forgotten/tests/common.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Therp BV +# 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() diff --git a/privacy_right_to_be_forgotten/tests/test_privacy_right_to_be_forgotten.py b/privacy_right_to_be_forgotten/tests/test_privacy_right_to_be_forgotten.py index b18e3b6..ac31bf7 100644 --- a/privacy_right_to_be_forgotten/tests/test_privacy_right_to_be_forgotten.py +++ b/privacy_right_to_be_forgotten/tests/test_privacy_right_to_be_forgotten.py @@ -1,13 +1,11 @@ # -*- coding: utf-8 -*- # Copyright 2018 Therp BV # 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) diff --git a/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py b/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py index 689a702..5ba815c 100644 --- a/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py +++ b/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py @@ -51,18 +51,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): From c4d3c8e524fcbc5975cce3d932661efdf350891c Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Mon, 4 Mar 2019 17:12:18 +0100 Subject: [PATCH 2/2] Add missing partner field --- privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py | 1 + 1 file changed, 1 insertion(+) diff --git a/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py b/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py index 5ba815c..e7e5e4e 100644 --- a/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py +++ b/privacy_right_to_be_forgotten/wizards/res_partner_gdpr.py @@ -18,6 +18,7 @@ FIELDS_GDPR = [ 'email', 'title', 'child_ids', + 'comment', ]