diff --git a/website_product_uom_multi/README.rst b/website_product_uom_multi/README.rst new file mode 100644 index 000000000..13299bc0b --- /dev/null +++ b/website_product_uom_multi/README.rst @@ -0,0 +1,47 @@ +.. image:: https://img.shields.io/badge/license-AGPL--3-blue.svg + :target: https://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +Website Product Multi Uom +========================= +Select the Product's UOM before adding to Cart. + +Configuration +============= +* No additional configurations needed + +Company +------- +* `Cybrosys Techno Solutions `__ + +License +------- +Affero General Public License v3.0 (AGPL v3) +(https://www.gnu.org/licenses/agpl-3.0-standalone.html) + + +Credits +------- +Developer: (V17) Anfas Faisal K @cybrosys, Contact: odoo@cybrosys.com + +Contacts +-------- +* Mail Contact : odoo@cybrosys.com +* Website : https://cybrosys.com + +Bug Tracker +----------- +Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. + +Maintainer +========== +.. image:: https://cybrosys.com/images/logo.png + :target: https://cybrosys.com + +This module is maintained by Cybrosys Technologies. + +For support and more information, please visit `Our Website `__ + +Further information +=================== +HTML Description: ``__ diff --git a/website_product_uom_multi/__init__.py b/website_product_uom_multi/__init__.py new file mode 100644 index 000000000..b2cc6599c --- /dev/null +++ b/website_product_uom_multi/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from . import controllers +from . import models diff --git a/website_product_uom_multi/__manifest__.py b/website_product_uom_multi/__manifest__.py new file mode 100644 index 000000000..7eca92b11 --- /dev/null +++ b/website_product_uom_multi/__manifest__.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +{ + 'name': 'Website Product Multi Uom', + 'version': '17.0.1.0.0', + 'category': 'Website', + 'summary': 'Select the Products UOM before adding to Cart', + 'description': 'This module allows customers to select the preferred ' + 'Unit of Measure (UOM) for products directly from the ' + 'website before adding them to the cart. It provides a ' + 'dropdown button for changing the UOM, similar to the ' + 'pricelist dropdown, ensuring that the product price ' + 'updates accordingly based on the selected UOM. This ' + 'customization enhances the shopping experience by giving ' + 'customers the flexibility to choose product quantities ' + 'that best suit their needs.', + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'maintainer': 'Cybrosys Techno Solutions', + 'website': "https://www.cybrosys.com", + 'depends': ['website_sale', 'uom', 'website_sale_product_configurator'], + 'data': [ + 'security/ir.model.access.csv', + 'views/website_sale_templates.xml', + ], + 'assets': { + 'web.assets_frontend': [ + "/website_product_uom_multi/static/src/js/uom_button.js", + ], + }, + 'images': ['static/description/banner.jpg'], + 'license': 'AGPL-3', + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/website_product_uom_multi/controllers/__init__.py b/website_product_uom_multi/controllers/__init__.py new file mode 100644 index 000000000..a388a2857 --- /dev/null +++ b/website_product_uom_multi/controllers/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from . import website_sale +from . import variant +from . import product_configurator diff --git a/website_product_uom_multi/controllers/product_configurator.py b/website_product_uom_multi/controllers/product_configurator.py new file mode 100644 index 000000000..46d27d1d2 --- /dev/null +++ b/website_product_uom_multi/controllers/product_configurator.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from odoo import http +from odoo.http import request + +from odoo.addons.website_sale_product_configurator.controllers.main import \ + WebsiteSaleProductConfiguratorController + + +class WebsiteProductVariant(WebsiteSaleProductConfiguratorController): + """ + This class extends the WebsiteVariantSale controller to handle the submission + of optional product modals, ensuring that the Unit of Measure (UOM) is included + in the cart update operations. + """ + @http.route( + '/sale_product_configurator/show_advanced_configurator', + type='json', auth='public', methods=['POST'], website=True, + ) + def show_advanced_configurator( + self, product_id, variant_values, add_qty=1, + force_dialog=False, + **kw, + ): + """ + This method handles the request to display the advanced product + configurator, which allows users to configure product variants and + optional products. It checks if there are any optional products + that can be added to the cart, and if the product has variants + or is already configured. + """ + product = request.env['product.product'].browse(int(product_id)) + product_template = product.product_tmpl_id + combination = request.env['product.template.attribute.value'].browse( + variant_values) + has_optional_products = product.optional_product_ids.filtered( + lambda p: p._is_add_to_cart_possible(combination) + and ( + not request.website.prevent_zero_price_sale or p._get_contextual_price()) + ) + already_configured = bool(combination) + if not force_dialog and not has_optional_products and ( + product.product_variant_count <= 1 or already_configured + ): + # The modal is not shown if there are no optional products and + # the main product either has no variants or is already configured + return False + + add_qty = float(add_qty) + combination_info = product_template._get_combination_info( + combination=combination, + product_id=product.id, + add_qty=add_qty, + ) + uom_id_session = request.session['uom_id'] + + if uom_id_session: + uom_id = request.env['uom.uom'].browse(int(uom_id_session)) + product = request.env['product.product'].sudo().browse(product_id) + default_uom_qty = uom_id._compute_quantity(1, product.uom_id) + updated_price = combination_info['list_price'] * default_uom_qty + combination_info.update({'price': updated_price}) + + return request.env['ir.ui.view']._render_template( + 'website_sale_product_configurator.optional_products_modal', + { + 'product': product, + 'product_template': product_template, + 'combination': combination, + 'combination_info': combination_info, + 'add_qty': add_qty, + 'parent_name': product.name, + 'variant_values': variant_values, + 'already_configured': already_configured, + 'mode': kw.get('mode', 'add'), + 'product_custom_attribute_values': kw.get( + 'product_custom_attribute_values', None), + 'no_attribute': kw.get('no_attribute', False), + 'custom_attribute': kw.get('custom_attribute', False), + } + ) diff --git a/website_product_uom_multi/controllers/variant.py b/website_product_uom_multi/controllers/variant.py new file mode 100644 index 000000000..2a3feaa37 --- /dev/null +++ b/website_product_uom_multi/controllers/variant.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from odoo import http +from odoo.http import request + +from odoo.addons.website_sale.controllers.variant import \ + WebsiteSaleVariantController + + +class Vairant(WebsiteSaleVariantController): + @http.route('/website_sale/get_combination_info', type='json', + auth='public', + methods=['POST'], website=True) + def get_combination_info_website( + self, product_template_id, product_id, combination, add_qty, + uom=False, + parent_combination=None, + **kwargs + ): + res = super( + Vairant, self).get_combination_info_website( + product_template_id=product_template_id, product_id=product_id, + combination=combination, add_qty=add_qty, + uom=uom, parent_combination=parent_combination, **kwargs) + request.session['uom_id'] = uom + if uom: + uom_id = request.env['uom.uom'].browse(int(uom)) + product = request.env['product.product'].sudo().browse(product_id) + default_uom_qty = uom_id._compute_quantity(add_qty, product.uom_id) + updated_price = res['list_price'] * default_uom_qty + res.update({'price': updated_price}) + return res diff --git a/website_product_uom_multi/controllers/website_sale.py b/website_product_uom_multi/controllers/website_sale.py new file mode 100644 index 000000000..d08874a4b --- /dev/null +++ b/website_product_uom_multi/controllers/website_sale.py @@ -0,0 +1,206 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +import json +import logging + +from odoo import fields, http +from odoo.http import request +from odoo.tools.json import scriptsafe as json_scriptsafe +from odoo.addons.payment import utils as payment_utils + +_logger = logging.getLogger(__name__) + +from odoo.addons.website_sale.controllers.main import WebsiteSale +from odoo.addons.website_sale_product_configurator.controllers.website_sale import \ + WebsiteSale as WebsiteVariantSale + + +class WebsiteProductUom(WebsiteSale): + """ + This class extends the WebsiteSale controller to include Unit of Measure + (UOM) in the shopping cart update operations. It overrides the + cart_update_json route to handle UOM-specific updates. + """ + + @http.route(['/shop/cart/update_json'], type='json', auth="public", + methods=['POST'], website=True, csrf=False) + def cart_update_json( + self, product_id, line_id=None, add_qty=None, set_qty=None, + display=True, + product_custom_attribute_values=None, + no_variant_attribute_values=None, uom_id=None, **kw + ): + + """ + This route is called : + - When changing quantity from the cart. + - When adding a product from the wishlist. + - When adding a product to cart on the same page (without redirection). + """ + order = request.website.sale_get_order(force_create=True) + + if order.state != 'draft': + request.website.sale_reset() + if kw.get('force_create'): + order = request.website.sale_get_order(force_create=True) + else: + return {} + + if product_custom_attribute_values: + product_custom_attribute_values = json_scriptsafe.loads( + product_custom_attribute_values) + + if no_variant_attribute_values: + no_variant_attribute_values = json_scriptsafe.loads( + no_variant_attribute_values) + + values = order._cart_update( + product_id=product_id, + line_id=line_id, + add_qty=add_qty, + set_qty=set_qty, + product_custom_attribute_values=product_custom_attribute_values, + no_variant_attribute_values=no_variant_attribute_values, + uom=uom_id, + **kw + ) + + values['notification_info'] = self._get_cart_notification_information( + order, [values['line_id']]) + values['notification_info']['warning'] = values.pop('warning', '') + request.session['website_sale_cart_quantity'] = order.cart_quantity + + if not order.cart_quantity: + request.website.sale_reset() + return values + + values['cart_quantity'] = order.cart_quantity + values['minor_amount'] = payment_utils.to_minor_currency_units( + order.amount_total, order.currency_id + ), + values['amount'] = order.amount_total + + if not display: + return values + + values['cart_ready'] = order._is_cart_ready() + values['website_sale.cart_lines'] = request.env[ + 'ir.ui.view']._render_template( + "website_sale.cart_lines", { + 'website_sale_order': order, + 'date': fields.Date.today(), + 'suggested_products': order._cart_accessories() + } + ) + values['website_sale.total'] = request.env[ + 'ir.ui.view']._render_template( + "website_sale.total", { + 'website_sale_order': order, + } + ) + return values + + +class WebsiteProductVariant(WebsiteVariantSale): + """ + This class extends the WebsiteVariantSale controller to handle the submission + of optional product modals, ensuring that the Unit of Measure (UOM) is included + in the cart update operations. + """ + + @http.route( + '/shop/cart/update_option', + type='json', + auth='public', + methods=['POST'], + website=True, + multilang=False, + ) + def cart_options_update_json(self, product_and_options, lang=None, + **kwargs): + """This route is called when submitting the optional product modal. + The product without parent is the main product, the other are options. + Options need to be linked to their parents with a unique ID. + The main product is the first product in the list and the options + need to be right after their parent. + product_and_options { + 'product_id', + 'product_template_id', + 'quantity', + 'parent_unique_id', + 'unique_id', + 'product_custom_attribute_values', + 'no_variant_attribute_values' + } + """ + if lang: + request.website = request.website.with_context(lang=lang) + + order = request.website.sale_get_order(force_create=True) + if order.state != 'draft': + request.session['sale_order_id'] = None + order = request.website.sale_get_order(force_create=True) + + product_and_options = json.loads(product_and_options) + if product_and_options: + # The main product is the first, optional products are the rest + main_product = product_and_options[0] + values = order._cart_update( + product_id=main_product['product_id'], + add_qty=main_product['quantity'], + product_custom_attribute_values=main_product[ + 'product_custom_attribute_values'], + no_variant_attribute_values=main_product[ + 'no_variant_attribute_values'], + uom=main_product['uom_id'], + **kwargs + ) + + line_ids = [values['line_id']] + + if values['line_id']: + # Link option with its parent iff line has been created. + option_parent = {main_product['unique_id']: values['line_id']} + for option in product_and_options[1:]: + parent_unique_id = option['parent_unique_id'] + option_values = order._cart_update( + product_id=option['product_id'], + set_qty=option['quantity'], + linked_line_id=option_parent[parent_unique_id], + product_custom_attribute_values=option[ + 'product_custom_attribute_values'], + no_variant_attribute_values=option[ + 'no_variant_attribute_values'], + **kwargs + ) + option_parent[option['unique_id']] = option_values[ + 'line_id'] + line_ids.append(option_values['line_id']) + + values[ + 'notification_info'] = self._get_cart_notification_information( + order, line_ids) + + values['cart_quantity'] = order.cart_quantity + request.session['website_sale_cart_quantity'] = order.cart_quantity + + return values diff --git a/website_product_uom_multi/doc/RELEASE_NOTES.md b/website_product_uom_multi/doc/RELEASE_NOTES.md new file mode 100644 index 000000000..d6bd5677d --- /dev/null +++ b/website_product_uom_multi/doc/RELEASE_NOTES.md @@ -0,0 +1,7 @@ +## Module + +#### 04.07.2024 +#### Version 17.0.1.0.0 +#### ADD + +- Initial Commit for Website Product Multi Uom diff --git a/website_product_uom_multi/models/__init__.py b/website_product_uom_multi/models/__init__.py new file mode 100644 index 000000000..5f1ac1e27 --- /dev/null +++ b/website_product_uom_multi/models/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from . import product_template +from . import sale_order diff --git a/website_product_uom_multi/models/product_template.py b/website_product_uom_multi/models/product_template.py new file mode 100644 index 000000000..6904e5048 --- /dev/null +++ b/website_product_uom_multi/models/product_template.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from odoo import api, models +from odoo.http import request + + +class ProductProduct(models.Model): + """ + Inherits the product.template model to extend its functionality. + """ + _inherit = 'product.template' + + @api.model + def _get_contextual_price(self, product=None): + """ + Get the contextual price of a product based on the current pricelist, + quantity, unit of measure (UOM), and date. If the UOM is not specified + in the context, it checks the session for a UOM ID. + """ + self.ensure_one() + pricelist = self._get_contextual_pricelist() + quantity = self.env.context.get('quantity', 1.0) + uom_id = self.env.context.get('uom') + # Check if uom_id is available in the session + if not uom_id and request.session.get('uom_id'): + uom_id = request.session['uom_id'] + date = self.env.context.get('date') + uom = self.env['uom.uom'].browse(uom_id) if uom_id else self.uom_id + return pricelist._get_product_price(product or self, quantity, uom=uom, + date=date) diff --git a/website_product_uom_multi/models/sale_order.py b/website_product_uom_multi/models/sale_order.py new file mode 100644 index 000000000..74ae62857 --- /dev/null +++ b/website_product_uom_multi/models/sale_order.py @@ -0,0 +1,142 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Cybrosys Technologies Pvt. Ltd. +# +# Copyright (C) 2024-TODAY Cybrosys Technologies(). +# Author: Anfas Faisal K (odoo@cybrosys.info) +# +# You can modify it under the terms of the GNU AFFERO +# GENERAL PUBLIC LICENSE (AGPL v3), Version 3. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. +# +# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE +# (AGPL v3) along with this program. +# If not, see . +# +################################################################################ +from odoo import models, _ +from odoo.exceptions import UserError +from odoo.http import request + + +class SaleOrder(models.Model): + """ + Inherits the sale.order model to extend its functionality. + """ + _inherit = 'sale.order' + + def _cart_update(self, product_id, line_id=None, add_qty=0, set_qty=0, + uom=None, **kwargs): + """ Add or set product quantity, add_qty can be negative """ + self.ensure_one() + self = self.with_company(self.company_id) + + if self.state != 'draft': + request.session.pop('sale_order_id', None) + request.session.pop('website_sale_cart_quantity', None) + raise UserError( + _('It is forbidden to modify a sales order which is not in draft status.')) + + product = self.env['product.product'].browse(product_id).exists() + uom_id = self.env['uom.uom'].browse(uom) + if add_qty and (not product or not product._is_add_to_cart_allowed()): + raise UserError( + _("The given product does not exist therefore it cannot be added to cart.")) + + if line_id is not False: + order_line = self._cart_find_product_line(product_id, line_id, + **kwargs)[:1] + if uom_id : + order_line_ids = order_line.order_id.order_line + current_product_ids = order_line_ids.filtered(lambda l: l.product_id.id == product_id) + if current_product_ids: + order_line = current_product_ids.filtered(lambda n: n.product_uom.id == uom_id.id) + + else: + order_line = self.env['sale.order.line'] + + try: + if add_qty: + add_qty = int(add_qty) + except ValueError: + add_qty = 1 + + try: + if set_qty: + set_qty = int(set_qty) + except ValueError: + set_qty = 0 + + quantity = 0 + if set_qty: + quantity = set_qty + elif add_qty is not None: + if order_line: + quantity = order_line.product_uom_qty + (add_qty or 0) + else: + quantity = add_qty or 0 + + if quantity > 0: + quantity, warning = self._verify_updated_quantity( + order_line, + product_id, + quantity, + **kwargs, + ) + else: + # If the line will be removed anyway, there is no need to verify + # the requested quantity update. + warning = '' + + self._remove_delivery_line() + + order_line = self._cart_update_order_line(product_id, quantity, + order_line,uom_id, **kwargs) + + if ( + order_line + and order_line.price_unit == 0 + and self.website_id.prevent_zero_price_sale + and product.detailed_type not in self.env[ + 'product.template']._get_product_types_allow_zero_price() + ): + raise UserError(_( + "The given product does not have a price therefore it cannot be added to cart.", + )) + + return { + 'line_id': order_line.id, + 'quantity': quantity, + 'option_ids': list(set(order_line.option_line_ids.filtered( + lambda l: l.order_id == order_line.order_id).ids)), + 'warning': warning, + } + + + def _cart_update_order_line(self, product_id, quantity, order_line, uom_id, **kwargs): + """ + Update the order line in the cart based on the given product, + quantity, and UOM. + """ + self.ensure_one() + if order_line and quantity <= 0: + # Remove zero or negative lines + order_line.unlink() + order_line = self.env['sale.order.line'] + elif order_line: + # Update existing line + update_values = self._prepare_order_line_update_values(order_line, quantity, **kwargs) + if update_values: + self._update_cart_line_values(order_line, update_values) + elif quantity > 0: + # Create new line + order_line_values = self._prepare_order_line_values(product_id, quantity, **kwargs) + if uom_id: + order_line_values['product_uom'] = uom_id.id + order_line = self.env['sale.order.line'].sudo().create(order_line_values) + return order_line diff --git a/website_product_uom_multi/security/ir.model.access.csv b/website_product_uom_multi/security/ir.model.access.csv new file mode 100644 index 000000000..da56c122f --- /dev/null +++ b/website_product_uom_multi/security/ir.model.access.csv @@ -0,0 +1,6 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_uom_category_portal,uom.category,uom.model_uom_category,base.group_portal,1,0,0,0 +access_uom_uom_portal,uom.uom,uom.model_uom_uom,base.group_portal,1,0,0,0 +access_uom_category_public,uom.category,uom.model_uom_category,base.group_public,1,0,0,0 +access_uom_uom_public,uom.uom,uom.model_uom_uom,base.group_public,1,0,0,0 + diff --git a/website_product_uom_multi/static/description/assets/icons/check.png b/website_product_uom_multi/static/description/assets/icons/check.png new file mode 100644 index 000000000..c8e85f51d Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/check.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/chevron.png b/website_product_uom_multi/static/description/assets/icons/chevron.png new file mode 100644 index 000000000..2089293d6 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/chevron.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/cogs.png b/website_product_uom_multi/static/description/assets/icons/cogs.png new file mode 100644 index 000000000..95d0bad62 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/cogs.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/consultation.png b/website_product_uom_multi/static/description/assets/icons/consultation.png new file mode 100644 index 000000000..8319d4baa Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/consultation.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/ecom-black.png b/website_product_uom_multi/static/description/assets/icons/ecom-black.png new file mode 100644 index 000000000..a9385ff13 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/ecom-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/education-black.png b/website_product_uom_multi/static/description/assets/icons/education-black.png new file mode 100644 index 000000000..3eb09b27b Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/education-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/hotel-black.png b/website_product_uom_multi/static/description/assets/icons/hotel-black.png new file mode 100644 index 000000000..130f613be Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/hotel-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/license.png b/website_product_uom_multi/static/description/assets/icons/license.png new file mode 100644 index 000000000..a5869797e Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/license.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/lifebuoy.png b/website_product_uom_multi/static/description/assets/icons/lifebuoy.png new file mode 100644 index 000000000..658d56ccc Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/lifebuoy.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/manufacturing-black.png b/website_product_uom_multi/static/description/assets/icons/manufacturing-black.png new file mode 100644 index 000000000..697eb0e9f Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/manufacturing-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/pos-black.png b/website_product_uom_multi/static/description/assets/icons/pos-black.png new file mode 100644 index 000000000..97c0f90c1 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/pos-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/puzzle.png b/website_product_uom_multi/static/description/assets/icons/puzzle.png new file mode 100644 index 000000000..65cf854e7 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/puzzle.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/restaurant-black.png b/website_product_uom_multi/static/description/assets/icons/restaurant-black.png new file mode 100644 index 000000000..4a35eb939 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/restaurant-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/service-black.png b/website_product_uom_multi/static/description/assets/icons/service-black.png new file mode 100644 index 000000000..301ab51cb Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/service-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/trading-black.png b/website_product_uom_multi/static/description/assets/icons/trading-black.png new file mode 100644 index 000000000..9398ba2f1 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/trading-black.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/training.png b/website_product_uom_multi/static/description/assets/icons/training.png new file mode 100644 index 000000000..884ca024d Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/training.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/update.png b/website_product_uom_multi/static/description/assets/icons/update.png new file mode 100644 index 000000000..ecbc5a01a Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/update.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/user.png b/website_product_uom_multi/static/description/assets/icons/user.png new file mode 100644 index 000000000..6ffb23d9f Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/user.png differ diff --git a/website_product_uom_multi/static/description/assets/icons/wrench.png b/website_product_uom_multi/static/description/assets/icons/wrench.png new file mode 100644 index 000000000..6c04dea0f Binary files /dev/null and b/website_product_uom_multi/static/description/assets/icons/wrench.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/Cybrosys_new.png b/website_product_uom_multi/static/description/assets/misc/Cybrosys_new.png new file mode 100644 index 000000000..da4058087 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/Cybrosys_new.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/categories.png b/website_product_uom_multi/static/description/assets/misc/categories.png new file mode 100644 index 000000000..bedf1e0b1 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/categories.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/check-box.png b/website_product_uom_multi/static/description/assets/misc/check-box.png new file mode 100644 index 000000000..42caf24b9 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/check-box.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/compass.png b/website_product_uom_multi/static/description/assets/misc/compass.png new file mode 100644 index 000000000..d5fed8faa Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/compass.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/corporate.png b/website_product_uom_multi/static/description/assets/misc/corporate.png new file mode 100644 index 000000000..2eb13edbf Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/corporate.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/customer-support.png b/website_product_uom_multi/static/description/assets/misc/customer-support.png new file mode 100644 index 000000000..79efc72ed Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/customer-support.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/cybrosys-logo.png b/website_product_uom_multi/static/description/assets/misc/cybrosys-logo.png new file mode 100644 index 000000000..cc3cc0ccf Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/cybrosys-logo.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/features.png b/website_product_uom_multi/static/description/assets/misc/features.png new file mode 100644 index 000000000..b41769f77 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/features.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/logo.png b/website_product_uom_multi/static/description/assets/misc/logo.png new file mode 100644 index 000000000..478462d3e Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/logo.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/pictures.png b/website_product_uom_multi/static/description/assets/misc/pictures.png new file mode 100644 index 000000000..56d255fe9 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/pictures.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/pie-chart.png b/website_product_uom_multi/static/description/assets/misc/pie-chart.png new file mode 100644 index 000000000..426e05244 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/pie-chart.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/right-arrow.png b/website_product_uom_multi/static/description/assets/misc/right-arrow.png new file mode 100644 index 000000000..730984a06 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/right-arrow.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/star.png b/website_product_uom_multi/static/description/assets/misc/star.png new file mode 100644 index 000000000..2eb9ab29f Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/star.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/support.png b/website_product_uom_multi/static/description/assets/misc/support.png new file mode 100644 index 000000000..4f18b8b82 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/support.png differ diff --git a/website_product_uom_multi/static/description/assets/misc/whatsapp.png b/website_product_uom_multi/static/description/assets/misc/whatsapp.png new file mode 100644 index 000000000..d513a5356 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/misc/whatsapp.png differ diff --git a/website_product_uom_multi/static/description/assets/modules/1.jpg b/website_product_uom_multi/static/description/assets/modules/1.jpg new file mode 100644 index 000000000..f3a24c620 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/modules/1.jpg differ diff --git a/website_product_uom_multi/static/description/assets/modules/2.jpg b/website_product_uom_multi/static/description/assets/modules/2.jpg new file mode 100644 index 000000000..5d694c069 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/modules/2.jpg differ diff --git a/website_product_uom_multi/static/description/assets/modules/3.jpg b/website_product_uom_multi/static/description/assets/modules/3.jpg new file mode 100644 index 000000000..9407e5e83 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/modules/3.jpg differ diff --git a/website_product_uom_multi/static/description/assets/modules/4.jpg b/website_product_uom_multi/static/description/assets/modules/4.jpg new file mode 100644 index 000000000..3d3da7f16 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/modules/4.jpg differ diff --git a/website_product_uom_multi/static/description/assets/modules/5.jpg b/website_product_uom_multi/static/description/assets/modules/5.jpg new file mode 100644 index 000000000..0e905cf14 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/modules/5.jpg differ diff --git a/website_product_uom_multi/static/description/assets/modules/6.jpg b/website_product_uom_multi/static/description/assets/modules/6.jpg new file mode 100644 index 000000000..a7a3264ef Binary files /dev/null and b/website_product_uom_multi/static/description/assets/modules/6.jpg differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/1.png b/website_product_uom_multi/static/description/assets/screenshots/1.png new file mode 100644 index 000000000..373b3f3ef Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/1.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/2.png b/website_product_uom_multi/static/description/assets/screenshots/2.png new file mode 100644 index 000000000..2bd3ddcd8 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/2.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/3.png b/website_product_uom_multi/static/description/assets/screenshots/3.png new file mode 100644 index 000000000..18ef4b909 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/3.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/4.png b/website_product_uom_multi/static/description/assets/screenshots/4.png new file mode 100644 index 000000000..17e896090 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/4.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/5.png b/website_product_uom_multi/static/description/assets/screenshots/5.png new file mode 100644 index 000000000..df53dead2 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/5.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/6.png b/website_product_uom_multi/static/description/assets/screenshots/6.png new file mode 100644 index 000000000..e9680f742 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/6.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/7.png b/website_product_uom_multi/static/description/assets/screenshots/7.png new file mode 100644 index 000000000..db900ad16 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/7.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/8.png b/website_product_uom_multi/static/description/assets/screenshots/8.png new file mode 100644 index 000000000..9a1367ba1 Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/8.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/9.png b/website_product_uom_multi/static/description/assets/screenshots/9.png new file mode 100644 index 000000000..4eb85649b Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/9.png differ diff --git a/website_product_uom_multi/static/description/assets/screenshots/hero-v17.gif b/website_product_uom_multi/static/description/assets/screenshots/hero-v17.gif new file mode 100644 index 000000000..4b5f94fbe Binary files /dev/null and b/website_product_uom_multi/static/description/assets/screenshots/hero-v17.gif differ diff --git a/website_product_uom_multi/static/description/banner.jpg b/website_product_uom_multi/static/description/banner.jpg new file mode 100644 index 000000000..91a9c91fe Binary files /dev/null and b/website_product_uom_multi/static/description/banner.jpg differ diff --git a/website_product_uom_multi/static/description/icon.png b/website_product_uom_multi/static/description/icon.png new file mode 100644 index 000000000..944eb3fcd Binary files /dev/null and b/website_product_uom_multi/static/description/icon.png differ diff --git a/website_product_uom_multi/static/description/index.html b/website_product_uom_multi/static/description/index.html new file mode 100644 index 000000000..2095e718f --- /dev/null +++ b/website_product_uom_multi/static/description/index.html @@ -0,0 +1,680 @@ + + + + + + + Odoo App 3 Index + + + + + + + + +
+
+
+
+
+ +
+
+
+ Community +
+
+ Enterprise +
+
+ Odoo.sh +
+
+
+
+
+
+

