[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
This commit is contained in:
Victor Piryns (pivi)
2024-01-10 19:39:35 +00:00
parent cced5ab357
commit ded660ad88
2 changed files with 3 additions and 24 deletions
+2 -12
View File
@@ -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):
+1 -12
View File
@@ -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()