forked from OCA/e-commerce
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'refs/pull/579/head' of https://github.com/oca/e-commerce …
…into 13.0-2505
- Loading branch information
Showing
13 changed files
with
549 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
setup/website_sale_product_multi_website/odoo/addons/website_sale_product_multi_website
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../website_sale_product_multi_website |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from .hooks import post_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import product_template | ||
from . import website |
35 changes: 35 additions & 0 deletions
35
website_sale_product_multi_website/models/product_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Oops, something went wrong.