diff --git a/website_sale_require_legal/README.rst b/website_sale_require_legal/README.rst index e9078db6b5..bb35ece9f4 100644 --- a/website_sale_require_legal/README.rst +++ b/website_sale_require_legal/README.rst @@ -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 `__ and enable *Customize > - Require Legal Terms Acceptance*. +4. Visit `/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 `__ and enable *Customize > - Accept Terms & Conditions* (upstream Odoo feature). +5. Visit `/shop/payment `__ and enable in the web editor + *Customize > Accept Terms & Conditions* (upstream Odoo feature). |image2| diff --git a/website_sale_require_legal/__manifest__.py b/website_sale_require_legal/__manifest__.py index f54e91c2db..bbb3b73fa0 100644 --- a/website_sale_require_legal/__manifest__.py +++ b/website_sale_require_legal/__manifest__.py @@ -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)", @@ -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", ], }, } diff --git a/website_sale_require_legal/controllers/main.py b/website_sale_require_legal/controllers/main.py index a5c5381047..e1d41cd12c 100644 --- a/website_sale_require_legal/controllers/main.py +++ b/website_sale_require_legal/controllers/main.py @@ -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 @@ -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 = "
".join( f"{val}: {environ.get(val)}" for val in ( @@ -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): @@ -70,7 +73,9 @@ def shop_payment_transaction(self, order_id, access_token, **kwargs): """ result = super().shop_payment_transaction(order_id, access_token, **kwargs) # 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 # Retrieve the sale order if order_id: diff --git a/website_sale_require_legal/readme/CONFIGURE.md b/website_sale_require_legal/readme/CONFIGURE.md index a365d14373..2b471db289 100644 --- a/website_sale_require_legal/readme/CONFIGURE.md +++ b/website_sale_require_legal/readme/CONFIGURE.md @@ -6,7 +6,7 @@ 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) @@ -14,8 +14,8 @@ To configure this module, you need to: 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) diff --git a/website_sale_require_legal/static/description/address-enable.png b/website_sale_require_legal/static/description/address-enable.png index c5b316fc1e..ef7f5ea24a 100644 Binary files a/website_sale_require_legal/static/description/address-enable.png and b/website_sale_require_legal/static/description/address-enable.png differ diff --git a/website_sale_require_legal/static/description/index.html b/website_sale_require_legal/static/description/index.html index e5ae13d0fe..2e465e655a 100644 --- a/website_sale_require_legal/static/description/index.html +++ b/website_sale_require_legal/static/description/index.html @@ -415,14 +415,14 @@

Configuration

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

  • -
  • Visit /shop/address and enable Customize > -Require Legal Terms Acceptance.

    +
  • Visit /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.

  • -
  • Visit /shop/payment and enable Customize > -Accept Terms & Conditions (upstream Odoo feature).

    +
  • Visit /shop/payment and enable in the web editor +Customize > Accept Terms & Conditions (upstream Odoo feature).

    image2

    This will require acceptance before paying the sale order, and log visitor’s acceptance.

    diff --git a/website_sale_require_legal/static/description/payment-enable.png b/website_sale_require_legal/static/description/payment-enable.png index fb062460a3..ff4238419d 100644 Binary files a/website_sale_require_legal/static/description/payment-enable.png and b/website_sale_require_legal/static/description/payment-enable.png differ diff --git a/website_sale_require_legal/static/tests/tours/tour.esm.js b/website_sale_require_legal/static/tests/tours/tour.esm.js new file mode 100644 index 0000000000..de86df8283 --- /dev/null +++ b/website_sale_require_legal/static/tests/tours/tour.esm.js @@ -0,0 +1,103 @@ +/** @odoo-module */ + +/* Copyright 2017 Jairo Llopis + * Copyright 2023 Pilar Vargas + * 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']", + }, + ], +}); diff --git a/website_sale_require_legal/static/tests/tours/tour.js b/website_sale_require_legal/static/tests/tours/tour.js deleted file mode 100644 index 0f251334ce..0000000000 --- a/website_sale_require_legal/static/tests/tours/tour.js +++ /dev/null @@ -1,84 +0,0 @@ -/* Copyright 2017 Jairo Llopis - * Copyright 2023 Pilar Vargas - * License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ - -odoo.define("website_sale_require_legal.tour", function (require) { - "use strict"; - - var tour = require("web_tour.tour"); - - var steps = [ - { - trigger: '.oe_product_cart a:contains("Customizable")', - }, - { - trigger: "#add_to_cart", - }, - { - trigger: "button:contains('Proceed to Checkout')", - }, - { - trigger: "a[href='/shop/cart']", - extra_trigger: "sup.my_cart_quantity:contains('1')", - }, - { - trigger: 'a:contains("Process Checkout")', - }, - { - trigger: "a[href='/shop/checkout']", - }, - // 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('Next')", - }, - // Accept legal terms and accept again - { - trigger: "#accepted_legal_terms.is-invalid", - }, - { - trigger: ".btn-primary:contains('Next')", - }, - { - trigger: "a[href='/shop/confirm_order']", - }, - // If I can proceed to payment, it's because the form validated fine - { - trigger: "div[name='o_checkbox_container'] input", - }, - { - trigger: ".btn-primary:contains('Pay Now')", - }, - { - trigger: '#payment_method label:contains("Dummy Provider")', - }, - { - trigger: 'button[name="o_payment_submit_button"]', - }, - ]; - - tour.register( - "website_sale_require_legal", - { - url: "/shop", - test: true, - }, - steps - ); - - return { - steps: steps, - }; -}); diff --git a/website_sale_require_legal/templates/website_sale.xml b/website_sale_require_legal/templates/website_sale.xml index 972e00d7bd..0ba6474643 100644 --- a/website_sale_require_legal/templates/website_sale.xml +++ b/website_sale_require_legal/templates/website_sale.xml @@ -6,7 +6,7 @@