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 21, 2024
1 parent 70e9fd0 commit 134d448
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 127 deletions.
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",
],
},
}
4 changes: 3 additions & 1 deletion website_sale_require_legal/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,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 71 in website_sale_require_legal/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/controllers/main.py#L71

Added line #L71 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 76 in website_sale_require_legal/controllers/main.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/controllers/main.py#L76

Added line #L76 was not covered by tests
# Retrieve the sale order
if order_id:
Expand Down
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
81 changes: 42 additions & 39 deletions website_sale_require_legal/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,50 +33,53 @@ def setUp(self):
website.viewref(
"website_sale_require_legal.address_require_legal"
).active = True
website.viewref("website_sale.payment_sale_note").active = True
new_test_user(self.env, login="super_mario", groups="base.group_portal")
# Create a dummy payment provider to ensure that the tour has at least one
# available to it.
arch = """
<form action="dummy" method="post">
<input type="hidden" name="view_id" t-att-value="viewid"/>
<input type="hidden" name="user_id" t-att-value="user_id.id"/>
</form>
"""
redirect_form = self.env["ir.ui.view"].create(
{
"name": "Dummy Redirect Form",
"type": "qweb",
"arch": arch,
}
)
self.dummy_provider = self.env["payment.provider"].create(
{
"name": "Dummy Provider",
"code": "none",
"state": "test",
"is_published": True,
"allow_tokenization": True,
"redirect_form_view_id": redirect_form.id,
}
website.viewref("website_sale.accept_terms_and_conditions").active = True
self.user = new_test_user(
self.env,
login="super_mario",
groups="base.group_portal",
password="super_mario",
name="Super Mario",
)

def test_ui_website(self):
"""Test frontend tour."""
self.start_tour("/shop", "website_sale_require_legal", login="super_mario")
order = self.env["sale.order"].search(
[
("partner_id", "ilike", "super_mario"),
("website_id", "!=", "False"),
]
)
partner = order.partner_id
# Assert that the sale order and partner have metadata logs
self.assertTrue(
order.message_ids.filtered(
lambda one: "Website legal terms acceptance metadata" in one.body
if self.env["ir.module.module"]._get("payment_custom").state != "installed":
self.start_tour(
"/shop",
"website_sale_require_legal",
stepDelay=100,
login="super_mario",
)
)
else:
transfer_provider = self.env.ref("payment.payment_provider_transfer")
transfer_provider.write(

Check warning on line 56 in website_sale_require_legal/tests/test_ui.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/tests/test_ui.py#L55-L56

Added lines #L55 - L56 were not covered by tests
{
"state": "enabled",
"is_published": True,
}
)
transfer_provider._transfer_ensure_pending_msg_is_set()
self.start_tour(

Check warning on line 63 in website_sale_require_legal/tests/test_ui.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/tests/test_ui.py#L62-L63

Added lines #L62 - L63 were not covered by tests
"/shop",
"website_sale_require_legal_with_payment",
stepDelay=100,
login="super_mario",
)
order = self.env["sale.order"].search(

Check warning on line 69 in website_sale_require_legal/tests/test_ui.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/tests/test_ui.py#L69

Added line #L69 was not covered by tests
[
("partner_id", "ilike", "super_mario"),
("website_id", "!=", "False"),
]
)
# Assert that the sale order have metadata logs
self.assertTrue(

Check warning on line 76 in website_sale_require_legal/tests/test_ui.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_legal/tests/test_ui.py#L76

Added line #L76 was not covered by tests
order.message_ids.filtered(
lambda one: "Website legal terms acceptance metadata" in one.body
)
)
# Assert that the partner have metadata logs
partner = self.user.partner_id
self.assertTrue(
partner.message_ids.filtered(
lambda one: "Website legal terms acceptance metadata" in one.body
Expand Down

0 comments on commit 134d448

Please sign in to comment.