Skip to content

Commit

Permalink
Merge PR OCA#661 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Jul 4, 2022
2 parents f4cf2d3 + 3697f17 commit aa172e8
Show file tree
Hide file tree
Showing 29 changed files with 1,470 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/website_sale_product_assortment/setup.py
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
102 changes: 102 additions & 0 deletions website_sale_product_assortment/README.rst
@@ -0,0 +1,102 @@
============================
eCommerce product assortment
============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/13.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-13-0/e-commerce-13-0-website_sale_product_assortment
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/113/13.0
:alt: Try me on Runbot

|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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/e-commerce/issues/new?body=module:%20website_sale_product_assortment%0Aversion:%2013.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

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/13.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
@@ -0,0 +1,2 @@
from . import controllers
from . import models
16 changes: 16 additions & 0 deletions website_sale_product_assortment/__manifest__.py
@@ -0,0 +1,16 @@
# 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": "14.0.1.0.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": ["templates/assets.xml", "views/ir_filters_views.xml"],
}
2 changes: 2 additions & 0 deletions website_sale_product_assortment/controllers/__init__.py
@@ -0,0 +1,2 @@
from . import variant
from . import website_sale
42 changes: 42 additions & 0 deletions website_sale_product_assortment/controllers/variant.py
@@ -0,0 +1,42 @@
# 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.variant import VariantController


class WebsiteSaleVariantController(VariantController):
@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
68 changes: 68 additions & 0 deletions website_sale_product_assortment/controllers/website_sale.py
@@ -0,0 +1,68 @@
# 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.osv import expression

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_domain(
self, search, category, attrib_values, search_in_description=True
):
"""Overriding _get_search_domain method to avoid show product templates that
has all their variants not allowed to be shown.
"""
res = super()._get_search_domain(
search, category, attrib_values, search_in_description=search_in_description
)
allowed_product_ids, assortment_restriction = self._get_products_allowed()
if assortment_restriction:
return expression.AND(
[res, [("product_variant_ids", "in", list(allowed_product_ids))]]
)
return res
132 changes: 132 additions & 0 deletions website_sale_product_assortment/i18n/es.po
@@ -0,0 +1,132 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * website_sale_product_assortment
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-05-25 06:21+0000\n"
"PO-Revision-Date: 2022-05-25 08:22+0200\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Generator: Poedit 2.3\n"

#. module: website_sale_product_assortment
#: model:ir.model.fields,help:website_sale_product_assortment.field_ir_filters__website_availability
msgid ""
"\n"
" Each point is used to:\n"
"\n"
" \t- Don't apply restriction: Show all products available for sale on "
"website.\n"
"\n"
" \t- Avoid to show non available products: Show only products "
"available for sale\n"
" on website.\n"
"\n"
" \t- Avoid selling not available products: Show all products, but "
"avoid\n"
" purchase on website.\n"
"\n"
" "
msgstr ""
"\n"
" Cada punto se utiliza para:\n"
"\n"
" \t- No aplicar restricción: Mostrar todos los productos disponibles "
"para la venta en el sitio web.\n"
"\n"
" \t- Evitar mostrar los productos no disponibles: Mostrar sólo los "
"productos disponibles para la venta\n"
" en el sitio web.\n"
"\n"
" \t- Evitar la venta de productos no disponibles: Mostrar todos los "
"productos, pero evitar\n"
" la venta en el sitio web.\n"
"\n"
" "

#. module: website_sale_product_assortment
#: model:ir.model.fields,field_description:website_sale_product_assortment.field_ir_filters__all_product_ids
msgid "All Product"
msgstr "Todos los productos"

#. module: website_sale_product_assortment
#: model:ir.model.fields,field_description:website_sale_product_assortment.field_ir_filters__aplly_on_public_user
msgid "Aplly On Public User"
msgstr "Aplicar en usuario público"

#. module: website_sale_product_assortment
#: model:ir.model.fields,field_description:website_sale_product_assortment.field_ir_filters__assortment_information
msgid "Assortment Information"
msgstr "Información de surtido"

#. module: website_sale_product_assortment
#: model:ir.model.fields,field_description:website_sale_product_assortment.field_ir_filters__website_availability
msgid "Availability on Website"
msgstr "Disponibilidad en sitio web"

#. module: website_sale_product_assortment
#: model:ir.model.fields.selection,name:website_sale_product_assortment.selection__ir_filters__website_availability__no_purchase
msgid "Avoid selling not available products"
msgstr "No permitir vender productos no disponibles"

#. module: website_sale_product_assortment
#: model:ir.model.fields.selection,name:website_sale_product_assortment.selection__ir_filters__website_availability__no_show
msgid "Avoid to show non available products"
msgstr "No permitir mostrar productos no disponibles"

#. module: website_sale_product_assortment
#: model:ir.model.fields.selection,name:website_sale_product_assortment.selection__ir_filters__website_availability__no_restriction
msgid "Don't apply restriction"
msgstr "No aplicar restricción"

#. module: website_sale_product_assortment
#: model:ir.model,name:website_sale_product_assortment.model_ir_filters
msgid "Filters"
msgstr "Filtros"

#. module: website_sale_product_assortment
#: model:ir.model.fields,help:website_sale_product_assortment.field_ir_filters__message_unavailable
msgid ""
"Message showed when some product is not available and the option\n"
" 'Avoid selling not available products' is selected.\n"
" "
msgstr ""
"Mensaje mostrado cuando algún producto no está disponible y la opción\n"
" 'Evitar la venta de productos no disponibles' está seleccionada.\n"
" "

#. module: website_sale_product_assortment
#: model:ir.model.fields,field_description:website_sale_product_assortment.field_ir_filters__message_unavailable
msgid "Message when unavailable"
msgstr "Mensaje cuando no está disponible"

#. module: website_sale_product_assortment
#: code:addons/website_sale_product_assortment/controllers/variant.py:0
#, python-format
msgid "Not available"
msgstr "No disponible"

#. module: website_sale_product_assortment
#: model:ir.model,name:website_sale_product_assortment.model_product_template
msgid "Product Template"
msgstr "Plantilla de producto"

#. module: website_sale_product_assortment
#. openerp-web
#: code:addons/website_sale_product_assortment/static/src/xml/website_sale_product_assortment.xml:0
#, python-format
msgid "Warning"
msgstr "Advertencia"

#. module: website_sale_product_assortment
#: model_terms:ir.ui.view,arch_db:website_sale_product_assortment.product_assortment_view_form
msgid "Website Availability"
msgstr "Disponibilidad en sitio web"

0 comments on commit aa172e8

Please sign in to comment.