Skip to content

Commit

Permalink
Merge commit 'refs/pull/579/head' of https://github.com/oca/e-commerce
Browse files Browse the repository at this point in the history
…into 13.0-2505
  • Loading branch information
docker-odoo committed May 25, 2023
2 parents 44e2c84 + 6a30b78 commit f32205a
Show file tree
Hide file tree
Showing 13 changed files with 549 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/website_sale_product_multi_website/setup.py
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Empty file.
2 changes: 2 additions & 0 deletions website_sale_product_multi_website/__init__.py
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
14 changes: 14 additions & 0 deletions website_sale_product_multi_website/__manifest__.py
@@ -0,0 +1,14 @@
{
"name": "Multi-website product",
"summary": "Show products in many web-sites",
"version": "13.0.1.0.0",
"category": "Website",
"author": "Odoo Community Association (OCA), Adhoc S.A.",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["website_sale"],
"data": ["views/product_template_views.xml"],
"demo": [],
"post_init_hook": "post_init_hook",
}
7 changes: 7 additions & 0 deletions website_sale_product_multi_website/hooks.py
@@ -0,0 +1,7 @@
from odoo import SUPERUSER_ID, api


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
for rec in env["product.template"].with_context(active_test=False).search([]):
rec.website_ids += rec.website_id
2 changes: 2 additions & 0 deletions website_sale_product_multi_website/models/__init__.py
@@ -0,0 +1,2 @@
from . import product_template
from . import website
35 changes: 35 additions & 0 deletions website_sale_product_multi_website/models/product_template.py
@@ -0,0 +1,35 @@
from odoo import api, fields, models
from odoo.http import request
import logging

_logger = logging.getLogger(__name__)


class ProductTemplate(models.Model):
_inherit = "product.template"

website_ids = fields.Many2many("website", string="Websites")

def can_access_from_current_website(self, website_id=False):
""" We overwrite this method completely in order to use the website_ids logic instead of website_id """
website_id = website_id or request.website.id
for rec in self.filtered(lambda x: x.website_ids):
if website_id not in rec.website_ids.ids:
return False
return True

@api.depends('is_published', 'website_ids')
@api.depends_context('website_id')
def _compute_website_published(self):
""" We overwrite this method completely in order to use the website_ids logic instead of website_id """
current_website_id = self._context.get('website_id')
for record in self:
if current_website_id:
record.website_published = record.is_published and (
not record.website_ids or current_website_id in record.website_ids.ids)
else:
record.website_published = record.is_published

def _search_website_published(self, operator, value):
""" We overwrite this method completely in order to use the website_ids logic instead of website_id """
return super(ProductTemplate, self.with_context(multi_website_domain=True))._search_website_published(operator, value)
16 changes: 16 additions & 0 deletions website_sale_product_multi_website/models/website.py
@@ -0,0 +1,16 @@
from odoo import api, models


class Website(models.Model):

_inherit = "website"

@api.model
def website_domain(self, website_id=False):
if self._context.get('multi_website_domain'):
return ['|', ('website_ids', '=', False), ('website_ids', '=', website_id or self.id)]
return super().website_domain(website_id=website_id)

def sale_product_domain(self):
""" We add a context in order to change the way that website_domain behavies """
return super(Website, self.with_context(multi_website_domain=True)).sale_product_domain()

0 comments on commit f32205a

Please sign in to comment.