Skip to content

Commit

Permalink
[MIG] website_sale_require_legal: Migration to version 17.0
Browse files Browse the repository at this point in the history
TT51564
  • Loading branch information
pilarvargas-tecnativa committed Nov 28, 2024
1 parent 70e9fd0 commit d72b08d
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 140 deletions.
8 changes: 4 additions & 4 deletions website_sale_require_legal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ To configure this module, you need to:

3. Go to your e-commerce and make a sample checkout.

4. Visit `/shop/address </shop/address>`__ and enable *Customize >
Require Legal Terms Acceptance*.
4. Visit `/shop/address </shop/address>`__ and enable in the web editor
*Customize > Require Legal Terms Acceptance*.

|image1|

This will require acceptance before recording a new address, and log
visitor's acceptance.

5. Visit `/shop/payment </shop/payment>`__ and enable *Customize >
Accept Terms & Conditions* (upstream Odoo feature).
5. Visit `/shop/payment </shop/payment>`__ and enable in the web editor
*Customize > Accept Terms & Conditions* (upstream Odoo feature).

|image2|

Expand Down
4 changes: 2 additions & 2 deletions website_sale_require_legal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Require accepting legal terms to checkout",
"summary": "Force the user to accept legal tems to buy in the web shop",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Tecnativa, Odoo Community Association (OCA)",
Expand All @@ -19,7 +19,7 @@
"/website_sale_require_legal/static/src/scss/website_sale_require_legal.scss",
],
"web.assets_tests": [
"/website_sale_require_legal/static/tests/tours/tour.js",
"/website_sale_require_legal/static/tests/tours/tour.esm.js",
],
},
}
11 changes: 8 additions & 3 deletions website_sale_require_legal/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from odoo import _, http
from odoo.http import request
from odoo.tools import Markup

from odoo.addons.website_sale.controllers import main

Expand Down Expand Up @@ -48,7 +49,6 @@ def _checkout_form_save(self, mode, checkout, all_values):
def _log_acceptance_metadata(self, record):
"""Log legal terms acceptance metadata."""
environ = request.httprequest.headers.environ
message = _("Website legal terms acceptance metadata: %s")
metadata = "<br/>".join(
f"{val}: {environ.get(val)}"
for val in (
Expand All @@ -57,7 +57,10 @@ def _log_acceptance_metadata(self, record):
"HTTP_ACCEPT_LANGUAGE",
)
)
record.sudo().message_post(body=message % metadata, message_type="notification")
message = Markup(_("Website legal terms acceptance metadata: %s") % metadata)
record.sudo().message_post(
body=message, message_type="notification", subtype_xmlid="mail.mt_comment"
)


