Skip to content

Commit

Permalink
T0485 Refactor legal fields
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Sep 14, 2023
1 parent 8c4dede commit 929f4dd
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 114 deletions.
5 changes: 5 additions & 0 deletions my_compassion/controllers/auth_signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# The licence is in the file __manifest__.py
#
##############################################################################
from datetime import datetime

from odoo import _
from odoo.http import request
Expand Down Expand Up @@ -50,3 +51,7 @@ def do_signup(self, qcontext):
"No sponsor found with this reference."
"Please try again."))
return super().do_signup(qcontext)

def _signup_with_values(self, token, values):
super()._signup_with_values(token, values)
request.env.user.partner_id.legal_agreement_date = datetime.now()
25 changes: 7 additions & 18 deletions my_compassion/templates/my_account_personal_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,25 @@
<t t-if="partner.date_agreed_child_protection_charter">
<span>Signing date: </span>
<t t-esc="partner.get_date('date_agreed_child_protection_charter', 'date_short')"/>
<a t-attf-href="/partner/#{partner.uuid}/child-protection-charter">(view agreement)</a>
<a href="/child-protection-charter">(view agreement)</a>
</t>
<t t-else="">
<form t-attf-action="/partner/{{partner.uuid}}/child-protection-charter">
<input type="hidden" name="redirect" t-att-value="request.httprequest.path" id="redirect"/>
<t t-set="input_value">Sign Child Protection Charter</t>
<input id="child_charter" class="btn btn-primary w-100" t-att-value="input_value" type="submit"/>
</form>
<a href="/partner/child-protection-charter?redirect=/my/information"
class="btn btn-primary w-100">Sign Child Protection Charter</a>
</t>
</div>
</div>

<!-- Data protection -->
<div class="row">
<div class="col-6 border-right">
<label>Data protection</label>
<label>Data protection and legal agreement</label>
</div>
<div class="col-6">
<t t-if="partner.privacy_statement_ids">
<t t-if="partner.legal_agreement_date">
<span>Signing date: </span>
<t t-esc="partner.get_date('privacy_statement_ids.agreement_date', 'date_short')"/>
<t t-set="data_protection_url">https://compassion.ch/protection-des-donnees/</t>
<a t-att-href="data_protection_url" target="_blank">(view agreement)</a>
</t>
<t t-else="">
<form t-attf-action="/partner/#{partner.uuid}/privacy-statement-agreement">
<input type="hidden" name="redirect" t-att-value="request.httprequest.path" id="redirect"/>
<t t-set="input_value">Accept Privacy Policy</t>
<input id="privacy_charter" class="btn btn-primary w-100" type="submit" t-att-value="input_value"/>
</form>
<t t-esc="partner.get_date('legal_agreement_date', 'date_short')"/>
<a href="/legal" target="_blank">(view agreement)</a>
</t>
</div>
</div>
Expand Down
13 changes: 13 additions & 0 deletions my_compassion/templates/signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
<input t-att-type="'hidden' if only_passwords else 'text'" name="sponsor_ref" id="sponsor_ref" class="form-control form-control-sm" placeholder="Put any known reference here for matching with your account..."/>
</div>
</xpath>
<xpath expr="//div[@class='form-group field-confirm_password']" position="after">
<input
type="checkbox"
value="accepted"
id="privacy_policy"
name="privacy_policy"
class="s_website_form_input form-check-input"
required="required"
/>
<label class="form-check-label" for="privacy_policy">
<t t-call="website_legal_page.acceptance_full" />
</label>
</xpath>
</template>

