Skip to content

Commit

Permalink
[REF] use variables to make it more readable and compatible
Browse files Browse the repository at this point in the history
Example of module which requires such refactoring:

https://github.com/it-projects-llc/website-addons/tree/10.0/website_sale_checkout_store

[FIX] condition to show normal checkout button was wrong in website_sale_suggest_create_account
I was equal to

(user_authenticated or not signup_allowed and can_checkout)

while it has to be

(user_authenticated or not signup_allowed) and can_checkout
  • Loading branch information
KolushovAlexandr authored and oscarolar committed Dec 21, 2017
1 parent a17bfcf commit 405941d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 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 @@ -4,7 +4,7 @@
{
"name": "Suggest to create user account when buying",
"summary": "Suggest users to create an account when buying in the website",
"version": "10.0.1.0.0",
"version": "10.0.1.1.0",
"category": "Website",
"website": "https://www.tecnativa.com",
"author": "Tecnativa, "
Expand Down
27 changes: 14 additions & 13 deletions website_sale_suggest_create_account/views/website_sale.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@
<odoo>

<template id="cart" inherit_id="website_sale.cart">
<xpath expr="//div[@id='wrap']" position="before">
<t t-set="user_authenticated" t-value="user_id != website.user_id"/>
<t t-set="signup_allowed" t-value="env['ir.config_parameter'].get_param('auth_signup.allow_uninvited') == 'True' "/>
<!-- TODO: optional_products has to be removed since odoo 12.0 at least. See https://github.com/odoo/odoo/pull/21461 -->
<t t-set="can_checkout" t-value="not optional_products
and website_sale_order and
website_sale_order.website_order_line"/>

<t t-set="suggest_create_account" t-value="not user_authenticated and signup_allowed and can_checkout" />
</xpath>

<!-- Show normal "Checkout" button if user is logged in or external login
is disabled -->
<xpath expr="//a[@href='/shop/checkout']" position="attributes">
<attribute name="t-if">(
user_id != website.user_id or
env['ir.config_parameter'].get_param(
'auth_signup.allow_uninvited') != 'True' and
not optional_products and website_sale_order and
website_sale_order.website_order_line
)</attribute>
<attribute name="t-if">(user_authenticated or not signup_allowed) and can_checkout</attribute>
</xpath>

<!-- Show choice in other cases -->
<xpath expr="//a[@href='/shop/checkout']" position="after">
<a t-if="user_id == website.user_id"
<a t-if="not user_authenticated"
class="btn btn-primary pull-right mb32"
href="/web/login?redirect=/shop/checkout">
<span>Log in and checkout</span>
<span class="fa fa-long-arrow-right"/>
</a>
<t t-if="(user_id == website.user_id and
env['ir.config_parameter'].get_param(
'auth_signup.allow_uninvited') == 'True' and
not optional_products and website_sale_order and
website_sale_order.website_order_line)">
<t t-if="suggest_create_account">
<a class="btn btn-primary pull-right mb32"
href="/web/signup?redirect=/shop/checkout">
<span>Sign up and checkout</span>
Expand Down

0 comments on commit 405941d

Please sign in to comment.