[FIX] website_sale: Prevent displaying categories from other websites

Steps:
    - Go to website/configuration/ecommerce categories
    - Change `Chairs` website to `Website`
    - Go to `Website 2`/shop
    - Write `ch` in the search bar

Autocomplete returns `Chairs` even if it's not available in `Website 2`

opw-2884856

closes odoo/odoo#95219

X-original-commit: 2f99929accc4b71156d235019f7b78a2dd4c75e5
Signed-off-by: Achraf <abz@odoo.com>
Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
This commit is contained in:
Achraf (abz)
2022-07-04 15:24:14 +02:00
parent 42eb0f6656
commit 353a837d9a
2 changed files with 5 additions and 3 deletions
@@ -65,7 +65,7 @@ class ProductPublicCategory(models.Model):
mapping['description'] = {'name': 'website_description', 'type': 'text', 'match': True, 'html': True}
return {
'model': 'product.public.category',
'base_domain': [], # categories are not website-specific
'base_domain': [website.website_domain()],
'search_fields': search_fields,
'fetch_fields': fetch_fields,
'mapping': mapping,
@@ -470,7 +470,9 @@ class ProductTemplate(models.Model):
with_category = 'extra_link' in mapping
with_price = 'detail' in mapping
results_data = super()._search_render_results(fetch_fields, mapping, icon, limit)
current_website = self.env['website'].get_current_website()
for product, data in zip(self, results_data):
categ_ids = product.public_categ_ids.filtered(lambda c: not c.website_id or c.website_id == current_website)
if with_price:
combination_info = product._get_combination_info(only_template=True)
data['price'], list_price = self._search_render_results_prices(
@@ -480,10 +482,10 @@ class ProductTemplate(models.Model):
data['list_price'] = list_price
if with_image:
data['image_url'] = '/web/image/product.template/%s/image_128' % data['id']
if with_category and product.public_categ_ids:
if with_category and categ_ids:
data['category'] = self.env['ir.ui.view'].sudo()._render_template(
"website_sale.product_category_extra_link",
{'categories': product.public_categ_ids, 'slug': slug}
{'categories': categ_ids, 'slug': slug}
)
return results_data