Skip to content

Commit

Permalink
[MIG] privacy_consent: version 13.0
Browse files Browse the repository at this point in the history
- Remove prefetching optimizations; v13 ORM does it better.
- Reset counters always in computed methods.
- Remove workaround for skipping duplicate consent creation message.
- Implement the new `_creation_subtype()` to let creation subscriptions keep on working.

@Tecnativa TT25941
  • Loading branch information
Jairo Llopis committed Jan 15, 2021
1 parent 1728222 commit ce67324
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 41 deletions.
10 changes: 5 additions & 5 deletions privacy_consent/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Privacy - Consent
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdata--protection-lightgray.png?logo=github
:target: https://github.com/OCA/data-protection/tree/12.0/privacy_consent
:target: https://github.com/OCA/data-protection/tree/13.0/privacy_consent
:alt: OCA/data-protection
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/data-protection-12-0/data-protection-12-0-privacy_consent
:target: https://translation.odoo-community.org/projects/data-protection-13-0/data-protection-13-0-privacy_consent
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/263/12.0
:target: https://runbot.odoo-community.org/runbot/263/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -136,7 +136,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/data-protection/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/data-protection/issues/new?body=module:%20privacy_consent%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/data-protection/issues/new?body=module:%20privacy_consent%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -173,6 +173,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/data-protection <https://github.com/OCA/data-protection/tree/12.0/privacy_consent>`_ project on GitHub.
This module is part of the `OCA/data-protection <https://github.com/OCA/data-protection/tree/13.0/privacy_consent>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion privacy_consent/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ConsentController(Controller):
@route(
"/privacy/consent/<any(accept,reject):choice>/" "<int:consent_id>/<token>",
"/privacy/consent/<any(accept,reject):choice>/<int:consent_id>/<token>",
type="http",
auth="none",
website=True,
Expand Down
10 changes: 2 additions & 8 deletions privacy_consent/models/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def _postprocess_sent_message(
and not failure_type
):
# Get related consent
consent = self.env["privacy.consent"].browse(
self.mail_message_id.res_id, self._prefetch,
)
consent = self.env["privacy.consent"].browse(self.mail_message_id.res_id)
# Set as sent if needed
if consent.state == "draft" and consent.partner_id.id in {
par.id for par in success_pids
Expand All @@ -48,11 +46,7 @@ def _send_prepare_body(self):
if self.model != "privacy.consent":
return result
# Tokenize consent links
consent = (
self.env["privacy.consent"]
.browse(self.mail_message_id.res_id)
.with_prefetch(self._prefetch)
)
consent = self.env["privacy.consent"].browse(self.mail_message_id.res_id)
result = result.replace("/privacy/consent/accept/", consent._url(True),)
result = result.replace("/privacy/consent/reject/", consent._url(False),)
return result
3 changes: 2 additions & 1 deletion privacy_consent/models/privacy_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,12 @@ def _default_consent_template_id(self):

@api.depends("consent_ids")
def _compute_consent_count(self):
self.consent_count = 0
groups = self.env["privacy.consent"].read_group(
[("activity_id", "in", self.ids)], ["activity_id"], ["activity_id"],
)
for group in groups:
self.browse(group["activity_id"][0], self._prefetch).consent_count = group[
self.browse(group["activity_id"][0]).consent_count = group[
"activity_id_count"
]

Expand Down
14 changes: 7 additions & 7 deletions privacy_consent/models/privacy_consent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ class PrivacyConsent(models.Model):
track_visibility="onchange",
)

def _creation_subtype(self):
return self.env.ref("privacy_consent.mt_consent_consent_new")

def _track_subtype(self, init_values):
"""Return specific subtypes."""
if self.env.context.get("subject_answering"):
return "privacy_consent.mt_consent_acceptance_changed"
if "activity_id" in init_values or "partner_id" in init_values:
return "privacy_consent.mt_consent_consent_new"
return self.env.ref("privacy_consent.mt_consent_acceptance_changed")
if "state" in init_values:
return "privacy_consent.mt_consent_state_changed"
return self.env.ref("privacy_consent.mt_consent_state_changed")
return super(PrivacyConsent, self)._track_subtype(init_values)

def _token(self):
Expand Down Expand Up @@ -115,10 +116,9 @@ def _run_action(self):
@api.model_create_multi
def create(self, vals_list):
"""Run server action on create."""
super_ = super(PrivacyConsent, self.with_context(mail_create_nolog=True))
results = super_.create(vals_list)
results = super().create(vals_list)
# Sync the default acceptance status
results.sudo()._run_action()
results._run_action()
return results

def write(self, vals):
Expand Down
7 changes: 4 additions & 3 deletions privacy_consent/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ class ResPartner(models.Model):
@api.depends("privacy_consent_ids")
def _compute_privacy_consent_count(self):
"""Count consent requests."""
self.privacy_consent_count = 0
groups = self.env["privacy.consent"].read_group(
[("partner_id", "in", self.ids)], ["partner_id"], ["partner_id"],
)
for group in groups:
self.browse(
group["partner_id"][0], self._prefetch
).privacy_consent_count = group["partner_id_count"]
self.browse(group["partner_id"][0]).privacy_consent_count = group[
"partner_id_count"
]
8 changes: 4 additions & 4 deletions privacy_consent/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Privacy - Consent</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Privacy - Consent</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/data-protection/tree/12.0/privacy_consent"><img alt="OCA/data-protection" src="https://img.shields.io/badge/github-OCA%2Fdata--protection-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/data-protection-12-0/data-protection-12-0-privacy_consent"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/263/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/data-protection/tree/13.0/privacy_consent"><img alt="OCA/data-protection" src="https://img.shields.io/badge/github-OCA%2Fdata--protection-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/data-protection-13-0/data-protection-13-0-privacy_consent"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/263/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module allows the user to define a set of subjects (partners)
affected by any data processing activity, and establish
a process to ask them for consent to include them in that activity.</p>
Expand Down Expand Up @@ -484,7 +484,7 @@ <h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/data-protection/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/data-protection/issues/new?body=module:%20privacy_consent%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/data-protection/issues/new?body=module:%20privacy_consent%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -516,7 +516,7 @@ <h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/data-protection/tree/12.0/privacy_consent">OCA/data-protection</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/data-protection/tree/13.0/privacy_consent">OCA/data-protection</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
19 changes: 7 additions & 12 deletions privacy_consent/views/privacy_consent.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
</header>
<sheet>
<div class="oe_button_box" name="button_box">
<button
class="oe_stat_button"
icon="fa-archive"
name="toggle_active"
type="object"
>
<field
name="active"
options='{"terminology": "archive"}'
widget="boolean_button"
/>
</button>
<field name="active" invisible="1" />
<widget
name="web_ribbon"
title="Archived"
bg_color="bg-danger"
attrs="{'invisible': [('active', '=', True)]}"
/>
</div>
<group>
<field name="partner_id" />
Expand Down

0 comments on commit ce67324

Please sign in to comment.