+ Website Product Multi UOM

+

+ Select the Product's UOM before adding to Cart +

+
+ +
+
+
+
+
+

+ Key Highlights +

+
+
+
+
+
+ +
+
+

+ Flexible UOM Selection in Website

+
+
+
+
+
+ +
+
+

+ Real Time Price Updates .

+
+
+
+
+
+
+ +
+
+

+ UOM-based Checkout .

+
+
+
+
+
+
+ +
+
+
+
+
+ +
+
+

+ Select the UOM for the product and click on Add to Cart +

+ +
+
+
+ +
+
+
+ +
+
+

+ The Products will be spilited based on UOM in the Checkout page

+ +
+
+
+ +
+
+
+
    +
  • + Hide products price in website. +
  • +
  • + Hide add to cart button in the website. +
  • +
  • + Adds a button for price requests from merchants. +
  • +
  • + Track all requests from the backend. +
  • +
+
+
+
+
+
+
Version + 17.0.1.0.0|Released on:22nd February 2024 +
+

+ Initial Commit for Website Call For Price.

+
+
+
+
+
+
+
+

+ Related Products

+
+
+ +
+
+

+ Our Services

+ +
+
+
+
+
+
+
+
+ service-icon +
+
+

Odoo + Customization

+
+
+
+
+
+
+ service-icon +
+
+

