Skip to content

Commit

Permalink
[MIG] website_sale_require_login: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
azimkhankuat committed Oct 2, 2024
1 parent 44df5a9 commit b4f8bb9
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 86 deletions.
9 changes: 7 additions & 2 deletions website_sale_require_login/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
{
"name": "Require login to checkout",
"summary": "Force users to login for buying",
"version": "14.0.1.0.0",
"version": "17.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Tecnativa, " "LasLabs, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["website_sale_suggest_create_account", "web_tour"],
"data": ["views/website_sale.xml", "views/assets.xml"],
"data": ["views/website_sale.xml"],
"assets": {
"web.assets_tests": [
"website_sale_require_login/static/tests/tours/checkout.esm.js",
],
},
"post_init_hook": "post_init_hook",
}
16 changes: 10 additions & 6 deletions website_sale_require_login/hooks.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
# Copyright (C) 2020 Alexandre Díaz - Tecnativa S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID, api
from odoo.tools import config


def post_init_hook(cr, registry):
def post_init_hook(env):
if config["test_enable"] or config["test_file"]:
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
env.ref("website_sale_require_login.cart").active = False
env.ref("website_sale_require_login.short_cart_summary").active = False
cart_ref = env.ref("website_sale_require_login.cart", raise_if_not_found=False)
if cart_ref:
cart_ref.active = False

short_cart_summary_ref = env.ref(
"website_sale_require_login.short_cart_summary", raise_if_not_found=False
)
if short_cart_summary_ref:
short_cart_summary_ref.active = False

Check warning on line 16 in website_sale_require_login/hooks.py

View check run for this annotation

Codecov / codecov/patch

website_sale_require_login/hooks.py#L16

Added line #L16 was not covered by tests
34 changes: 34 additions & 0 deletions website_sale_require_login/static/tests/tours/checkout.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/** @odoo-module */

import {registry} from "@web/core/registry";

registry.category("web_tour.tours").add("shop_buy_checkout_required_login_website", {
test: true,
url: "/shop",
steps: () => [
// Shop Page
{
trigger: "td.oe_product a:first",
},
// Product Page
{
trigger: "#add_to_cart",
},
{
trigger: 'a.o_navlink_background.btn[href="/shop/cart"]',
},
{
trigger: '.oe_website_sale:not(a.btn-primary[href^="/shop/checkout"])',
run: function () {
// Check: do nothing
},
},
{
trigger: '.oe_website_sale:not(a.btn-default[href^="/shop/checkout"])',
run: function () {
// Check: do nothing
},
},
// The End
],
});
40 changes: 0 additions & 40 deletions website_sale_require_login/static/tests/tours/checkout.js

This file was deleted.

1 change: 0 additions & 1 deletion website_sale_require_login/tests/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ def test_01_shop_buy(self):
current_website = self.env["website"].get_current_website()
current_website.auth_signup_uninvited = "b2b"
self.env.ref("website_sale_require_login.cart").active = True
self.env.ref("website_sale_require_login.short_cart_summary").active = True
self.start_tour("/shop", "shop_buy_checkout_required_login_website")
15 changes: 0 additions & 15 deletions website_sale_require_login/views/assets.xml

This file was deleted.

23 changes: 1 addition & 22 deletions website_sale_require_login/views/website_sale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,11 @@
priority="20"
customize_show="True"
>
<xpath expr="//div[@id='wrap']" position="before">
<xpath expr="//t[@t-set='show_shorter_cart_summary']" position="before">
<t
t-set="hide_checkout_button"
t-value="not (user_authenticated and can_checkout)"
/>
</xpath>
<xpath
expr="//div[hasclass('oe_cart')]//a[@href='/shop/checkout?express=1']"
position="attributes"
>
<attribute name="t-if">not hide_checkout_button</attribute>
</xpath>
<xpath
expr="//div[hasclass('col-12','col-xl-4')]//a[@href='/shop/checkout?express=1']"
position="attributes"
>
<attribute name="t-if">not hide_checkout_button</attribute>
</xpath>
</template>
<template
id="short_cart_summary"
inherit_id="website_sale.short_cart_summary"
customize_show="True"
>
<xpath expr="//a[@href='/shop/checkout?express=1']" position="attributes">
<attribute name="t-if">not hide_checkout_button</attribute>
</xpath>
</template>
</odoo>

0 comments on commit b4f8bb9

Please sign in to comment.