diff --git a/addons/pos_self_order/models/product_product.py b/addons/pos_self_order/models/product_product.py index 413f7a059b5..894781dc957 100644 --- a/addons/pos_self_order/models/product_product.py +++ b/addons/pos_self_order/models/product_product.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from __future__ import annotations + from typing import List, Dict, Optional from odoo import api, models, fields +from copy import deepcopy from odoo.addons.point_of_sale.models.pos_config import PosConfig @@ -66,9 +69,16 @@ class ProductProduct(models.Model): def _get_attributes(self, pos_config_sudo: PosConfig) -> List[Dict]: self.ensure_one() - attributes = self._filter_applicable_attributes( - self.env["pos.session"]._get_attributes_by_ptal_id() - ) + attributes = self.env.context.get("cached_attributes_by_ptal_id") + + if attributes is None: + attributes = self.env["pos.session"]._get_attributes_by_ptal_id() + attributes = self._filter_applicable_attributes(attributes) + else: + # Performance trick to avoid unnecessary calls to _get_attributes_by_ptal_id() + # Needs to be deep-copied because attributes is potentially mutated + attributes = deepcopy(self._filter_applicable_attributes(attributes)) + return self._add_price_info_to_attributes( attributes, pos_config_sudo, @@ -200,6 +210,8 @@ class ProductProduct(models.Model): } def _get_self_order_data(self, pos_config: PosConfig) -> List[Dict]: + attributes_by_ptal_id = self.env["pos.session"]._get_attributes_by_ptal_id() + self = self.with_context(cached_attributes_by_ptal_id=attributes_by_ptal_id) return [ product._get_product_for_ui(pos_config) for product in self