Skip to content

Commit

Permalink
[MIG] website_sale_product_multi_website: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lav-adhoc committed Nov 24, 2023
1 parent b6677d3 commit 65b0d03
Show file tree
Hide file tree
Showing 6 changed files with 553 additions and 406 deletions.
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 <simone.rubino@agilebg.com>


* `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.
3 changes: 2 additions & 1 deletion website_sale_product_multi_website/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Multi-website product",
"summary": "Show products in many web-sites",
"version": "13.0.1.0.0",
"version": "16.0.1.0.0",
"category": "Website",
"author": "Odoo Community Association (OCA), Adhoc S.A.",
"license": "AGPL-3",
Expand All @@ -11,4 +11,5 @@
"data": ["views/product_template_views.xml"],
"demo": [],
"post_init_hook": "post_init_hook",
"website": "https://github.com/OCA/e-commerce",
}
26 changes: 17 additions & 9 deletions website_sale_product_multi_website/models/product_template.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

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

_logger = logging.getLogger(__name__)

Expand All @@ -11,25 +12,32 @@ class ProductTemplate(models.Model):
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 """
"""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')
@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')
"""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)
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)
"""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)
14 changes: 10 additions & 4 deletions website_sale_product_multi_website/models/website.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ class Website(models.Model):

@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)]
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()
"""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()
Loading

0 comments on commit 65b0d03

Please sign in to comment.