Skip to content

Commit c557821

Browse files
sergio-teruelCarlosRoca13
authored andcommitted
[IMP] website_sale_tax_toggle: black, isort
1 parent 23ab3a6 commit c557821

File tree

10 files changed

+120
-99
lines changed

10 files changed

+120
-99
lines changed
Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,17 @@
11
# Copyright 2020 Tecnativa - Sergio Teruel
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33
{
4-
'name': 'Website Sale Tax Toggle',
5-
'summary': 'Allow display price in Shop with or without taxes',
6-
'version': '12.0.1.1.1',
7-
'development_status': 'Beta',
8-
'category': 'Website',
9-
'website': 'https://github.com/OCA/e-commerce',
10-
'author': 'Tecnativa, Odoo Community Association (OCA)',
11-
'license': 'AGPL-3',
12-
'application': False,
13-
'installable': True,
14-
'depends': [
15-
'website_sale',
16-
],
17-
'data': [
18-
'views/assets.xml',
19-
'views/templates.xml',
20-
],
4+
"name": "Website Sale Tax Toggle",
5+
"summary": "Allow display price in Shop with or without taxes",
6+
"version": "12.0.1.1.1",
7+
"development_status": "Beta",
8+
"category": "Website",
9+
"website": "https://github.com/OCA/e-commerce",
10+
"author": "Tecnativa, Odoo Community Association (OCA)",
11+
"license": "AGPL-3",
12+
"application": False,
13+
"installable": True,
14+
"depends": ["website_sale",],
15+
"data": ["views/assets.xml", "views/templates.xml",],
2116
"demo": ["demo/assets.xml"],
2217
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Copyright 2020 Tecnativa - Sergio Teruel
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo.addons.website_sale.controllers.main import WebsiteSale
54
from odoo import http
65
from odoo.http import request
76

7+
from odoo.addons.website_sale.controllers.main import WebsiteSale
8+
89

910
class WebsiteSaleTaxToggle(WebsiteSale):
10-
11-
@http.route(
12-
['/website/tax_toggle'], type='json', auth="public", website=True)
11+
@http.route(["/website/tax_toggle"], type="json", auth="public", website=True)
1312
def tax_toggle(self):
1413
# Create a session variable
15-
request.session['tax_toggle_taxed'] = not request.session.get(
16-
'tax_toggle_taxed', False)
17-
return request.session['tax_toggle_taxed']
14+
request.session["tax_toggle_taxed"] = not request.session.get(
15+
"tax_toggle_taxed", False
16+
)
17+
return request.session["tax_toggle_taxed"]
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<!-- Copyright 2020 Tecnativa - Jairo Llopis
33
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
44
<data>
5-
65
<template id="assets_frontend_demo" inherit_id="website.assets_frontend">
76
<xpath expr=".">
8-
<script type="text/javascript"
9-
src="/website_sale_tax_toggle/static/src/js/website_sale_tax_toggle_tour.js"/>
7+
<script
8+
type="text/javascript"
9+
src="/website_sale_tax_toggle/static/src/js/website_sale_tax_toggle_tour.js"
10+
/>
1011
</xpath>
1112
</template>
12-
1313
</data>

website_sale_tax_toggle/models/res_users.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,25 @@ class ResUsers(models.Model):
1010

1111
@api.model
1212
def has_group(self, group_ext_id):
13-
tax_included = 'account.group_show_line_subtotals_tax_included'
14-
tax_excluded = 'account.group_show_line_subtotals_tax_excluded'
15-
if (self.env.context.get('website_id') and
16-
group_ext_id in [tax_included, tax_excluded] and
17-
not self.env.context.get('skip_tax_toggle_check')):
13+
tax_included = "account.group_show_line_subtotals_tax_included"
14+
tax_excluded = "account.group_show_line_subtotals_tax_excluded"
15+
if (
16+
self.env.context.get("website_id")
17+
and group_ext_id in [tax_included, tax_excluded]
18+
and not self.env.context.get("skip_tax_toggle_check")
19+
):
1820
taxed = request.session.get(
19-
'tax_toggle_taxed',
20-
self.env.user.with_context(
21-
skip_tax_toggle_check=True
22-
).has_group(tax_included)
21+
"tax_toggle_taxed",
22+
self.env.user.with_context(skip_tax_toggle_check=True).has_group(
23+
tax_included
24+
),
2325
)
2426
return group_ext_id != (tax_excluded if taxed else tax_included)
2527
return super().has_group(group_ext_id)
2628

2729
# HACK: To clear cache called from res.users write method
2830
@api.model
29-
@ormcache('self._uid', 'group_ext_id')
31+
@ormcache("self._uid", "group_ext_id")
3032
def _has_group(self, group_ext_id):
3133
return super()._has_group(group_ext_id)
3234

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
/* Copyright 2020 Sergio Teruel
22
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
33

4-
odoo.define("website_sale_tax_toggle.tax_toggle_button", function (require) {
4+
odoo.define("website_sale_tax_toggle.tax_toggle_button", function(require) {
55
"use strict";
66

77
var sAnimation = require("website.content.snippets.animation");
88

99
sAnimation.registry.tax_toggle_button = sAnimation.Class.extend({
1010
selector: ".js_tax_toggle_management",
1111
events: {
12-
'click .js_tax_toggle_btn': '_onPublishBtnClick',
12+
"click .js_tax_toggle_btn": "_onPublishBtnClick",
1313
},
14-
_onPublishBtnClick: function (ev) {
14+
_onPublishBtnClick: function(ev) {
1515
ev.preventDefault();
1616
var self = this;
1717
var $data = $(ev.currentTarget).parents(".js_tax_toggle_management:first");
1818
this._rpc({
19-
route: $data.data('controller'),
20-
})
21-
.done(function (result) {
22-
$data.find('input').prop("checked", result);
19+
route: $data.data("controller"),
20+
}).done(function(result) {
21+
$data.find("input").prop("checked", result);
2322
window.location.reload();
2423
});
2524
},
2625
});
27-
2826
});

website_sale_tax_toggle/static/src/js/website_sale_tax_toggle_tour.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* Copyright 2020 Sergio Teruel
22
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */
33

4-
odoo.define("website_sale_tax_toggle.tour", function (require) {
4+
odoo.define("website_sale_tax_toggle.tour", function(require) {
55
"use strict";
66

77
var tour = require("web_tour.tour");
@@ -13,24 +13,29 @@ odoo.define("website_sale_tax_toggle.tour", function (require) {
1313
var steps = [
1414
{
1515
content: "Toggle tax button click from list page",
16-
trigger: '.js_tax_toggle_btn',
17-
extra_trigger: ".oe_product_cart:contains('Product test tax toggle') b .oe_currency_value:containsExact('750.00')",
16+
trigger: ".js_tax_toggle_btn",
17+
extra_trigger:
18+
".oe_product_cart:contains('Product test tax toggle') b .oe_currency_value:containsExact('750.00')",
1819
},
1920
{
2021
content: "Enter the product page",
21-
trigger: ".oe_product_cart:has(b .oe_currency_value:containsExact('862.50')) a:contains('Product test tax toggle')",
22+
trigger:
23+
".oe_product_cart:has(b .oe_currency_value:containsExact('862.50')) a:contains('Product test tax toggle')",
2224
},
2325
{
2426
content: "Toggle tax button click from product page",
25-
trigger: '.js_tax_toggle_btn',
26-
extra_trigger: "#product_details .oe_price .oe_currency_value:containsExact('862.50')",
27+
trigger: ".js_tax_toggle_btn",
28+
extra_trigger:
29+
"#product_details .oe_price .oe_currency_value:containsExact('862.50')",
2730
},
2831
{
2932
content: "Check the product price is back to what it should",
30-
trigger: "#product_details .oe_price .oe_currency_value:containsExact('750.00')",
33+
trigger:
34+
"#product_details .oe_price .oe_currency_value:containsExact('750.00')",
3135
},
3236
];
33-
tour.register("website_sale_tax_toggle",
37+
tour.register(
38+
"website_sale_tax_toggle",
3439
{
3540
url: "/shop",
3641
test: true,

website_sale_tax_toggle/static/src/scss/website_sale_tax_toggle.scss

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
+ span {
1414
background-color: $o-we-switch-inactive-color;
15-
box-shadow: inset 0 0 0px 1px darken($o-we-switch-inactive-color,10%);
15+
box-shadow: inset 0 0 0px 1px darken($o-we-switch-inactive-color, 10%);
1616
border-radius: 100rem;
1717
height: $o-we-switch-size;
1818
width: $o-we-switch-size * 1.81;
@@ -31,7 +31,8 @@
3131
margin-left: 0.1ex;
3232
border-radius: 100rem;
3333
transition: all 0.3s $o-we-md-ease;
34-
box-shadow: 0 1px 1px darken($o-we-switch-inactive-color,35%), inset 0 0 0 1px lighten($o-we-switch-inactive-color,10%);
34+
box-shadow: 0 1px 1px darken($o-we-switch-inactive-color, 35%),
35+
inset 0 0 0 1px lighten($o-we-switch-inactive-color, 10%);
3536
}
3637
}
3738

@@ -40,7 +41,7 @@
4041
background: $o-we-color-success;
4142

4243
&:after {
43-
margin-left: ($o-we-switch-size*1.8 - $o-we-switch-size) + 0.1;
44+
margin-left: ($o-we-switch-size * 1.8 - $o-we-switch-size) + 0.1;
4445
}
4546
}
4647
}

website_sale_tax_toggle/tests/test_website_sale_tax_toggle.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,37 @@
44

55

66
class WebsiteSaleTaxesToggleHttpCase(HttpCase):
7-
87
def setUp(self):
98
super().setUp()
109
# Get company for Mitchel Admin user
11-
self.user_admin = self.env.ref('base.user_admin')
10+
self.user_admin = self.env.ref("base.user_admin")
1211
user_company = self.user_admin.company_id
13-
self.tax = self.env['account.tax'].create({
14-
'name': 'Taxes toggle test tax',
15-
'amount_type': 'percent',
16-
'amount': 15,
17-
'type_tax_use': 'sale',
18-
'company_id': user_company.id,
19-
})
20-
self.product_template = self.env['product.template'].create({
21-
'name': 'Product test tax toggle',
22-
'list_price': 750.00,
23-
'taxes_id': [(6, 0, self.tax.ids)],
24-
'website_published': True,
25-
'website_sequence': 9999,
26-
})
27-
pricelist = self.env['product.pricelist'].create({
28-
'name': 'Price list for tests',
29-
'currency_id': user_company.currency_id.id
30-
})
12+
self.tax = self.env["account.tax"].create(
13+
{
14+
"name": "Taxes toggle test tax",
15+
"amount_type": "percent",
16+
"amount": 15,
17+
"type_tax_use": "sale",
18+
"company_id": user_company.id,
19+
}
20+
)
21+
self.product_template = self.env["product.template"].create(
22+
{
23+
"name": "Product test tax toggle",
24+
"list_price": 750.00,
25+
"taxes_id": [(6, 0, self.tax.ids)],
26+
"website_published": True,
27+
"website_sequence": 9999,
28+
}
29+
)
30+
pricelist = self.env["product.pricelist"].create(
31+
{"name": "Price list for tests", "currency_id": user_company.currency_id.id}
32+
)
3133
self.env.user.partner_id.property_product_pricelist = pricelist
3234
# To avoid currency converter
33-
self.env['res.currency.rate'].search([]).write({
34-
'rate': 1,
35-
})
35+
self.env["res.currency.rate"].search([]).write(
36+
{"rate": 1,}
37+
)
3638

3739
def test_ui_website(self):
3840
"""Test frontend tour."""
@@ -44,5 +46,5 @@ def test_ui_website(self):
4446
url_path="/shop",
4547
code="%s.run('%s')" % tour,
4648
ready="%s.tours['%s'].ready" % tour,
47-
login="admin"
49+
login="admin",
4850
)
Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
33
<template id="assets_frontend" inherit_id="website.assets_frontend">
44
<xpath expr=".">
5-
<script type="text/javascript"
6-
src="/website_sale_tax_toggle/static/src/js/website_sale_tax_toggle.js"/>
7-
<link type="text/scss" rel="stylesheet"
8-
href="/website_sale_tax_toggle/static/src/scss/website_sale_tax_toggle.scss"/>
5+
<script
6+
type="text/javascript"
7+
src="/website_sale_tax_toggle/static/src/js/website_sale_tax_toggle.js"
8+
/>
9+
<link
10+
type="text/scss"
11+
rel="stylesheet"
12+
href="/website_sale_tax_toggle/static/src/scss/website_sale_tax_toggle.scss"
13+
/>
914
</xpath>
1015
</template>
1116
</odoo>
Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,48 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8" ?>
22
<!-- Copyright 2020 Tecnativa - Sergio Teruel
33
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
44
<odoo>
5-
65
<template id="tax_toggle_template">
7-
<t t-set="taxed" t-value="request.session.get('tax_toggle_taxed', request.env.user.with_context(skip_tax_toggle_check=True).has_group('account.group_show_line_subtotals_tax_included'))"/>
6+
<t
7+
t-set="taxed"
8+
t-value="request.session.get('tax_toggle_taxed', request.env.user.with_context(skip_tax_toggle_check=True).has_group('account.group_show_line_subtotals_tax_included'))"
9+
/>
810
<div class="js_tax_toggle_management" data-controller="/website/tax_toggle">
911
<label class="o_switch o_switch_danger js_tax_toggle_btn">
10-
<input type="checkbox" t-att-checked="taxed"/>
11-
<span/>
12+
<input type="checkbox" t-att-checked="taxed" />
13+
<span />
1214
<span>Show prices with taxes included</span>
1315
</label>
1416
</div>
1517
</template>
16-
17-
<template id="products" inherit_id="website_sale.products" active="True" customize_show="True" name="Taxes toggle" priority="999">
18+
<template
19+
id="products"
20+
inherit_id="website_sale.products"
21+
active="True"
22+
customize_show="True"
23+
name="Taxes toggle"
24+
priority="999"
25+
>
1826
<xpath expr="//div[hasclass('products_pager')]" position="after">
1927
<div class="row mt16 mb0">
2028
<div class="col">
2129
<div class="pull-right">
22-
<t t-call="website_sale_tax_toggle.tax_toggle_template"/>
30+
<t t-call="website_sale_tax_toggle.tax_toggle_template" />
2331
</div>
2432
</div>
2533
</div>
2634
</xpath>
2735
</template>
28-
29-
<template id="product" inherit_id="website_sale.product" active="True" customize_show="True" name="Taxes toggle" priority="999">
36+
<template
37+
id="product"
38+
inherit_id="website_sale.product"
39+
active="True"
40+
customize_show="True"
41+
name="Taxes toggle"
42+
priority="999"
43+
>
3044
<xpath expr="//t[@t-call='website_sale.product_price']" position="before">
31-
<t t-call="website_sale_tax_toggle.tax_toggle_template"/>
45+
<t t-call="website_sale_tax_toggle.tax_toggle_template" />
3246
</xpath>
3347
</template>
34-
3548
</odoo>

0 commit comments

Comments
 (0)