class PaymentPortal(main.PaymentPortal):
Expand All @@ -70,7 +73,9 @@ def shop_payment_transaction(self, order_id, access_token, **kwargs):
"""
result = super().shop_payment_transaction(order_id, access_token, **kwargs)

Check warning on line 74 in website_sale_require_legal/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/controllers/main.py#L74

Added line #L74 was not covered by tests
# If the "Accept Terms & Conditions" view is disabled, we log nothing
if not request.website.viewref("website_sale.payment_sale_note").active:
if not request.website.viewref(
"website_sale.accept_terms_and_conditions"
).active:
return result

Check warning on line 79 in website_sale_require_legal/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/controllers/main.py#L79

Added line #L79 was not covered by tests
# Retrieve the sale order
if order_id:
Expand Down
6 changes: 3 additions & 3 deletions website_sale_require_legal/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ To configure this module, you need to:

3. Go to your e-commerce and make a sample checkout.

4. Visit [/shop/address](/shop/address) and enable *Customize \>
4. Visit [/shop/address](/shop/address) and enable in the web editor *Customize \>
Require Legal Terms Acceptance*.

![](../static/description/address-enable.png)

This will require acceptance before recording a new address, and log
visitor's acceptance.

5. Visit [/shop/payment](/shop/payment) and enable *Customize \> Accept
Terms & Conditions* (upstream Odoo feature).
5. Visit [/shop/payment](/shop/payment) and enable in the web editor *Customize \>
Accept Terms & Conditions* (upstream Odoo feature).

![](../static/description/payment-enable.png)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions website_sale_require_legal/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -415,14 +415,14 @@ <h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
</li>
<li><p class="first">Go to your e-commerce and make a sample checkout.</p>
</li>
<li><p class="first">Visit <a class="reference external" href="/shop/address">/shop/address</a> and enable <em>Customize &gt;
Require Legal Terms Acceptance</em>.</p>
<li><p class="first">Visit <a class="reference external" href="/shop/address">/shop/address</a> and enable in the web editor
<em>Customize &gt; Require Legal Terms Acceptance</em>.</p>
<p><img alt="image1" src="https://raw.githubusercontent.com/OCA/e-commerce/17.0/website_sale_require_legal/static/description/address-enable.png" /></p>
<p>This will require acceptance before recording a new address, and log
visitor’s acceptance.</p>
</li>
<li><p class="first">Visit <a class="reference external" href="/shop/payment">/shop/payment</a> and enable <em>Customize &gt;
Accept Terms &amp; Conditions</em> (upstream Odoo feature).</p>
<li><p class="first">Visit <a class="reference external" href="/shop/payment">/shop/payment</a> and enable in the web editor
<em>Customize &gt; Accept Terms &amp; Conditions</em> (upstream Odoo feature).</p>
<p><img alt="image2" src="https://raw.githubusercontent.com/OCA/e-commerce/17.0/website_sale_require_legal/static/description/payment-enable.png" /></p>
<p>This will require acceptance before paying the sale order, and log
visitor’s acceptance.</p>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
103 changes: 103 additions & 0 deletions website_sale_require_legal/static/tests/tours/tour.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/** @odoo-module */

/* Copyright 2017 Jairo Llopis <[email protected]>
* Copyright 2023 Pilar Vargas <[email protected]>
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */

import {registry} from "@web/core/registry";
import tourUtils from "@website_sale/js/tours/tour_utils";

registry.category("web_tour.tours").add("website_sale_require_legal_with_payment", {
test: true,
url: "/shop",
steps: () => [
...tourUtils.searchProduct("Storage Box"),
{
content: "select Storage Box",
trigger: '.oe_product_cart:first a:contains("Storage Box")',
},
{
content: "click on add to cart",
trigger: '#product_detail form[action^="/shop/cart/update"] #add_to_cart',
},
tourUtils.goToCart(),
tourUtils.goToCheckout(),
// Fill all required fields except legal terms acceptance
{
trigger: 'select[name="country_id"]',
run: function () {
$('input[name="phone"]').val("99999999");
// Required for test compatibility with the website_sale_vat_required module
$('input[name="vat"]').val("00000000X");
$('input[name="street"]').val("Castle St., 1");
$('input[name="city"]').val("Mushroom Kingdom");
$('input[name="zip"]').val("10000");
$("#country_id option:eq(1)").attr("selected", true);
},
},
// Submit, to prove that it is not possible to continue without accepting the legal terms
{
trigger: ".btn-primary:contains('Save address')",
},
// // Accept legal terms and accept again
{
trigger: "#accepted_legal_terms.is-invalid",
},
{
trigger: ".btn-primary:contains('Save address')",
},
{
trigger: "a[href='/shop/confirm_order']",
},
// If I can proceed to payment, it's because the form validated fine
{
trigger: "input[id='website_sale_tc_checkbox']",
},
...tourUtils.payWithTransfer(true),
],
});

registry.category("web_tour.tours").add("website_sale_require_legal", {
test: true,
url: "/shop",
steps: () => [
...tourUtils.searchProduct("Storage Box"),
{
content: "select Storage Box",
trigger: '.oe_product_cart:first a:contains("Storage Box")',
},
{
content: "click on add to cart",
trigger: '#product_detail form[action^="/shop/cart/update"] #add_to_cart',
},
tourUtils.goToCart(),
tourUtils.goToCheckout(),
// Fill all required fields except legal terms acceptance
{
trigger: 'select[name="country_id"]',
run: function () {
$('input[name="phone"]').val("99999999");
// Required for test compatibility with the website_sale_vat_required module
$('input[name="vat"]').val("00000000X");
$('input[name="street"]').val("Castle St., 1");
$('input[name="city"]').val("Mushroom Kingdom");
$('input[name="zip"]').val("10000");
$("#country_id option:eq(1)").attr("selected", true);
},
},
// Submit, to prove that it is not possible to continue without accepting the legal terms
{
trigger: ".btn-primary:contains('Save address')",
},
// // Accept legal terms and accept again
{
trigger: "#accepted_legal_terms.is-invalid",
},
{
trigger: ".btn-primary:contains('Save address')",
},
{
trigger: "a[href='/shop/confirm_order']",
},
],
});
84 changes: 0 additions & 84 deletions website_sale_require_legal/static/tests/tours/tour.js

This file was deleted.

2 changes: 1 addition & 1 deletion website_sale_require_legal/templates/website_sale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<template id="accept_input">
<div class="col-lg-12 mb-2">
<input
t-attf-class="form-check-input position-relative ml-0 mr-1 #{'is-invalid' if error and error.get('accepted_legal_terms') else ''}"
t-attf-class="form-check-input position-relative ms-0 me-1 #{'is-invalid' if error and error.get('accepted_legal_terms') else ''}"
type="checkbox"
name="accepted_legal_terms"
id="accepted_legal_terms"
Expand Down
Loading

0 comments on commit d72b08d

Please sign in to comment.