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

[16.0][MIG] rotordc_optional_product: migration to 16.0 #119

Open
wants to merge 16 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
71 changes: 71 additions & 0 deletions rotordc_optional_product/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
========================
RotorDC Optional Product
========================

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

.. |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-coopiteasy%2Fcie--custom-lightgray.png?logo=github
:target: https://github.com/coopiteasy/cie-custom/tree/16.0/rotordc_optional_product
:alt: coopiteasy/cie-custom

|badge1| |badge2| |badge3|

This module has two main behaviours:

- When selecting optional products in the 'add to cart' modal, the user is
prevented from adding more than one optional product of the same internal
category.
- When checking out, the user is redirected to an informative error page when
they did not select all available optional products for their order. e.g. if a
lamp has optional products with the internal categories 'light bulb' and
'cable', then the user **must** select one optional product of both categories
when ordering a lamp.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/cie-custom/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/coopiteasy/cie-custom/issues/new?body=module:%20rotordc_optional_product%0Aversion:%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
~~~~~~~

* Coop IT Easy SC

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

* `Coop IT Easy SC <https://coopiteasy.be>`_:

* Carmen Bianca Bakker

Maintainers
~~~~~~~~~~~

This module is part of the `coopiteasy/cie-custom <https://github.com/coopiteasy/cie-custom/tree/16.0/rotordc_optional_product>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions rotordc_optional_product/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
27 changes: 27 additions & 0 deletions rotordc_optional_product/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022 Coop IT Easy SC
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "RotorDC Optional Product",
"summary": """
Custom modifications regarding RotorDC's use of optional products.""",
"version": "16.0.1.0.0",
"category": "Sales",
"website": "https://coopiteasy.be",
"author": "Coop IT Easy SC",
"license": "AGPL-3",
"depends": [
"sale_product_configurator",
"web",
"website_sale",
],
"data": [
"views/sale_product_configurator_templates.xml",
"views/templates.xml",
],
"assets": {
"web.assets_frontend": [
"rotordc_optional_product/static/src/js/product_configurator_modal.esm.js",
],
},
}
1 change: 1 addition & 0 deletions rotordc_optional_product/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
62 changes: 62 additions & 0 deletions rotordc_optional_product/controllers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# SPDX-FileCopyrightText: 2022 Coop IT Easy SC
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import http
from odoo.http import request

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


class MissingCategoryException(Exception):
def __init__(self, *args, **kwargs):
super().__init__(*args)
self.unused_categs = kwargs.get("unused_categs")


def _verify_products_have_all_optional_products(env, order):
"""On an order, verify that each product has chosen one optional product of
each available category to that product.

Return a Dict[sale.order.line, product.category] with all order lines that
have missing categories.
"""
order_line_unused_map = {}
for order_line in order.order_line:
try:
_verify_line(order_line)
except MissingCategoryException as err:
order_line_unused_map[order_line] = err.unused_categs
return order_line_unused_map


def _verify_line(order_line):
# FIXME: Consider also raising an exception if there is a duplicate encounter.
categ_ids = {
template_id.categ_id
for template_id in order_line.product_id.optional_product_ids
}
encountered = {line.product_id.categ_id for line in order_line.option_line_ids}
# unused_categs is all elements in categ_ids that are not in encountered,
# NOT the other way around. The other way around is not tested, assuming
# that Odoo works soundly.
unused_categs = categ_ids.difference(encountered)
if unused_categs:
raise MissingCategoryException(unused_categs=unused_categs)


class WebsiteSaleDelivery(WebsiteSale):
@http.route()
def checkout(self, **post):
order = request.website.sale_get_order()
result = _verify_products_have_all_optional_products(request.env, order)

if result:
return request.render(
"rotordc_optional_product.missing_categories",
{
"order_line_unused_map": result,
},
)

return super().checkout(**post)
66 changes: 66 additions & 0 deletions rotordc_optional_product/i18n/rotordc_optional_product.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * rotordc_optional_product
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "<br/>\n"
" Missing categories:"
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "Go to"
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "If this problem persists, please contact us."
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "In order to rectify this problem, take the following steps:"
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "Re-add the products. When you do, make sure to also add any available 'Optional Products'."
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "The order checkout was interrupted because your order is not complete. You added one or more products to your cart that are not completely configured. The products are listed below together with the configurations that are missing."
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "Try checking out again."
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "Your order is incomplete"
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "and remove the above listed products."
msgstr ""

#. module: rotordc_optional_product
#: model_terms:ir.ui.view,arch_db:rotordc_optional_product.missing_categories
msgid "your cart"
msgstr ""

3 changes: 3 additions & 0 deletions rotordc_optional_product/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Coop IT Easy SC <https://coopiteasy.be>`_:

* Carmen Bianca Bakker
10 changes: 10 additions & 0 deletions rotordc_optional_product/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
This module has two main behaviours:

- When selecting optional products in the 'add to cart' modal, the user is
prevented from adding more than one optional product of the same internal
category.
- When checking out, the user is redirected to an informative error page when
they did not select all available optional products for their order. e.g. if a
lamp has optional products with the internal categories 'light bulb' and
'cable', then the user **must** select one optional product of both categories
when ordering a lamp.
Loading
Loading