|
| 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