[FIX] sale_product_configurator, website_sale(_wishlist): fix multicompany issue

Currently, we are allowing to select the other company's product as
an alternative product or accessory products on the product.

For example,
	website: W1, W2
	company: C1, C2

	W1-> C1
	W2-> C2

	Product: P1
	===========
		company: C1

	Product: P2
	===========
		company: C2
		alternative product: P1

And this will give a traceback because we are going to use another company's
products. And this is obviously a wrong behavior.

That's why put a specific domain on the alternative, accessory and optional
product fields to fix this multi-company issues.

Now product wishlist will be also a company-specific.

task-2070522

closes odoo/odoo#44011

X-original-commit: 800abfc7baa8461f6b7b5ece95fa7700d3cd872a
Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
This commit is contained in:
Hiral Bhavsar
2020-01-27 14:26:00 +00:00
parent ce02a0ba89
commit 07d4bbb35b
6 changed files with 10 additions and 7 deletions
@@ -6,12 +6,13 @@ from odoo import fields, models, api
class ProductTemplate(models.Model):
_inherit = 'product.template'
_check_company_auto = True
optional_product_ids = fields.Many2many(
'product.template', 'product_optional_rel', 'src_id', 'dest_id',
string='Optional Products', help="Optional Products are suggested "
"whenever the customer hits *Add to Cart* (cross-sell strategy, "
"e.g. for computers: warranty, software, etc.).")
"e.g. for computers: warranty, software, etc.).", check_company=True)
@api.depends('attribute_line_ids.value_ids.is_custom', 'attribute_line_ids.attribute_id.create_variant')
def _compute_has_configurable_attributes(self):
@@ -8,7 +8,7 @@
<xpath expr="//group[@name='sale']" position="after">
<group name="options" groups="product.group_product_variant">
<group string="Options">
<field name="optional_product_ids" widget="many2many_tags" options="{'color_field': 'color'}" domain="[('id', '!=', active_id)]" />
<field name="optional_product_ids" widget="many2many_tags" options="{'color_field': 'color'}" domain="[('id', '!=', active_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]" />
</group>
</group>
</xpath>
+3 -2
View File
@@ -169,14 +169,15 @@ class ProductTemplate(models.Model):
_inherit = ["product.template", "website.seo.metadata", 'website.published.multi.mixin', 'rating.mixin']
_name = 'product.template'
_mail_post_access = 'read'
_check_company_auto = True
website_description = fields.Html('Description for the website', sanitize_attributes=False, translate=html_translate)
alternative_product_ids = fields.Many2many(
'product.template', 'product_alternative_rel', 'src_id', 'dest_id',
'product.template', 'product_alternative_rel', 'src_id', 'dest_id', check_company=True,
string='Alternative Products', help='Suggest alternatives to your customer (upsell strategy). '
'Those products show up on the product page.')
accessory_product_ids = fields.Many2many(
'product.product', 'product_accessory_rel', 'src_id', 'dest_id', string='Accessory Products',
'product.product', 'product_accessory_rel', 'src_id', 'dest_id', string='Accessory Products', check_company=True,
help='Accessories show up when the customer reviews the cart before payment (cross-sell strategy).')
website_size_x = fields.Integer('Size X', default=1)
website_size_y = fields.Integer('Size Y', default=1)
+2 -1
View File
@@ -293,7 +293,8 @@ class SaleOrder(models.Model):
accessory_products |= line.product_id.accessory_product_ids.filtered(lambda product:
product.website_published and
product not in products and
product._is_variant_possible(parent_combination=combination)
product._is_variant_possible(parent_combination=combination) and
(product.company_id == line.company_id or not product.company_id)
)
return random.sample(accessory_products, len(accessory_products))
+1 -1
View File
@@ -92,7 +92,7 @@
<field name="website_id" options="{'no_create': True}" groups="website.group_multi_website"/>
<field name="website_sequence" groups="base.group_no_one"/>
<field name="public_categ_ids" widget="many2many_tags" string="Categories"/>
<field name="alternative_product_ids" widget="many2many_tags" domain="[('id', '!=', active_id)]"/>
<field name="alternative_product_ids" widget="many2many_tags" domain="[('id', '!=', active_id), '|', ('company_id', '=', company_id), ('company_id', '=', False)]"/>
<field name="accessory_product_ids" widget="many2many_tags"/>
<field name="website_style_ids" widget="many2many_tags" groups="base.group_no_one"/>
</group>
@@ -31,7 +31,7 @@ class ProductWishlist(models.Model):
if request.website.is_public_user():
wish = self.sudo().search([('id', 'in', request.session.get('wishlist_ids', []))])
else:
wish = self.search([("partner_id", "=", self.env.user.partner_id.id)])
wish = self.search([("partner_id", "=", self.env.user.partner_id.id), ('website_id', '=', request.website.id)])
return wish.filtered(lambda x: x.sudo().product_id.product_tmpl_id.website_published)