Skip to content

Commit

Permalink
[MIG] website_sale_hide_empty_category: Migration to v13
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Jun 1, 2020
2 parents 658b1bf + fac2dee commit 65f8929
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 28 deletions.
2 changes: 1 addition & 1 deletion website_sale_hide_empty_category/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"application": False,
"installable": True,
"depends": ["website_sale"],
"data": ["views/website_sale_templates.xml"],
"data": ["views/assets.xml", "views/website_sale_templates.xml"],
}
4 changes: 3 additions & 1 deletion website_sale_hide_empty_category/static/src/js/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ odoo.define("website_sale_hide_empty_category.tour", function(require) {

var steps = [
{
trigger: "asd",
trigger: "#products_grid_before a:contains('Category Test Posted')",
extra_trigger:
"#products_grid_before:not(:has(a:contains('Category Test Not Posted')))",
},
];

Expand Down
1 change: 1 addition & 0 deletions website_sale_hide_empty_category/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_ui
9 changes: 5 additions & 4 deletions website_sale_hide_empty_category/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
class UICase(HttpCase):
def setUp(self):
super().setUp()
category_posted = self.env["product.category"].create(
category_posted = self.env["product.public.category"].create(
{"name": "Category Test Posted"}
)
self.env["product.category"].create({"name": "Category Test Not Posted"})
self.env["product.public.category"].create({"name": "Category Test Not Posted"})
self.env["product.template"].create(
{
"name": "Test Product 1",
"is_published": True,
"website_sequence": 1,
"type": "product",
"categ_id": category_posted.id,
"type": "consu",
"public_categ_ids": [category_posted.id],
}
)
self.env.ref("website_sale.products_categories").active = True

def test_ui_website(self):
"""Test frontend tour."""
Expand Down
11 changes: 11 additions & 0 deletions website_sale_hide_empty_category/views/assets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_frontend" inherit_id="website.assets_frontend">
<xpath expr=".">
<script
type="text/javascript"
src="/website_sale_hide_empty_category/static/src/js/tour.js"
/>
</xpath>
</template>
</odoo>
2 changes: 1 addition & 1 deletion website_sale_stock_list_preview/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Usage
To use this module, you need to:

* Edit some products on the option Availability of e-commerce
* Go to the shop on the website.
* Go to the shop on the website and active Add to Cart view on Customize menu.
* You can see on your products the results of the options that you had choose.

Bug Tracker
Expand Down
4 changes: 2 additions & 2 deletions website_sale_stock_list_preview/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
{
"name": "Website Sale Stock List Preview",
"summary": "Show the stock of products on the product previews",
"version": "13.0.1.0.0",
"version": "13.0.1.0.1",
"category": "Website",
"website": "https://github.com/OCA/e-commerce/",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": ["website_sale_stock"],
"data": ["views/assets.xml"],
"data": ["views/assets.xml", "views/templates.xml"],
}
5 changes: 2 additions & 3 deletions website_sale_stock_list_preview/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def get_combination_info_stock_preview(self, product_template_ids, **kw):
.with_context(warehouse=current_website.warehouse_id.id)
.browse(product_template_ids)
)
for template in templates.filtered(
lambda t: t.is_published and t.inventory_availability != "never"
):
for template in templates.filtered(lambda t: t.is_published):

res.append(
{
Expand All @@ -41,6 +39,7 @@ def get_combination_info_stock_preview(self, product_template_ids, **kw):
"available_threshold": template.available_threshold,
"custom_message": template.custom_message,
"type": template.type,
"uom_name": template.uom_name,
}
)
return res
2 changes: 1 addition & 1 deletion website_sale_stock_list_preview/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
To use this module, you need to:

* Edit some products on the option Availability of e-commerce
* Go to the shop on the website.
* Go to the shop on the website and active Add to Cart view on Customize menu.
* You can see on your products the results of the options that you had choose.
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ <h1><a class="toc-backref" href="#id1">Usage</a></h1>
<p>To use this module, you need to:</p>
<ul class="simple">
<li>Edit some products on the option Availability of e-commerce</li>
<li>Go to the shop on the website.</li>
<li>Go to the shop on the website and active Add to Cart view on Customize menu.</li>
<li>You can see on your products the results of the options that you had choose.</li>
</ul>
</div>
Expand Down
94 changes: 80 additions & 14 deletions website_sale_stock_list_preview/static/src/js/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,116 @@ odoo.define("website_sale_stock_list_preview.tour", function(require) {

var steps = [
{
trigger: "a:contains('Test Product 1')",
extra_trigger: ".text-success:contains('30 available')",
trigger:
".o_wsale_product_information:has(.text-success:contains('30 Units available')) a:contains('Test Product 1')",
},
{
trigger: "a[href='/shop']",
extra_trigger:
"#product_details .text-success:contains('30 Units available')",
},
{
trigger: "a:contains('Test Product 2')",
extra_trigger: ".text-success:contains('In stock')",
trigger:
".o_wsale_product_information:not(:has(.btn-secondary.disabled)) a:contains('Test Product 1')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details a:not(#add_to_cart.disabled)",
},
{
trigger: "a:contains('Test Product 3')",
extra_trigger: ".text-warning:contains('5 available')",
trigger:
".o_wsale_product_information:has(.text-success:contains('In stock')) a:contains('Test Product 2')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details .text-success:contains('In stock')",
},
{
trigger: "a:contains('Test Product 4')",
extra_trigger: ".text-success:contains('test message')",
trigger:
".o_wsale_product_information:not(:has(.btn-secondary.disabled)) a:contains('Test Product 2')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details a:not(#add_to_cart.disabled)",
},
{
trigger: "a:contains('Test Product 5')",
// Extra_trigger: ".text-success:contains('30 available')",
trigger:
".o_wsale_product_information:has(.text-warning:contains('5 Units available')) a:contains('Test Product 3')",
},
{
trigger: "a[href='/shop']",
extra_trigger:
"#product_details .text-warning:contains('5 Units available')",
},
{
trigger: "a:contains('Test Product 6')",
extra_trigger: ".text-danger:contains(' Temporarily out of stock')",
trigger:
".o_wsale_product_information:not(:has(.btn-secondary.disabled)) a:contains('Test Product 3')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details a:not(#add_to_cart.disabled)",
},
{
trigger: "a:contains('Test Product 7')",
extra_trigger: ".text-danger:contains(' Temporarily out of stock')",
trigger:
".o_wsale_product_information:has(.text-success:contains('test message')) a:contains('Test Product 4')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details .text-success:contains('test message')",
},
{
trigger:
".o_wsale_product_information:not(:has(.btn-secondary.disabled)) a:contains('Test Product 4')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details a:not(#add_to_cart.disabled)",
},
{
trigger:
".o_wsale_product_information:has(.product_price:not(:has(.mt16))) a:contains('Test Product 5')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details :not(.mt16)",
},
{
trigger:
".o_wsale_product_information:not(:has(btn-secondary.disabled)) a:contains('Test Product 5')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details a:not(#add_to_cart.disabled)",
},
{
trigger:
".o_wsale_product_information:has(.text-danger:contains(' Temporarily out of stock')) a:contains('Test Product 6')",
},
{
trigger: "a[href='/shop']",
extra_trigger:
"#product_details .text-danger:contains(' Temporarily out of stock')",
},
{
trigger:
".o_wsale_product_information:has(.btn-secondary.disabled) a:contains('Test Product 6')",
},
{
trigger: "a[href='/shop']",
extra_trigger: "#product_details a#add_to_cart.disabled",
},
{
trigger:
".o_wsale_product_information:has(.text-danger:contains(' Temporarily out of stock')) a:contains('Test Product 7')",
},
{
trigger: "a[href='/shop']",
extra_trigger:
"#product_details .text-danger:contains(' Temporarily out of stock')",
},
{
trigger:
".o_wsale_product_information:has(.btn-secondary.disabled) a:contains('Test Product 7')",
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,35 @@ odoo.define("website_sale_stock_list_preview.shop_stock", function(require) {
custom_message: product.custom_message,
product_template: product.id,
product_type: product.type,
uom_name: product.uom_name,
}
)
).get(0)
);
// With this code we active just the products that can be sold on website.
if (
product.virtual_available <= 0 &&
(product.inventory_availability == "always" ||
product.inventory_availability == "threshold")
) {
$(product_dic[product.id])
.find(".fa-spinner")
.addClass("d-none");
$(product_dic[product.id])
.find(".fa-shopping-cart")
.removeClass("d-none");
} else {
$(product_dic[product.id])
.find(".fa-spinner")
.addClass("d-none");
$(product_dic[product.id])
.find(".fa-shopping-cart")
.removeClass("d-none");
$(product_dic[product.id])
.find(".fa-shopping-cart")
.parent()
.removeClass("disabled");
}
}
});
},
Expand Down
1 change: 1 addition & 0 deletions website_sale_stock_list_preview/tests/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def setUp(self):
},
]
)
self.env.ref("website_sale.products_add_to_cart").active = True

def test_ui_website(self):
"""Test frontend tour."""
Expand Down
23 changes: 23 additions & 0 deletions website_sale_stock_list_preview/views/templates.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="products_add_to_cart" inherit_id="website_sale.products_add_to_cart">
<xpath
expr="//a[hasclass('a-submit')]/span[hasclass('fa-shopping-cart')]/.."
position="attributes"
>
<attribute name="class" add="disabled" separator=" " />
</xpath>
<xpath
expr="//a[hasclass('a-submit')]/span[hasclass('fa-shopping-cart')]"
position="attributes"
>
<attribute name="class" add="d-none" separator=" " />
</xpath>
<xpath
expr="//a[hasclass('a-submit')]/span[hasclass('fa-shopping-cart')]"
position="after"
>
<span class="fa fa-spinner fa-spin" />
</xpath>
</template>
</odoo>

0 comments on commit 65f8929

Please sign in to comment.