Skip to content

Commit

Permalink
[MIG] website_sale_require_legal: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Tejeda committed Oct 14, 2020
1 parent bef5dac commit cc2f8a9
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 89 deletions.
1 change: 1 addition & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
brand
website
22 changes: 11 additions & 11 deletions website_sale_require_legal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Require accepting legal terms to checkout
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github
:target: https://github.com/OCA/e-commerce/tree/12.0/website_sale_require_legal
:target: https://github.com/OCA/e-commerce/tree/13.0/website_sale_require_legal
:alt: OCA/e-commerce
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/e-commerce-12-0/e-commerce-12-0-website_sale_require_legal
:target: https://translation.odoo-community.org/projects/e-commerce-13-0/e-commerce-13-0-website_sale_require_legal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/113/12.0
:target: https://runbot.odoo-community.org/runbot/113/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -61,7 +61,7 @@ Known issues / Roadmap
* Shopping terms and conditions are accepted only on user registration or
address edition. So if those terms change after the user signed up, a
notification should be made. An implicit acceptance could be printed in the
payment screen to solve this. Maybe that could be a work to develope in
payment screen to solve this. Maybe that could be a work to develop in
another module.

Bug Tracker
Expand All @@ -70,7 +70,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/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/e-commerce/issues/new?body=module:%20website_sale_require_legal%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/e-commerce/issues/new?body=module:%20website_sale_require_legal%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 All @@ -87,11 +87,11 @@ Contributors

* `Tecnativa <https://www.tecnativa.com>`_:

* Rafael Blasco <rafael.blasco@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
* Ernesto Tejeda <ernesto.tejeda87@gmail.com>
* Rafael Blasco
* Jairo Llopis
* Vicent Cubells
* David Vidal
* Ernesto Tejeda
* Cristina Martin R.

Maintainers
Expand All @@ -107,6 +107,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/e-commerce <https://github.com/OCA/e-commerce/tree/12.0/website_sale_require_legal>`_ project on GitHub.
This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/13.0/website_sale_require_legal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
9 changes: 4 additions & 5 deletions website_sale_require_legal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
{
"name": "Require accepting legal terms to checkout",
"summary": "Force the user to accept legal tems to buy in the web shop",
"version": "12.0.1.0.0",
"version": "13.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["web_tour", "website_legal_page", "website_sale",],
"data": ["views/website_sale.xml",],
"demo": ["demo/assets.xml",],
"depends": ["web_tour", "website_legal_page", "website_sale"],
"data": ["views/website_sale.xml", "views/assets.xml"],
}
15 changes: 6 additions & 9 deletions website_sale_require_legal/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

class WebsiteSale(main.WebsiteSale):
def _get_mandatory_billing_fields(self):
result = super(WebsiteSale, self)._get_mandatory_billing_fields()
result = super()._get_mandatory_billing_fields()
return result + self._mandatory_legal_terms()

def _get_mandatory_shipping_fields(self):
result = super(WebsiteSale, self)._get_mandatory_shipping_fields()
result = super()._get_mandatory_shipping_fields()
return result + self._mandatory_legal_terms()

def _mandatory_legal_terms(self):
Expand All @@ -28,17 +28,14 @@ def checkout_form_validate(self, mode, all_form_values, data):
"""Require accepting legal terms to validate form."""
# Patch context
old_context = request.context
new_context = dict(request.context, needs_legal=True)
request.context = new_context
result = super(WebsiteSale, self).checkout_form_validate(
mode, all_form_values, data
)
request.context = dict(request.context, needs_legal=True)
result = super().checkout_form_validate(mode, all_form_values, data)
# Unpatch context
request.context = old_context
return result