Odoo + Implementation

+
+
+
+
+
+
+ service-icon +
+
+

Odoo + Support

+
+
+
+
+
+
+ service-icon +
+
+

Hire + Odoo Developer

+
+
+
+
+ +
+
+ service-icon +
+
+

Odoo + Integration

+
+
+
+
+
+
+ service-icon +
+
+

Odoo + Migration

+
+
+
+
+
+
+ service-icon +
+
+

Odoo + Consultancy

+
+
+
+
+
+
+ service-icon +
+
+

Odoo + Implementation

+
+
+
+
+
+
+ service-icon +
+
+

Odoo + Licensing Consultancy

+
+
+
+
+
+
+

+ Our Industries

+ +
+
+
+
+
+
+ +

Trading

+

Easily procure and sell your products

+
+
+
+
+ +

POS

+

Easy configuration and convivial experience

+
+
+
+
+ +

+ Education

+

A platform for educational management

+
+
+
+
+ +

+ Manufacturing

+

Plan, track and schedule your operations

+
+
+
+
+ +

E-commerce & + Website

+

Mobile friendly, awe-inspiring product pages

+
+
+
+
+ +

Service + Management

+

Keep track of services and invoice

+
+
+
+
+ +

+ Restaurant

+

Run your bar or restaurant methodically

