From 3751379f1e9a4c215fb6eb898b4ccc67659b9ace Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 21:51:50 +0700 Subject: initial commit 2 --- .../models/__init__.py | 3 +++ .../models/sale_order.py | 25 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 addons/website_sale_product_configurator/models/__init__.py create mode 100644 addons/website_sale_product_configurator/models/sale_order.py (limited to 'addons/website_sale_product_configurator/models') diff --git a/addons/website_sale_product_configurator/models/__init__.py b/addons/website_sale_product_configurator/models/__init__.py new file mode 100644 index 00000000..6064afee --- /dev/null +++ b/addons/website_sale_product_configurator/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import sale_order diff --git a/addons/website_sale_product_configurator/models/sale_order.py b/addons/website_sale_product_configurator/models/sale_order.py new file mode 100644 index 00000000..3d25c8f9 --- /dev/null +++ b/addons/website_sale_product_configurator/models/sale_order.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def _cart_find_product_line(self, product_id=None, line_id=None, **kwargs): + lines = super(SaleOrder, self)._cart_find_product_line(product_id, line_id, **kwargs) + if line_id: # in this case we get the exact line we want, so filtering below would be wrong + return lines + + linked_line_id = kwargs.get('linked_line_id', False) + optional_product_ids = set(kwargs.get('optional_product_ids', [])) + + lines = lines.filtered(lambda line: line.linked_line_id.id == linked_line_id) + if optional_product_ids: + # only match the lines with the same chosen optional products on the existing lines + lines = lines.filtered(lambda line: optional_product_ids == set(line.mapped('option_line_ids.product_id.id'))) + else: + lines = lines.filtered(lambda line: not line.option_line_ids) + + return lines -- cgit v1.2.3