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_assortment: Migration to 18.0 #998

Open
wants to merge 19 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d452b56
[ADD] website_sale_product_assortment: New module to use product asso…
CarlosRoca13 Nov 29, 2021
ad7ecc8
[FIX] website_sale_product_assortment: 'set' object does not support …
carlosdauden Dec 28, 2021
390f0fc
[FIX] website_sale_product_assortment: Error when no variant_ids in t…
CarlosRoca13 Jan 20, 2022
1ccd9a8
[ADD] icon.png
OCA-git-bot Jun 28, 2022
582ffc8
[IMP] website_sale_product_assortment: black, isort, prettier
AshishHirapara Jul 1, 2022
1f5b32b
[MIG] website_sale_product_assortment: Migration to 14.0
AshishHirapara Jul 1, 2022
0866f34
[UPD] README.rst
OCA-git-bot Jul 4, 2022
f33049b
Added translation using Weblate (Italian)
francesco-ooops Jul 5, 2022
2ff5236
Translated using Weblate (Italian)
francesco-ooops Jul 5, 2022
e6b234c
[MIG] website_sale_product_assortment: Migration to 15.0
stefan-tecnativa Feb 7, 2023
e0eded0
Update translation files
weblate Feb 9, 2023
2ceb375
Translated using Weblate (Italian)
mymage Jun 13, 2023
275b76b
Translated using Weblate (Spanish)
Ivorra78 Jul 5, 2023
02448c7
[MIG] website_sale_product_assortment: Migration to version 16.0
pilarvargas-tecnativa Nov 10, 2023
1d08867
[UPD] Update website_sale_product_assortment.pot
Nov 21, 2023
e73b8d9
[IMP] website_sale_product_assortment: bullet list
SirAionTech Aug 19, 2024
8d37d4c
[BOT] post-merge updates
OCA-git-bot Aug 19, 2024
5f30180
[IMP] website_sale_product_assortment: pre-commit auto fixes
PieterPaulussen Dec 18, 2024
06ae828
[MIG] website_sale_product_assortment: Migration to 18.0
PieterPaulussen Dec 18, 2024
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
115 changes: 115 additions & 0 deletions website_sale_product_assortment/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
============================
eCommerce product assortment
============================

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

.. |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/18.0/website_sale_product_assortment
: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-18-0/e-commerce-18-0-website_sale_product_assortment
: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=18.0
:alt: Try me on Runboat

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

This module allows to set e-commerce restrictions on product
assortments.

**Table of contents**

.. contents::
:local:

Configuration
=============

To see this module working, you have to define a product assortment and
select an option on the website availability field.

- **Don't apply restriction**: This option will not set any kind of
restriction on product items.
- **Avoid to show non available products**: This option will hide on the
e-commerce, the products that are not added to the products domain. If
a product template has at least one allowed variant to show, the
product will appear on the product items view but only that variants
will be able to be bought.
- **Avoid selling not available products**: This option will restrict to
buy the products that are added to the assortment on the e-commerce.
To inform the clients, two more fields were added: "Message when
unavailable" and "Assortment information". The first one will add a
short description to the product item and the other one will set a
detailed description on the product sheet. This second one is editable
from the website editor.

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_assortment%0Aversion:%2018.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
-------

* Tecnativa

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

- `Tecnativa <https://www.tecnativa.com>`__:

- Carlos Roca
- Pedro M. Baeza
- Stefan Ungureanu
- Pilar Vargas

- `Ooops <https://www.ooops404.com>`__:

