Skip to content

Commit 1b3b785

Browse files
committed
Merge PR #1184 into 18.0
Signed-off-by ivantodorovich
2 parents c585efa + bf1caca commit 1b3b785

4 files changed

Lines changed: 147 additions & 10 deletions

File tree

website_sale_product_reference_displayed/models/website_snippet_filter.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,47 @@
44
class WebsiteSnippetFilter(models.Model):
55
_inherit = "website.snippet.filter"
66

7-
def _get_products_latest_sold(self, website, limit, domain, context):
8-
products = super()._get_products_latest_sold(website, limit, domain, context)
7+
def _get_products_latest_sold(self, website, limit, domain, **kwargs):
8+
products = super()._get_products_latest_sold(website, limit, domain, **kwargs)
99
if products:
1010
return products.with_context(display_default_code=True)
1111
else:
1212
return products
1313

14-
def _get_products_latest_viewed(self, website, limit, domain, context):
15-
products = super()._get_products_latest_viewed(website, limit, domain, context)
14+
def _get_products_latest_viewed(self, website, limit, domain, **kwargs):
15+
products = super()._get_products_latest_viewed(website, limit, domain, **kwargs)
1616
if products:
1717
return products.with_context(display_default_code=True)
1818
else:
1919
return products
2020

21-
def _get_products_recently_sold_with(self, website, limit, domain, context):
21+
def _get_products_recently_sold_with(
22+
self, website, limit, domain, product_template_id, **kwargs
23+
):
2224
products = super()._get_products_recently_sold_with(
23-
website, limit, domain, context
25+
website, limit, domain, product_template_id, **kwargs
2426
)
2527
if products:
2628
return products.with_context(display_default_code=True)
2729
else:
2830
return products
2931

30-
def _get_products_accessories(self, website, limit, domain, context):
31-
products = super()._get_products_accessories(website, limit, domain, context)
32+
def _get_products_accessories(
33+
self, website, limit, domain, product_template_id=None, **kwargs
34+
):
35+
products = super()._get_products_accessories(
36+
website, limit, domain, product_template_id=product_template_id, **kwargs
37+
)
3238
if products:
3339
return products.with_context(display_default_code=True)
3440
else:
3541
return products
3642

37-
def _get_products_alternative_products(self, website, limit, domain, context):
43+
def _get_products_alternative_products(
44+
self, website, limit, domain, product_template_id=None, **kwargs
45+
):
3846
products = super()._get_products_alternative_products(
39-
website, limit, domain, context
47+
website, limit, domain, product_template_id=product_template_id, **kwargs
4048
)
4149
if products:
4250
return products.with_context(display_default_code=True)

website_sale_product_reference_displayed/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
- Anjeel Haria
66
- [Kencove](https://www.kencove.com/):
77
- Mohamed Alkobrosli
8+
- [Versada](https://versada.eu)
9+
- Maciej Wichowski
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_website_snippet_filter
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
2+
3+
from odoo import Command
4+
from odoo.osv import expression
5+
from odoo.tests import tagged
6+
7+
from odoo.addons.sale.tests.test_sale_product_attribute_value_config import (
8+
TestSaleProductAttributeValueCommon,
9+
)
10+
from odoo.addons.website.tools import MockRequest
11+
from odoo.addons.website_sale.tests.common import WebsiteSaleCommon
12+
13+
14+
@tagged("post_install", "-at_install")
15+
class TestWebsiteSnippetFilter(WebsiteSaleCommon, TestSaleProductAttributeValueCommon):
16+
@classmethod
17+
def setUpClass(cls):
18+
super().setUpClass()
19+
cls.SnippetFilter = cls.env["website.snippet.filter"]
20+
cls.computer.write(
21+
{
22+
"company_id": False,
23+
"website_published": True,
24+
}
25+
)
26+
cls.accessory = cls.env["product.template"].create(
27+
{
28+
"name": "Accessory",
29+
"company_id": False,
30+
"website_published": True,
31+
}
32+
)
33+
cls.alternative = cls.env["product.template"].create(
34+
{
35+
"name": "Alternative",
36+
"company_id": False,
37+
"website_published": True,
38+
}
39+
)
40+
cls.computer.write(
41+
{
42+
"accessory_product_ids": [
43+
Command.set(cls.accessory.product_variant_ids.ids)
44+
],
45+
"alternative_product_ids": [Command.set(cls.alternative.ids)],
46+
}
47+
)
48+
49+
cls.sold_order = cls.env["sale.order"].create(
50+
{
51+
"partner_id": cls.partner.id,
52+
"website_id": cls.website.id,
53+
"order_line": [
54+
Command.create({"product_id": cls.computer.product_variant_id.id}),
55+
Command.create({"product_id": cls.accessory.product_variant_id.id}),
56+
],
57+
}
58+
)
59+
cls.sold_order.action_confirm()
60+
61+
def _domain(self):
62+
return expression.AND(
63+
[
64+
[("website_published", "=", True)],
65+
self.website.website_domain(),
66+
[("company_id", "in", [False, self.website.company_id.id])],
67+
]
68+
)
69+
70+
def test_latest_sold_sets_display_default_code(self):
71+
with MockRequest(self.env, website=self.website):
72+
result = self.SnippetFilter._get_products_latest_sold(
73+
website=self.website, limit=16, domain=self._domain()
74+
)
75+
self.assertTrue(result)
76+
self.assertTrue(result.env.context.get("display_default_code"))
77+
78+
def test_latest_viewed_sets_display_default_code(self):
79+
with MockRequest(self.env, website=self.website):
80+
visitor = self.env["website.visitor"]._upsert_visitor(
81+
self.env.user.partner_id.id
82+
)
83+
self.env["website.track"].create(
84+
{
85+
"visitor_id": visitor[0],
86+
"product_id": self.accessory.product_variant_id.id,
87+
}
88+
)
89+
result = self.SnippetFilter._get_products_latest_viewed(
90+
website=self.website, limit=16, domain=self._domain()
91+
)
92+
self.assertTrue(result)
93+
self.assertTrue(result.env.context.get("display_default_code"))
94+
95+
def test_recently_sold_with_sets_display_default_code(self):
96+
with MockRequest(self.env, website=self.website):
97+
result = self.SnippetFilter._get_products_recently_sold_with(
98+
website=self.website,
99+
limit=16,
100+
domain=self._domain(),
101+
product_template_id=self.computer.id,
102+
)
103+
self.assertTrue(result)
104+
self.assertTrue(result.env.context.get("display_default_code"))
105+
106+
def test_accessories_sets_display_default_code(self):
107+
with MockRequest(self.env, website=self.website):
108+
result = self.SnippetFilter._get_products_accessories(
109+
website=self.website,
110+
limit=16,
111+
domain=self._domain(),
112+
product_template_id=self.computer.id,
113+
)
114+
self.assertTrue(result)
115+
self.assertTrue(result.env.context.get("display_default_code"))
116+
117+
def test_alternative_products_sets_display_default_code(self):
118+
with MockRequest(self.env, website=self.website):
119+
result = self.SnippetFilter._get_products_alternative_products(
120+
website=self.website,
121+
limit=16,
122+
domain=self._domain(),
123+
product_template_id=self.computer.id,
124+
)
125+
self.assertTrue(result)
126+
self.assertTrue(result.env.context.get("display_default_code"))

0 commit comments

Comments
 (0)