From ded660ad88bb3d56c51cff7876dc83da7ce9ccf2 Mon Sep 17 00:00:00 2001 From: "Victor Piryns (pivi)" Date: Wed, 10 Jan 2024 10:20:12 +0100 Subject: [PATCH] [REV] point_of_sale,pos_sale: remove usage of `lru_cache` Since b6242264ea9f9f9f42cca4427e30071219ae6a70 a new caching strategy for reducing the database queries when computing frequently the currency conversions or rate was implemented. Therefor it isn't needed to use a local `lru_cache` anymore. The new cache is implemented via a `depends_context` which each have their own ORM cache lasting for the current transaction. Part-of: odoo/odoo#148825 --- addons/point_of_sale/models/pos_order.py | 14 ++------------ addons/pos_sale/models/pos_order.py | 13 +------------ 2 files changed, 3 insertions(+), 24 deletions(-) diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 37dd9b43acc..b361860278e 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -3,7 +3,7 @@ import logging from datetime import datetime from markupsafe import Markup -from functools import partial, lru_cache +from functools import partial from itertools import groupby from collections import defaultdict @@ -380,18 +380,8 @@ class PosOrder(models.Model): @api.depends('date_order', 'company_id', 'currency_id', 'company_id.currency_id') def _compute_currency_rate(self): - @lru_cache - def get_rate(from_currency, to_currency, company, date): - return self.env['res.currency']._get_conversion_rate( - from_currency=from_currency, - to_currency=to_currency, - company=company, - date=date, - ) for order in self: - # date_order is a datetime, but the rates are looked up on a date basis, - # therefor converting the date_order to a date helps with sharing entries in the lru_cache - order.currency_rate = get_rate(order.company_id.currency_id, order.currency_id, order.company_id, order.date_order.date()) + order.currency_rate = self.env['res.currency']._get_conversion_rate(order.company_id.currency_id, order.currency_id, order.company_id, order.date_order) @api.depends('lines.is_total_cost_computed') def _compute_is_total_cost_computed(self): diff --git a/addons/pos_sale/models/pos_order.py b/addons/pos_sale/models/pos_order.py index a8b02052461..534ccc869a3 100644 --- a/addons/pos_sale/models/pos_order.py +++ b/addons/pos_sale/models/pos_order.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from functools import lru_cache from odoo import api, fields, models, _ from odoo.tools import float_compare, float_is_zero @@ -25,19 +24,9 @@ class PosOrder(models.Model): @api.depends('date_order', 'company_id') def _compute_currency_rate(self): - @lru_cache - def get_rate(from_currency, to_currency, company, date): - return self.env['res.currency']._get_conversion_rate( - from_currency=from_currency, - to_currency=to_currency, - company=company, - date=date, - ) for order in self: date_order = order.date_order or fields.Datetime.now() - # date_order is a datetime, but the rates are looked up on a date basis, - # therefor converting the date_order to a date helps with sharing entries in the lru_cache - order.currency_rate = get_rate(order.company_id.currency_id, order.currency_id, order.company_id, date_order.date()) + order.currency_rate = self.env['res.currency']._get_conversion_rate(order.company_id.currency_id, order.currency_id, order.company_id, date_order) def _prepare_invoice_vals(self): invoice_vals = super(PosOrder, self)._prepare_invoice_vals()