diff options
| author | Hiral Bhavsar <hbh@odoo.com> | 2019-10-11 13:21:54 +0000 |
|---|---|---|
| committer | Hiral Bhavsar <hbh@odoo.com> | 2020-01-27 14:26:00 +0000 |
| commit | 07d4bbb35bbb48112c07276ab8f35d53301d6cf7 (patch) | |
| tree | e6c50d31326ad81b22f81314dc20d1b7ace938f5 | |
| parent | ce02a0ba89a83952ff39041adb60713745957e6b (diff) | |
[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>
| -rw-r--r-- | addons/sale_product_configurator/models/product.py | 3 | ||||
| -rw-r--r-- | addons/sale_product_configurator/views/sale_views.xml | 2 | ||||
| -rw-r--r-- | addons/website_sale/models/product.py | 5 | ||||
| -rw-r--r-- | addons/website_sale/models/sale_order.py | 3 | ||||
| -rw-r--r-- | addons/website_sale/views/product_views.xml | 2 | ||||
| -rw-r--r-- | addons/website_sale_wishlist/models/product_wishlist.py | 2 |
6 files changed, 10 insertions, 7 deletions
diff --git a/addons/sale_product_configurator/models/product.py b/addons/sale_product_configurator/models/product.py index d565de3fc2f..9fea6201d68 100644 --- a/addons/sale_product_configurator/models/product.py +++ b/addons/sale_product_configurator/models/product.py @@ -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): diff --git a/addons/sale_product_configurator/views/sale_views.xml b/addons/sale_product_configurator/views/sale_views.xml index de662593e6f..3e55deb10b3 100644 --- a/addons/sale_product_configurator/views/sale_views.xml +++ b/addons/sale_product_configurator/views/sale_views.xml @@ -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> diff --git a/addons/website_sale/models/product.py b/addons/website_sale/models/product.py index 944ff4b56e9..6103ad064c5 100644 --- a/addons/website_sale/models/product.py +++ b/addons/website_sale/models/product.py @@ -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) diff --git a/addons/website_sale/models/sale_order.py b/addons/website_sale/models/sale_order.py index 72e46666f35..73e52810c61 100644 --- a/addons/website_sale/models/sale_order.py +++ b/addons/website_sale/models/sale_order.py @@ -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)) diff --git a/addons/website_sale/views/product_views.xml b/addons/website_sale/views/product_views.xml index 11fb1395472..30a31aad9f5 100644 --- a/addons/website_sale/views/product_views.xml +++ b/addons/website_sale/views/product_views.xml @@ -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> diff --git a/addons/website_sale_wishlist/models/product_wishlist.py b/addons/website_sale_wishlist/models/product_wishlist.py index 72b2b7ffa55..b7cbe5e884d 100644 --- a/addons/website_sale_wishlist/models/product_wishlist.py +++ b/addons/website_sale_wishlist/models/product_wishlist.py @@ -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) |