def _checkout_form_save(self, mode, checkout, all_values):
res = super(WebsiteSale, self)._checkout_form_save(mode, checkout, all_values)
res = super()._checkout_form_save(mode, checkout, all_values)
if all_values.get("submitted") and all_values.get("accepted_legal_terms"):
environ = request.httprequest.headers.environ
metadata = "Website legal terms acceptance metadata: "
Expand All @@ -48,7 +45,7 @@ def _checkout_form_save(self, mode, checkout, all_values):
)
partner_id = request.env["res.partner"].browse(res)
website_user = request.website.salesperson_id.id or SUPERUSER_ID
partner_id.sudo(website_user).message_post(
partner_id.with_user(website_user).message_post(
body=metadata, message_type="notification"
)
return res
13 changes: 0 additions & 13 deletions website_sale_require_legal/demo/assets.xml

This file was deleted.

10 changes: 5 additions & 5 deletions website_sale_require_legal/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Rafael Blasco <rafael.blasco@tecnativa.com>
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* David Vidal <david.vidal@tecnativa.com>
* Ernesto Tejeda <ernesto.tejeda87@gmail.com>
* Rafael Blasco
* Jairo Llopis
* Vicent Cubells
* David Vidal
* Ernesto Tejeda
* Cristina Martin R.
2 changes: 1 addition & 1 deletion website_sale_require_legal/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
* Shopping terms and conditions are accepted only on user registration or
address edition. So if those terms change after the user signed up, a
notification should be made. An implicit acceptance could be printed in the
payment screen to solve this. Maybe that could be a work to develope in
payment screen to solve this. Maybe that could be a work to develop in
another module.
18 changes: 9 additions & 9 deletions website_sale_require_legal/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Require accepting legal terms to checkout</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="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/e-commerce/tree/12.0/website_sale_require_legal"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/e-commerce-12-0/e-commerce-12-0-website_sale_require_legal"><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/113/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="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.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/e-commerce/tree/13.0/website_sale_require_legal"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/e-commerce-13-0/e-commerce-13-0-website_sale_require_legal"><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/113/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the functionality of your website shop to
support forcing the user to accept your legal advice, terms of use and privacy
policy, and allow you to comply with some countries’ laws.</p>
Expand Down Expand Up @@ -414,7 +414,7 @@ <h1><a class="toc-backref" href="#id4">Known issues / Roadmap</a></h1>
<li>Shopping terms and conditions are accepted only on user registration or
address edition. So if those terms change after the user signed up, a
notification should be made. An implicit acceptance could be printed in the
payment screen to solve this. Maybe that could be a work to develope in
payment screen to solve this. Maybe that could be a work to develop in
another module.</li>
</ul>
</div>
Expand All @@ -423,7 +423,7 @@ <h1><a class="toc-backref" href="#id5">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/e-commerce/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/e-commerce/issues/new?body=module:%20website_sale_require_legal%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/e-commerce/issues/new?body=module:%20website_sale_require_legal%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 All @@ -440,11 +440,11 @@ <h2><a class="toc-backref" href="#id8">Contributors</a></h2>
<li><p class="first"><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:</p>
<blockquote>
<ul class="simple">
<li>Rafael Blasco &lt;<a class="reference external" href="mailto:rafael.blasco&#64;tecnativa.com">rafael.blasco&#64;tecnativa.com</a>&gt;</li>
<li>Jairo Llopis &lt;<a class="reference external" href="mailto:jairo.llopis&#64;tecnativa.com">jairo.llopis&#64;tecnativa.com</a>&gt;</li>
<li>Vicent Cubells &lt;<a class="reference external" href="mailto:vicent.cubells&#64;tecnativa.com">vicent.cubells&#64;tecnativa.com</a>&gt;</li>
<li>David Vidal &lt;<a class="reference external" href="mailto:david.vidal&#64;tecnativa.com">david.vidal&#64;tecnativa.com</a>&gt;</li>
<li>Ernesto Tejeda &lt;<a class="reference external" href="mailto:ernesto.tejeda87&#64;gmail.com">ernesto.tejeda87&#64;gmail.com</a>&gt;</li>
<li>Rafael Blasco</li>
<li>Jairo Llopis</li>
<li>Vicent Cubells</li>
<li>David Vidal</li>
<li>Ernesto Tejeda</li>
<li>Cristina Martin R.</li>
</ul>
</blockquote>
Expand All @@ -458,7 +458,7 @@ <h2><a class="toc-backref" href="#id9">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/e-commerce/tree/12.0/website_sale_require_legal">OCA/e-commerce</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/e-commerce/tree/13.0/website_sale_require_legal">OCA/e-commerce</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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
input#accepted_legal_terms.is-invalid ~ .form-check-label a {
color: $red;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,9 @@ odoo.define("website_sale_require_legal.tour", function(require) {
var base = require("web_editor.base");
var tour = require("web_tour.tour");

// Get an option value by its text
// HACK https://github.com/odoo/odoo/pull/32718
function opt_val(option_text) {
return function(action_helper) {
var option_id = this.$anchor
.children(_.str.sprintf("option:contains('%s')", option_text))
.val();
action_helper.text(option_id);
};
}

var steps = [
// Buy chair floor protection
{
trigger: '.oe_product_cart a:contains("Chair floor protection")',
trigger: '.oe_product_cart a:contains("Customizable")',
},
{
trigger: "#add_to_cart",
Expand All @@ -30,30 +18,10 @@ odoo.define("website_sale_require_legal.tour", function(require) {
trigger: ".btn:contains('Process Checkout')",
},
// Fill all required fields except legal terms acceptance
{
run: "text Super Mario",
trigger: ".checkout_autoformat input[name=name]",
},
{
run: "text mario@example.com",
trigger: ".checkout_autoformat input[name=email]",
},
{
run: "text 000 000 000",
trigger: ".checkout_autoformat input[name=phone]",
},
{
run: "text Castle St., 1",
trigger: ".checkout_autoformat input[name=street]",
},
{
run: "text Mushroom Kingdom",
trigger: ".checkout_autoformat input[name=city]",
},
{
run: opt_val("Japan"),
trigger: ".checkout_autoformat select[name=country_id]",
},
// Submit, to check the lack of acceptance is a failure
{
trigger: ".btn-primary:contains('Next')",
Expand All @@ -65,6 +33,9 @@ odoo.define("website_sale_require_legal.tour", function(require) {
{
trigger: ".btn-primary:contains('Next')",
},
{
trigger: ".btn-primary:contains('Confirm')",
},
// If I can proceed to payment, it's because the form validated fine
{
trigger: ".btn-primary:contains('Pay Now')",
Expand Down
8 changes: 5 additions & 3 deletions website_sale_require_legal/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ def setUp(self):
"""Ensure website lang is en_US."""
super().setUp()
website = self.env["website"].get_current_website()
wiz = self.env["base.language.install"].create({"lang": "en_US",})
wiz = self.env["base.language.install"].create({"lang": "en_US"})
wiz.website_ids = website
wiz.lang_install()
website.default_lang_id = self.env.ref("base.lang_en")

def test_ui_website(self):
"""Test frontend tour."""
self.env.ref("base.partner_admin").email = False
tour = "website_sale_require_legal"
self.browser_js(
url_path="/shop",
code="odoo.__DEBUG__.services['web_tour.tour']" ".run('%s')" % tour,
ready="odoo.__DEBUG__.services['web_tour.tour']" ".tours.%s.ready" % tour,
code="odoo.__DEBUG__.services['web_tour.tour'].run('%s')" % tour,
ready="odoo.__DEBUG__.services['web_tour.tour'].tours.%s.ready" % tour,
login="admin",
)
22 changes: 22 additions & 0 deletions website_sale_require_legal/views/assets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 Jairo Llopis <jairo.llopis@tecnativa.com>
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<template id="assets_frontend" inherit_id="website.assets_frontend">
<xpath expr=".">
<link
rel="stylesheet"
type="text/scss"
href="/website_sale_require_legal/static/src/scss/website_sale_require_legal.scss"
/>
</xpath>
</template>
<template id="assets_tests" inherit_id="website.assets_tests">
<xpath expr=".">
<script
type="text/javascript"
src="/website_sale_require_legal/static/tests/tours/tour.js"
/>
</xpath>
</template>
</odoo>

0 comments on commit cc2f8a9

Please sign in to comment.