Skip to content
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

[MIG] website_sale_product_multi_website: Migration to 18.0 #981

Open
wants to merge 10 commits into
base: 18.0
Choose a base branch
from
98 changes: 98 additions & 0 deletions website_sale_product_multi_website/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
==================================
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/licence-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/16.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-16-0/e-commerce-16-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=16.0
:alt: Try me on Runboat

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

By default, Odoo allows to set just one (or all) website for products to be sold on eCommerces, by setting the field product_template.website_ids (a many2one field). This module allows to set more than one value (website) in this field (convert it in a many2many field).

**Table of contents**

.. contents::
:local:

Usage
=====
#. Just install it.

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_website0Aversion:%2016.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
~~~~~~~

* Agile Business Group

Contributors
~~~~~~~~~~~~

* Simone Rubino <[email protected]>


* `Tecnativa <https://www.tecnativa.com>`_:

* João Marques
* Pilar Vargas
* Stefan Ungureanu

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.

.. |maintainer-stefan-tecnativa| image:: https://github.com/stefan-tecnativa.png?size=40px
:target: https://github.com/stefan-tecnativa
:alt: stefan-tecnativa
.. |maintainer-pilarvargas-tecnativa| image:: https://github.com/pilarvargas-tecnativa.png?size=40px
:target: https://github.com/pilarvargas-tecnativa
:alt: pilarvargas-tecnativa

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-stefan-tecnativa| |maintainer-pilarvargas-tecnativa|

This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/16.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
15 changes: 15 additions & 0 deletions website_sale_product_multi_website/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "Multi-website product",
"summary": "Show products in many web-sites",
"version": "18.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",
"website": "https://github.com/OCA/e-commerce",
}
3 changes: 3 additions & 0 deletions website_sale_product_multi_website/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def post_init_hook(env):
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_template
from . import website
43 changes: 43 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,43 @@
import logging

from odoo import api, fields, models
from odoo.http import request

_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

Check warning on line 20 in website_sale_product_multi_website/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

website_sale_product_multi_website/models/product_template.py#L20

Added line #L20 was not covered by tests
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(

Check warning on line 41 in website_sale_product_multi_website/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

website_sale_product_multi_website/models/product_template.py#L41

Added line #L41 was not covered by tests
ProductTemplate, self.with_context(multi_website_domain=True)
)._search_website_published(operator, value)
21 changes: 21 additions & 0 deletions website_sale_product_multi_website/models/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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()
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"
Loading
Loading