+
+
+
+
+ +

Hotel + Management

+

An all-inclusive hotel management application

+
+
+
+
+
+
+

+ Support

+
+
+
+
+
+
+
+ +
+ Need + Help? +

Got + questions or need help? Get in touch.

+
odoo@cybrosys.com +
+
+
+
+
+
+
+
+ +
+ WhatsApp +

Say hi to + us on WhatsApp!

+
+91 + 99456767686 +
+
+
+
+
+
+
+
+
+ + + + + + diff --git a/website_product_uom_multi/static/src/js/uom_button.js b/website_product_uom_multi/static/src/js/uom_button.js new file mode 100644 index 000000000..34d88bcda --- /dev/null +++ b/website_product_uom_multi/static/src/js/uom_button.js @@ -0,0 +1,214 @@ +/** @odoo-module **/ +import publicWidget from "@web/legacy/js/public/public_widget"; +import { WebsiteSale } from '@website_sale/js/website_sale'; +import { OptionalProductsModal } from "@website_sale_product_configurator/js/sale_product_configurator_modal"; +import { jsonrpc } from "@web/core/network/rpc_service"; +import VariantMixin from "@website_sale/js/sale_variant_mixin"; + +publicWidget.registry.UomDropDown = publicWidget.Widget.extend(VariantMixin,{ + selector: '.o_uom_dropdown', + events: { + 'change #o_uom_dropdown': '_onChangeSelect', + + }, + init(ev) { + this._super(...arguments); + this.rpc = this.bindService("rpc"); + this.orm = this.bindService("orm"); + }, + + + _onChangeSelect: function(ev){ + var self = this + var $parent = $(ev.target).closest('.js_product'); + var $default_price = $parent.find(".oe_default_price:first .oe_currency_value"); + var quantity = $parent.find('.css_quantity'); + var price = $default_price.text().trim(); + var uom_id = ev.target.value + var productID = ev.target.getAttribute('data') + this._getCombinationInfo(ev) + }, + + _getCombinationInfo: function (ev) { + if ($(ev.target).hasClass('variant_custom_value')) { + return Promise.resolve(); + } + + const $parent = $(ev.target).closest('.js_product'); + if(!$parent.length){ + return Promise.resolve(); + } + const combination = this.getSelectedVariantValues($parent); + let parentCombination; + + if ($parent.hasClass('main_product')) { + parentCombination = $parent.find('ul[data-attribute_exclusions]').data('attribute_exclusions').parent_combination; + const $optProducts = $parent.parent().find(`[data-parent-unique-id='${$parent.data('uniqueId')}']`); + + for (const optionalProduct of $optProducts) { + const $currentOptionalProduct = $(optionalProduct); + const childCombination = this.getSelectedVariantValues($currentOptionalProduct); + const productTemplateId = parseInt($currentOptionalProduct.find('.product_template_id').val()); + jsonrpc('/website_sale/get_combination_info', { + 'product_template_id': productTemplateId, + 'product_id': this._getProductId($currentOptionalProduct), + 'combination': childCombination, + 'add_qty': parseInt($currentOptionalProduct.find('input[name="add_qty"]').val()), + 'uom': parseInt($parent.find('select#o_uom_dropdown.form-control').val()), + 'parent_combination': combination, + 'context': this.context, + ...this._getOptionalCombinationInfoParam($currentOptionalProduct), + }).then((combinationData) => { + if (this._shouldIgnoreRpcResult()) { + return; + } + this._onChangeCombination(ev, $currentOptionalProduct, combinationData); + this._checkExclusions($currentOptionalProduct, childCombination, combinationData.parent_exclusions); + }); + } + } else { + parentCombination = this.getSelectedVariantValues( + $parent.parent().find('.js_product.in_cart.main_product') + ); + } + + return jsonrpc('/website_sale/get_combination_info', { + 'product_template_id': parseInt($parent.find('.product_template_id').val()), + 'product_id': this._getProductId($parent), + 'combination': combination, + 'add_qty': parseInt($parent.find('input[name="add_qty"]').val()), + 'parent_combination': parentCombination, + 'uom': parseInt($parent.find('select#o_uom_dropdown.form-control').val()), + 'context': this.context, + ...this._getOptionalCombinationInfoParam($parent), + }).then((combinationData) => { + if (this._shouldIgnoreRpcResult()) { + return; + } + this._onChangeCombination(ev, $parent, combinationData); + this._checkExclusions($parent, combination, combinationData.parent_exclusions); + }); + }, +}); + + + +publicWidget.registry.WebsiteSale.include({ + _updateRootProduct($form, productId) { + this.rootProduct = { + product_id: productId, + quantity: parseFloat($form.find('input[name="add_qty"]').val() || 1), + product_custom_attribute_values: this.getCustomVariantValues($form.find('.js_product')), + variant_values: this.getSelectedVariantValues($form.find('.js_product')), + no_variant_attribute_values: this.getNoVariantAttributeValues($form.find('.js_product')), + uom_id: parseInt($form.find('select#o_uom_dropdown.form-control').val()) // Include the uom_id in the rootProduct object + }; + }, + + _getCombinationInfo: function (ev) { + if ($(ev.target).hasClass('variant_custom_value')) { + return Promise.resolve(); + } + + const $parent = $(ev.target).closest('.js_product'); + if(!$parent.length){ + return Promise.resolve(); + } + const combination = this.getSelectedVariantValues($parent); + let parentCombination; + + if ($parent.hasClass('main_product')) { + parentCombination = $parent.find('ul[data-attribute_exclusions]').data('attribute_exclusions').parent_combination; + + const $optProducts = $parent.parent().find(`[data-parent-unique-id='${$parent.data('uniqueId')}']`); + + for (const optionalProduct of $optProducts) { + const $currentOptionalProduct = $(optionalProduct); + const childCombination = this.getSelectedVariantValues($currentOptionalProduct); + const productTemplateId = parseInt($currentOptionalProduct.find('.product_template_id').val()); + jsonrpc('/website_sale/get_combination_info', { + 'product_template_id': productTemplateId, + 'product_id': this._getProductId($currentOptionalProduct), + 'combination': childCombination, + 'add_qty': parseInt($currentOptionalProduct.find('input[name="add_qty"]').val()), + 'uom': parseInt($parent.find('select#o_uom_dropdown.form-control').val()), + 'parent_combination': combination, + 'context': this.context, + ...this._getOptionalCombinationInfoParam($currentOptionalProduct), + }).then((combinationData) => { + if (this._shouldIgnoreRpcResult()) { + return; + } + this._onChangeCombination(ev, $currentOptionalProduct, combinationData); + this._checkExclusions($currentOptionalProduct, childCombination, combinationData.parent_exclusions); + }); + } + } else { + parentCombination = this.getSelectedVariantValues( + $parent.parent().find('.js_product.in_cart.main_product') + ); + } + + return jsonrpc('/website_sale/get_combination_info', { + 'product_template_id': parseInt($parent.find('.product_template_id').val()), + 'product_id': this._getProductId($parent), + 'combination': combination, + 'add_qty': parseInt($parent.find('input[name="add_qty"]').val()), + 'parent_combination': parentCombination, + 'uom': parseInt($parent.find('select#o_uom_dropdown.form-control').val()), + 'context': this.context, + ...this._getOptionalCombinationInfoParam($parent), + }).then((combinationData) => { + if (this._shouldIgnoreRpcResult()) { + return; + } + this._onChangeCombination(ev, $parent, combinationData); + this._checkExclusions($parent, combination, combinationData.parent_exclusions); + }); + }, + + +}); + +OptionalProductsModal.include({ + + getAndCreateSelectedProducts: async function () { + const self = this; + const products = []; + for (const product of self.$modal.find('.js_product.in_cart')) { + const $item = $(product); + const quantity = parseFloat($item.find('input[name="add_qty"]').val().replace(',', '.') || 1); + const parentUniqueId = product.dataset.parentUniqueId; + const uniqueId = product.dataset.uniqueId; + const uomId = self.rootProduct.uom_id + const productCustomVariantValues = $item.find('.custom-attribute-info').data("attribute-value") || self.getCustomVariantValues($item); + const noVariantAttributeValues = $item.find('.no-attribute-info').data("attribute-value") || self.getNoVariantAttributeValues($item); + + const productID = await self.selectOrCreateProduct( + $item, + parseInt($item.find('input.product_id').val(), 10), + parseInt($item.find('input.product_template_id').val(), 10), + true + ); + + products.push({ + 'product_id': productID, + 'product_template_id': parseInt($item.find('input.product_template_id').val(), 10), + 'quantity': quantity, + 'parent_unique_id': parentUniqueId, + 'unique_id': uniqueId, + 'uom_id': uomId, + 'product_custom_attribute_values': productCustomVariantValues, + 'no_variant_attribute_values': noVariantAttributeValues + }); + } + return products; + }, + _onChangeCombination: function (ev, $parent, combination) { + $parent + .find('.td-product_name .product-name') + .first() + .text(combination.display_name); + this._computePriceTotal(); + } +}); diff --git a/website_product_uom_multi/views/website_sale_templates.xml b/website_product_uom_multi/views/website_sale_templates.xml new file mode 100644 index 000000000..cf335b9bf --- /dev/null +++ b/website_product_uom_multi/views/website_sale_templates.xml @@ -0,0 +1,146 @@ + + + + + +