-
-
Notifications
You must be signed in to change notification settings - Fork 549
[17.0][MIG] website_sale_product_multi_website: Continue migration to 17.0 #1185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pilarvargas-tecnativa
wants to merge
7
commits into
OCA:17.0
Choose a base branch
from
Tecnativa:17.0-mig-website_sale_product_multi_website
base: 17.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5ba14b
[ADD]website_sale_product_multi_website:new module
pablohmontenegro 0555ecc
[IMP] website_sale_product_multi_website
zaoral 1b98e3c
[FIX] website_sale_product_multi_website
jjscarafia c6bb9a9
[MIG] website_sale_product_multi_website: Migration to 16.0
lav-adhoc d859c4d
[IMP] website_sale_product_multi_website: pre-commit execution
cem-adhoc 1f12120
[MIG] website_sale_product_multi_website: Migration to 17.0
cem-adhoc c6d7f74
[MIG] website_sale_product_multi_website: Continue migration to 17.0
pilarvargas-tecnativa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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. |
This file contains hidden or 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 hidden or 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": "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", | ||
| } |
This file contains hidden or 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 @@ | ||
| # 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 | ||
| """ | ||
| ) |
This file contains hidden or 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 |
62 changes: 62 additions & 0 deletions
62
website_sale_product_multi_website/models/product_template.py
This file contains hidden or 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,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. | ||
| return super( | ||
| ProductTemplate, self.with_context(multi_website_domain=True) | ||
| )._search_website_published(operator, value) | ||
This file contains hidden or 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,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): | ||
|
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() | ||
This file contains hidden or 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,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or 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,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. |
This file contains hidden or 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 @@ | ||
| - Pablo Montenegro | ||
| - Katherine Zaoral | ||
| - Juan Jose Scarafia | ||
| - lav-adhoc | ||
| - Manuela Cepeda | ||
| - Tecnativa (\<<https://www.tecnativa.com>\>): | ||
|
pilarvargas-tecnativa marked this conversation as resolved.
|
||
| - Pilar Vargas | ||
This file contains hidden or 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 @@ | ||
| 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. |
This file contains hidden or 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 @@ | ||
| 1. Go to **Website fields** on the product form. | ||
| 2. Select the websites where the product should be available. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.