</odoo>
27 changes: 22 additions & 5 deletions website_child_protection/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ class ChildProtectionCharterController(http.Controller):
"""

@http.route(
route="/partner/<string:partner_uuid>/child-protection-charter",
route=["/partner/<string:partner_uuid>/child-protection-charter",
"/partner/child-protection-charter"],
auth="public",
website=True,
sitemap=False,
)
def child_protection_charter(self, partner_uuid, **kwargs):
def child_protection_charter(self, partner_uuid=None, **kwargs):
"""
This page allows a partner to sign the child protection charter.
:param partner_uuid: The uuid associated with the partner.
Expand All @@ -33,9 +34,14 @@ def child_protection_charter(self, partner_uuid, **kwargs):
"""
# Need sudo() to bypass domain restriction on res.partner for anonymous
# users.
partner = (
request.env["res.partner"].sudo().search([("uuid", "=", partner_uuid)])
)
if partner_uuid:
partner = (
request.env["res.partner"].sudo().search([
("uuid", "=", partner_uuid)])
)
else:
partner = request.env.user.partner_id
partner_uuid = partner.uuid

if not partner:
return request.redirect("/")
Expand Down Expand Up @@ -64,3 +70,14 @@ def child_protection_charter_agreed(self, redirect=None, **kwargs):
"website_child_protection.child_protection_charter_confirmation_page",
values,
)

@http.route(
route="/child-protection-charter",
auth="public",
website=True,
sitemap=False,
)
def child_protection_text_page(self, **kwargs):
return request.render(
"website_child_protection.charter_only_page"
)
10 changes: 10 additions & 0 deletions website_child_protection/templates/child_protection_charter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@
</div>
</t>
</template>

<template id="charter_only_page">
<t t-call="website.layout">
<div id="wrap">
<div class="container my-5">
<t t-call="website_child_protection.child_protection_charter_text"/>
</div>
</div>
</t>
</template>
</odoo>
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ def create(self, vals_list):
)
else:
partner = self.env.user.partner_id
partner.write({"has_agreed_child_protection_charter": True})
partner.write({
"date_agreed_child_protection_charter": fields.Datetime.now()
})
return forms
4 changes: 2 additions & 2 deletions website_sponsorship/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"partner_auto_match",
"partner_search_fuzzy",
"website_form",
"website_legal_page", # OCA/website
],
"data": [
"data/form_data.xml",
Expand All @@ -31,9 +32,8 @@
"templates/children_page.xml",
"templates/form_success_page.xml",
"templates/sponsorship_form.xml",
"templates/data_protection_page.xml",
"views/contract_origin_view.xml",
"views/data_protection_view.xml",
"views/partner_view.xml",
"views/child_view.xml",
],
"installable": True,
Expand Down
22 changes: 0 additions & 22 deletions website_sponsorship/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,6 @@ def sponsorship_confirmation(self, child_id, **kwargs):
},
)

@http.route(
[
"/data-protection",
"/data-protection/<string:version>",
],
type="http",
auth="public",
website=True,
)
def data_protection_page(self, version=None):
search_args = [("website_published", "=", True)] if request.env.user.share else []
if version:
search_args.append(("version", "=", version))
statement = request.env["compassion.privacy.statement"].search(
search_args, limit=1
)
if not statement:
raise NotFound()
return request.render(
"website_sponsorship.data_protection_page", {"main_object": statement}
)

@http.route(["/hold_a_child"], type="json", auth="public")
def hold_a_child(self):
return (
Expand Down
11 changes: 7 additions & 4 deletions website_sponsorship/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
##############################################################################
#
# Copyright (C) 2018 Compassion CH (http://www.compassion.ch)
# @author: Quentin Gigon <[email protected]>
# Copyright (C) 2018-2023 Compassion CH (https://www.compassion.ch)
# @author: Emanuel Cino <[email protected]>
#
# The licence is in the file __manifest__.py
#
##############################################################################

from . import (compassion_child, ir_qweb_html, privacy_statement,
recurring_contract_origin, res_partner_match)
from . import compassion_child
from . import ir_qweb_html
from . import recurring_contract_origin
from . import res_partner_match
from . import res_partner
19 changes: 0 additions & 19 deletions website_sponsorship/models/privacy_statement.py

This file was deleted.

8 changes: 8 additions & 0 deletions website_sponsorship/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import models, fields


class ResPartner(models.Model):
_inherit = "res.partner"

legal_agreement_date = fields.Datetime(
"Date of legal agreement", tracking=True)
10 changes: 0 additions & 10 deletions website_sponsorship/templates/data_protection_page.xml

This file was deleted.

11 changes: 10 additions & 1 deletion website_sponsorship/templates/sponsorship_form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@
required="required"
/>
<label class="form-check-label font-weight-normal" for="privacy_policy">
By submitting this form, I confirm the acceptance of the <a href="/data-protection" target="_blank">data protection policy</a>.
<t t-call="website_legal_page.acceptance_full" />
</label>
</div>
</div>
Expand All @@ -340,4 +340,13 @@
</div>
</div>
</template>

<template id="acceptance_full" inherit_id="website_legal_page.acceptance_full">
<xpath expr="//a" position="replace">
<a
href="/legal"
target="_blank"
>I accept the legal terms, the privacy policy &amp; conditions of Compassion.</a>
</xpath>
</template>
</odoo>
19 changes: 0 additions & 19 deletions website_sponsorship/views/data_protection_view.xml

This file was deleted.

12 changes: 12 additions & 0 deletions website_sponsorship/views/partner_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<record id="view_partner_form_compassion_legal" model="ir.ui.view">
<field name="name">res.partner.form.compassion.legal</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_personal_info.view_partner_form_compassion_birthdate"/>
<field name="arch" type="xml">
<field name="uuid" position="after">
<field name="legal_agreement_date"/>
</field>
</field>
</record>
</odoo>
14 changes: 1 addition & 13 deletions website_sponsorship/wizards/sponsorship_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,7 @@ def create(self, vals_list):
form.contract_id = self.env["recurring.contract"].create(
form._get_sponsorship_vals()
)
privacy_statement = self.env["compassion.privacy.statement"].search(
[], limit=1
)
if privacy_statement:
self.env["privacy.statement.agreement"].create(
{
"partner_id": form.partner_id.id,
"agreement_date": datetime.today(),
"privacy_statement_id": privacy_statement.id,
"version": privacy_statement.version,
"origin_signature": "new_sponsorship",
}
)
form.partner_id.legal_agreement_date = fields.Datetime.now()
return records

def write(self, vals):
Expand Down

0 comments on commit 929f4dd

Please sign in to comment.