[PERF] point_of_sale,pos_sale: better usage of the currency cache

Tune currency cache usage to enhance entry sharing by converting
date_order from datetimes to dates. This change aligns with currency
rates being queried based on dates, enabling the cache to consolidate
entries for identical currency rates on the same date. This optimization
reduces the number of entries and queries, especially for orders made on
the same date but different times.

closes odoo/odoo#148825

Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
Victor Piryns (pivi)
2024-01-10 19:39:35 +00:00
parent ded660ad88
commit 40dab4b5a3
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -381,7 +381,7 @@ class PosOrder(models.Model):
@api.depends('date_order', 'company_id', 'currency_id', 'company_id.currency_id')
def _compute_currency_rate(self):
for order in self:
order.currency_rate = self.env['res.currency']._get_conversion_rate(order.company_id.currency_id, order.currency_id, order.company_id, order.date_order)
order.currency_rate = self.env['res.currency']._get_conversion_rate(order.company_id.currency_id, order.currency_id, order.company_id, order.date_order.date())
@api.depends('lines.is_total_cost_computed')
def _compute_is_total_cost_computed(self):
+1 -1
View File
@@ -26,7 +26,7 @@ class PosOrder(models.Model):
def _compute_currency_rate(self):
for order in self:
date_order = order.date_order or fields.Datetime.now()
order.currency_rate = self.env['res.currency']._get_conversion_rate(order.company_id.currency_id, order.currency_id, order.company_id, date_order)
order.currency_rate = self.env['res.currency']._get_conversion_rate(order.company_id.currency_id, order.currency_id, order.company_id, date_order.date())
def _prepare_invoice_vals(self):
invoice_vals = super(PosOrder, self)._prepare_invoice_vals()