[IMP] website_sale: don't show product from another website to admin
Before this commit, the alternatives products were not multi-website filtered to the admin. The suggested product were filtered by website thanks to the `website_published` filter. This only concern the admins, as for portal and public user, all of this is done automatically by the ACLs anyway, where we force_domain to `website_published` products, which also filter by website (see the mixin). This will also eases module inheritance as we use `sale_product_domain()`. Fixes #67501 Co-authored-by: Romain Derie <rde@odoo.com> Co-authored-by: Florent de Labarre <florent.mirieu@gmail.com>
This commit is contained in:
co-authored by
Florent de Labarre
parent
b4920bfe55
commit
ce4c692c81
@@ -207,6 +207,14 @@ class ProductTemplate(models.Model):
|
||||
|
||||
product_template_image_ids = fields.One2many('product.image', 'product_tmpl_id', string="Extra Product Media", copy=True)
|
||||
|
||||
def _get_website_accessory_product(self):
|
||||
domain = self.env['website'].sale_product_domain()
|
||||
return self.accessory_product_ids.filtered_domain(domain)
|
||||
|
||||
def _get_website_alternative_product(self):
|
||||
domain = self.env['website'].sale_product_domain()
|
||||
return self.alternative_product_ids.filtered_domain(domain)
|
||||
|
||||
def _has_no_variant_attributes(self):
|
||||
"""Return whether this `product.template` has at least one no_variant
|
||||
attribute.
|
||||
|
||||
@@ -301,7 +301,7 @@ class SaleOrder(models.Model):
|
||||
accessory_products = self.env['product.product']
|
||||
for line in order.website_order_line.filtered(lambda l: l.product_id):
|
||||
combination = line.product_id.product_template_attribute_value_ids + line.product_no_variant_attribute_value_ids
|
||||
accessory_products |= line.product_id.accessory_product_ids.filtered(lambda product:
|
||||
accessory_products |= line.product_id.product_tmpl_id._get_website_accessory_product().filtered(lambda product:
|
||||
product.website_published and
|
||||
product not in products and
|
||||
product._is_variant_possible(parent_combination=combination) and
|
||||
|
||||
@@ -146,7 +146,7 @@ class WebsiteSnippetFilter(models.Model):
|
||||
if current_template.exists():
|
||||
excluded_products = website.sale_get_order().order_line.product_id.ids
|
||||
excluded_products.extend(current_template.product_variant_ids.ids)
|
||||
included_products = current_template.product_variant_ids.accessory_product_ids.filtered('website_published').ids
|
||||
included_products = current_template._get_website_accessory_product().filtered('website_published').ids
|
||||
products_ids = list(set(included_products) - set(excluded_products))
|
||||
if products_ids:
|
||||
domain = expression.AND([
|
||||
|
||||
@@ -682,10 +682,11 @@
|
||||
|
||||
<template id="recommended_products" inherit_id="website_sale.product" customize_show="True" name="Alternative Products">
|
||||
<xpath expr="//div[@id='product_full_description']" position="after">
|
||||
<div class="container mt32" t-if="product.alternative_product_ids">
|
||||
<t t-set="alternative_products" t-value="product._get_website_alternative_product()"/>
|
||||
<div class="container mt32" t-if="alternative_products">
|
||||
<h3>Alternative Products:</h3>
|
||||
<div class="row mt16" style="">
|
||||
<t t-foreach="product.alternative_product_ids" t-as="alt_product">
|
||||
<t t-foreach="alternative_products" t-as="alt_product">
|
||||
<div class="col-lg-2" style="width: 170px; height:130px; float:left; display:inline; margin-right: 10px; overflow:hidden;">
|
||||
<div class="mt16 text-center" style="height: 100%;">
|
||||
<t t-set="combination_info" t-value="alt_product._get_combination_info()"/>
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
-->
|
||||
<t t-set="product_variant" t-value="product_variant or product._create_first_product_variant()"/>
|
||||
<t t-set="id_list" t-value="[product_variant.id] if product_variant else []"/>
|
||||
<t t-foreach="product.alternative_product_ids" t-as="alt_product">
|
||||
<t t-foreach="product._get_website_alternative_product()" t-as="alt_product">
|
||||
<t t-set="alt_product_variant_id" t-value="alt_product._create_first_product_variant().id"/>
|
||||
<t t-if="alt_product_variant_id" t-set="id_list" t-value="id_list + [alt_product_variant_id]"/>
|
||||
</t>
|
||||
|
||||
Reference in New Issue
Block a user