Use a separate browse list to compute amounts from non cached states

The browse record list loops over the ids of the list to complete the read
batch. So move the record without cache at the end does not prevent to read
the lines of the first records with cache. A separate browse list must be used
for the records without cache to prevent to read lines from record with cache.

Closes #13396
This commit is contained in:
Cédric Krier
2024-07-27 10:16:51 +02:00
parent 48ad8ebb02
commit be68d7ad69
3 changed files with 21 additions and 12 deletions
+7 -4
View File
@@ -532,11 +532,14 @@ class Purchase(
compute_taxes = True
else:
compute_taxes = False
# Sort cached first and re-instanciate to optimize cache management
purchases = sorted(purchases,
key=lambda p: p.state in cls._states_cached, reverse=True)
purchases = cls.browse(purchases)
# Browse separately not cached to limit number of lines read
cached, not_cached = [], []
for purchase in purchases:
if purchase.state in cls._states_cached:
cached.append(purchase)
else:
not_cached.append(purchase)
for purchase in chain(cached, cls.browse(not_cached)):
if (purchase.state in cls._states_cached
and purchase.untaxed_amount_cache is not None
and purchase.tax_amount_cache is not None
+7 -4
View File
@@ -259,11 +259,14 @@ class PurchaseRequisition(Workflow, ModelSQL, ModelView):
def get_amount(cls, requisitions, name):
total_amount = {}
# Sort cached first and re-instantiate to optimize cache management
requisitions = sorted(requisitions,
key=lambda r: r.state in cls._states_cached, reverse=True)
requisitions = cls.browse(requisitions)
# Browse separately not cached to limit number of lines read
cached, not_cached = [], []
for requisition in requisitions:
if requisition.state in cls._states_cached:
cached.append(requisition)
else:
not_cached.append(requisition)
for requisition in chain(cached, cls.browse(not_cached)):
if (requisition.state in cls._states_cached
and requisition.total_amount_cache is not None):
total_amount[requisition.id] = requisition.total_amount_cache
+7 -4
View File
@@ -587,11 +587,14 @@ class Sale(
compute_taxes = True
else:
compute_taxes = False
# Sort cached first and re-instanciate to optimize cache management
sales = sorted(sales, key=lambda s: s.state in cls._states_cached,
reverse=True)
sales = cls.browse(sales)
# Browse separately not cached to limit number of lines read
cached, not_cached = [], []
for sale in sales:
if sale.state in cls._states_cached:
cached.append(sale)
else:
not_cached.append(sale)
for sale in chain(cached, cls.browse(not_cached)):
if (sale.state in cls._states_cached
and sale.untaxed_amount_cache is not None
and sale.tax_amount_cache is not None