Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions website_sale_product_multi_website/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==================================
Website Sale Product Multi Website
==================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0f39a547d2e1ceb92b5aa6b8751b67a1e263224a712a6519667c94d370f1a8f1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github
:target: https://github.com/OCA/e-commerce/tree/17.0/website_sale_product_multi_website
:alt: OCA/e-commerce
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/e-commerce-17-0/e-commerce-17-0-website_sale_product_multi_website
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends that behavior by allowing products to be linked to
multiple websites through a new ``website_ids`` field. It also adapts
the website publication and access logic so products are only available
on the selected websites.

This is useful in multi-website environments where the same catalog item
must be shared across some websites, but not all of them.

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

Standard Odoo only allows linking a product to one website through the
``website_id`` field. As a result, a product can be restricted to a
single website or made globally available, but it cannot be assigned to
several specific websites.

Usage
=====

1. Go to **Website fields** on the product form.
2. Select the websites where the product should be available.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/e-commerce/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/e-commerce/issues/new?body=module:%20website_sale_product_multi_website%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Adhoc S.A.

Contributors
------------

- Pablo Montenegro
- Katherine Zaoral
- Juan Jose Scarafia
- lav-adhoc
- Manuela Cepeda
- Tecnativa (<https://www.tecnativa.com>):

- Pilar Vargas

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/17.0/website_sale_product_multi_website>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions website_sale_product_multi_website/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "Website Sale Product Multi Website",
"summary": "Show products in many websites",
"version": "17.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"],
"post_init_hook": "post_init_hook",
"website": "https://github.com/OCA/e-commerce",
}
16 changes: 16 additions & 0 deletions website_sale_product_multi_website/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).


def post_init_hook(env):
env.cr.execute(
"""
INSERT INTO product_template_website_rel (
product_template_id,
website_id
)
SELECT id, website_id
FROM product_template
WHERE website_id IS NOT NULL
ON CONFLICT DO NOTHING
"""
)
2 changes: 2 additions & 0 deletions website_sale_product_multi_website/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_template
from . import website
62 changes: 62 additions & 0 deletions website_sale_product_multi_website/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


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

website_ids = fields.Many2many(
"website",
"product_template_website_rel",
"product_template_id",
"website_id",
string="Websites",
help="Restrict the product to the selected websites. Leave empty to "
"make it available on all websites.",
)
website_id = fields.Many2one(
"website",
string="Website",
compute="_compute_website_id",
inverse="_inverse_website_id",
store=True,
)

@api.depends("website_ids")
def _compute_website_id(self):
for record in self:
record.website_id = record.website_ids[:1]

def _inverse_website_id(self):
for record in self:
record.website_ids = record.website_id

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 self.env.context.get("website_id")
for record in self:
website_ids = record.sudo().website_ids.ids
if website_ids and website_id not in website_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.env.context.get("website_id")
for record in self:
website_ids = record.sudo().website_ids
record.website_published = record.is_published and (
not current_website_id
or not website_ids
or current_website_id in website_ids.ids
)

def _search_website_published(self, operator, value):
# Search with the multi_website_domain context.
Comment thread
pilarvargas-tecnativa marked this conversation as resolved.
return super(
ProductTemplate, self.with_context(multi_website_domain=True)
)._search_website_published(operator, value)
25 changes: 25 additions & 0 deletions website_sale_product_multi_website/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import api, models


class Website(models.Model):
_inherit = "website"

@api.model
def website_domain(self, website_id=False):
Comment thread
pilarvargas-tecnativa marked this conversation as resolved.
# Keep the standard behavior by default, but allow specific flows to switch
# the website restriction from website_id to website_ids through context.
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):
# Reuse the standard published search while enabling the multi-website
# variant of website_domain() used in website sale flows.
return super(
Website, self.with_context(multi_website_domain=True)
).sale_product_domain()
3 changes: 3 additions & 0 deletions website_sale_product_multi_website/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions website_sale_product_multi_website/readme/CONTEXT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Standard Odoo only allows linking a product to one website through the
`website_id` field. As a result, a product can be restricted to a single
website or made globally available, but it cannot be assigned to several
specific websites.
7 changes: 7 additions & 0 deletions website_sale_product_multi_website/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Pablo Montenegro
- Katherine Zaoral
- Juan Jose Scarafia
- lav-adhoc
- Manuela Cepeda
- Tecnativa (\<<https://www.tecnativa.com>\>):
Comment thread
pilarvargas-tecnativa marked this conversation as resolved.
- Pilar Vargas
7 changes: 7 additions & 0 deletions website_sale_product_multi_website/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This module extends that behavior by allowing products to be linked to
multiple websites through a new `website_ids` field. It also adapts the
website publication and access logic so products are only available on
the selected websites.

This is useful in multi-website environments where the same catalog item
must be shared across some websites, but not all of them.
2 changes: 2 additions & 0 deletions website_sale_product_multi_website/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1. Go to **Website fields** on the product form.
2. Select the websites where the product should be available.
Loading
Loading