Skip to content

Commit

Permalink
[MIG] website_sale_suggest_create_account: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cem-adhoc committed Jul 25, 2024
1 parent d10e905 commit 5fb276a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 81 deletions.
2 changes: 1 addition & 1 deletion website_sale_suggest_create_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Suggest to create user account when buying",
"summary": "Suggest users to create an account when buying in the website",
"version": "16.0.1.1.0",
"version": "17.0.1.0.0",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Tecnativa, LasLabs, Odoo Community Association (OCA)",
Expand Down
7 changes: 2 additions & 5 deletions website_sale_suggest_create_account/hooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# 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):
# This is here to not broke the tests. The idea:
# - XML changes in website are made using 'customize_show=True'
# - When Odoo is running in testing mode, we disable our changes
Expand All @@ -14,6 +13,4 @@ def post_init_hook(cr, registry):
# For CI/CD avoids problems testing modules that removes/positioning elements
# that other modules uses in their tests.
if config["test_enable"] or config["test_file"]:
env = api.Environment(cr, SUPERUSER_ID, {})
env.ref("website_sale_suggest_create_account.cart").active = False
env.ref("website_sale_suggest_create_account.short_cart_summary").active = False
env.ref("website_sale_suggest_create_account.navigation_buttons").active = False
3 changes: 1 addition & 2 deletions website_sale_suggest_create_account/tests/test_shop_buy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ def test_01_shop_buy(self):
portal_user.partner_id.vat = "BE1234567"
current_website = self.env["website"].get_current_website()
current_website.account_on_checkout = "disabled"
self.env.ref("website_sale_suggest_create_account.cart").active = True
self.env.ref(
"website_sale_suggest_create_account.short_cart_summary"
"website_sale_suggest_create_account.navigation_buttons"
).active = True
if self.env["ir.module.module"]._get("payment_custom").state != "installed":
self.skipTest("Transfer provider is not installed")
Expand Down
104 changes: 31 additions & 73 deletions website_sale_suggest_create_account/views/website_sale.xml
Original file line number Diff line number Diff line change
@@ -1,105 +1,63 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template
id="cart"
inherit_id="website_sale.cart"
id="navigation_buttons"
inherit_id="website_sale.navigation_buttons"
customize_show="True"
priority="18"
>
<xpath expr="//div[@id='wrap']" position="before">
<t t-set="user_authenticated" t-value="user_id != website.user_id" />
<t
<xpath expr="//a[@name='website_sale_main_button']/../.." position="before">
<t t-set="user_authenticated" t-value="user_id != website.user_id" />
<t
t-set="signup_allowed"
t-value="user_id._get_signup_invitation_scope() == 'b2c'"
/>
<t
<t
t-set="can_checkout"
t-value="website_sale_order and website_sale_order.website_order_line"
t-value="website_sale_order and bool(website_sale_order.website_order_line)"
/>
<t
<t
t-set="suggest_create_account"
t-value="not user_authenticated and signup_allowed and can_checkout"
/>
<t
<t
t-set="suggest_login"
t-value="not user_authenticated and not signup_allowed and can_checkout"
/>
</xpath>
<xpath expr="//a[@t-attf-href='{{redirect_url}}']/.." position="attributes">
<attribute name="class" />
</xpath>
<!-- Show normal "Checkout" button if user is logged in or external login
is disabled -->
<xpath expr="//a[@t-attf-href='{{redirect_url}}']" position="attributes">
<t
t-set="redirect_to_sign_in"
t-value="website.account_on_checkout == 'mandatory' and website.is_public_user()"
/>
</xpath>
<xpath expr="//a[@name='website_sale_main_button']" position="attributes">
<attribute name="class" />
<attribute
name="t-attf-class"
>#{'btn btn-primary' if user_authenticated or redirect_to_sign_in else 'btn btn-light'}</attribute>
>#{'btn btn-primary' if user_authenticated or redirect_to_sign_in else 'btn btn-secondary'}</attribute>
</xpath>
<!-- Show choice in other cases -->
<xpath expr="//a[@t-attf-href='{{redirect_url}}']" position="before">

<xpath expr="//a[@name='website_sale_main_button']/../.." position="after">
<t t-if="xmlid != 'website_sale.payment' ">
<a
t-if="suggest_login and not redirect_to_sign_in"
role="button"
class="btn btn-primary"
href="/web/login?redirect=/shop/checkout?express=1"
>
<span>Sign In and Checkout</span>
t-if="suggest_login and not redirect_to_sign_in"
role="button"
class="btn btn-primary mt-2"
href="/web/login?redirect=/shop/checkout?express=1"
>
<span>Sign in and Checkout</span>
<span class="fa fa-sign-in" />
</a>
<t t-if="suggest_create_account and not redirect_to_sign_in">
<a class="btn btn-primary" role="button" href="/web/login">
<a
class="btn btn-primary mt-2"
role="button"
href="/web/login?redirect=/shop/checkout"
>
<span>Sign In/Up and Checkout</span>
<span class="fa fa-sign-in" />
</a>
</t>
</xpath>
<xpath expr="//a/t[@t-if='redirect_to_sign_in']/span[1]" position="attributes">
<attribute name="class">d-none</attribute>
</xpath>
<xpath expr="//a/t[@t-if='redirect_to_sign_in']/span[1]" position="after">
<span>Sign In/Up</span>
</xpath>
</template>
<!-- Cart summary -->
<template
id="short_cart_summary"
inherit_id="website_sale.short_cart_summary"
customize_show="True"
priority="18"
>
<xpath expr="//a[@t-attf-href='{{redirect_url}}']" position="attributes">
<attribute name="class" />
<attribute
name="t-attf-class"
>#{'btn btn-secondary float-end d-none d-xl-inline-block' if user_authenticated or redirect_to_sign_in else 'btn btn-light float-end d-none d-xl-inline-block'}</attribute>
</xpath>
<xpath expr="//a[@t-attf-href='{{redirect_url}}']" position="after">
<a
t-if="suggest_login and not redirect_to_sign_in"
role="button"
class="btn btn-secondary float-end d-none d-xl-inline-block"
href="/web/login?redirect=/shop/checkout?express=1"
>
<span>Sign in and Checkout</span>
<span class="fa fa-sign-in" />
</a>
<t t-if="suggest_create_account and not redirect_to_sign_in">
<a
class="btn btn-secondary float-end d-none d-xl-inline-block"
role="button"
href="/web/login"
>
<span>Sign In/Up and Checkout</span>
<span class="fa fa-sign-in" />
</a>
</t>
</xpath>
<xpath expr="//t[@t-if='redirect_to_sign_in']/span[1]" position="attributes">
<attribute name="class">d-none</attribute>
</xpath>
<xpath expr="//t[@t-if='redirect_to_sign_in']/span[1]" position="after">
<span>Sign In/Up</span>
</t>
</xpath>
</template>
</odoo>

0 comments on commit 5fb276a

Please sign in to comment.