- Ashish Hirpara (https://ashish-hirpara.com)

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-CarlosRoca13| image:: https://github.com/CarlosRoca13.png?size=40px
:target: https://github.com/CarlosRoca13
:alt: CarlosRoca13

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

|maintainer-CarlosRoca13|

This module is part of the `OCA/e-commerce <https://github.com/OCA/e-commerce/tree/18.0/website_sale_product_assortment>`_ 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_assortment/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import controllers
from . import models
28 changes: 28 additions & 0 deletions website_sale_product_assortment/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2021 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "eCommerce product assortment",
"summary": "Use product assortments to display products available on e-commerce.",
"version": "18.0.1.1.0",
"development_status": "Beta",
"license": "AGPL-3",
"category": "Website",
"website": "https://github.com/OCA/e-commerce",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["CarlosRoca13"],
"installable": True,
"depends": ["product_assortment", "website_sale"],
"data": ["views/ir_filters_views.xml"],
"assets": {
"web.assets_frontend": [
"website_sale_product_assortment/static/src/xml/*.xml",
"website_sale_product_assortment/static/src/js/variant_mixin.esm.js",
"website_sale_product_assortment/static/src/js/assortment_list_preview.esm.js",
],
"web.assets_tests": [
"website_sale_product_assortment/static/src/js/no_purchase_tour.js",
"website_sale_product_assortment/static/src/js/no_restriction_tour.js",
"website_sale_product_assortment/static/src/js/no_show_tour.js",
],
},
}
2 changes: 2 additions & 0 deletions website_sale_product_assortment/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import variant
from . import website_sale
44 changes: 44 additions & 0 deletions website_sale_product_assortment/controllers/variant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2020 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, http
from odoo.http import request

from odoo.addons.sale.controllers.product_configurator import (
SaleProductConfiguratorController,
)


class WebsiteSaleVariantController(SaleProductConfiguratorController):
@http.route(
["/sale/get_info_assortment_preview"],
type="json",
auth="public",
methods=["POST"],
website=True,
)
def get_info_assortment_preview(self, product_template_ids, **kw):
"""Special route to use website logic in get_combination_info override.
This route is called in JS by appending _website to the base route.
"""
res = []
templates = request.env["product.template"].sudo().browse(product_template_ids)
not_allowed_product_dict = templates.get_product_assortment_restriction_info(
templates.mapped("product_variant_ids.id")
)
for template in templates:
variant_ids = set(template.product_variant_ids.ids)
if (
variant_ids
and variant_ids & set(not_allowed_product_dict.keys()) == variant_ids
):
res.append(
{
"id": template.id,
"message_unavailable": not_allowed_product_dict[
variant_ids.pop()
][0].message_unavailable
or _("Not available"),
}
)
return res
78 changes: 78 additions & 0 deletions website_sale_product_assortment/controllers/website_sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2021 Tecnativa - Carlos Roca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from werkzeug.exceptions import NotFound

from odoo.http import request, route

from odoo.addons.website_sale.controllers.main import WebsiteSale


class WebsiteSale(WebsiteSale):
def _get_products_allowed(self):
partner = request.env.user.partner_id
website_id = request.website.id
assortments = (
request.env["ir.filters"]
.sudo()
.search(
[
("is_assortment", "=", True),
("website_availability", "=", "no_show"),
"|",
("website_ids", "=", False),
("website_ids", "=", website_id),
]
)
)
assortment_restriction = False
allowed_product_ids = set()
for assortment in assortments:
if (
# Set active_test to False to allow filtering by partners
# that are not active, (for example Public User)
partner & assortment.with_context(active_test=False).all_partner_ids
):
assortment_restriction = True
allowed_product_ids = allowed_product_ids.union(
set(assortment.all_product_ids.ids)
)
return allowed_product_ids, assortment_restriction

@route()
def product(self, product, category="", search="", **kwargs):
"""Overriding product method to avoid accessing to product sheet when the
product assortments prevent to show them.
"""
allowed_product_ids, assortment_restriction = self._get_products_allowed()
if assortment_restriction:
if len(set(product.product_variant_ids.ids) & allowed_product_ids) == 0:
raise NotFound()
return super().product(product, category=category, search=search, **kwargs)

def _get_search_options(
self,
category=None,
attrib_values=None,
pricelist=None,
min_price=0.0,
max_price=0.0,
conversion_rate=1,
**post,
):
"""Overriding _get_search_options method to avoid show product templates that
has all their variants not allowed to be shown."""
res = super()._get_search_options(
category=category,
attrib_values=attrib_values,
pricelist=pricelist,
min_price=min_price,
max_price=max_price,
conversion_rate=conversion_rate,
**post,
)
allowed_product_ids, assortment_restriction = self._get_products_allowed()
if assortment_restriction:
res["allowed_product_domain"] = [
("product_variant_ids", "in", list(allowed_product_ids))
]
return res
Loading
Loading