Always clear cached amount before storing it
This is safer as if for some reason the cache is filled with wrong data, the values will be fixed instead of keep propagating it.
This commit is contained in:
@@ -1762,11 +1762,13 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin, InvoiceReportMixin):
|
||||
|
||||
@classmethod
|
||||
def _store_cache(cls, invoices):
|
||||
invoices = list(invoices)
|
||||
cls.write(invoices, {
|
||||
'untaxed_amount_cache': None,
|
||||
'tax_amount_cache': None,
|
||||
'total_amount_cache': None,
|
||||
})
|
||||
for invoice in invoices:
|
||||
if (invoice.untaxed_amount == invoice.untaxed_amount_cache
|
||||
and invoice.tax_amount == invoice.tax_amount_cache
|
||||
and invoice.total_amount == invoice.total_amount_cache):
|
||||
continue
|
||||
invoice.untaxed_amount_cache = invoice.untaxed_amount
|
||||
invoice.tax_amount_cache = invoice.tax_amount
|
||||
invoice.total_amount_cache = invoice.total_amount
|
||||
|
||||
@@ -766,6 +766,12 @@ class Purchase(
|
||||
|
||||
@classmethod
|
||||
def store_cache(cls, purchases):
|
||||
purchases = list(purchases)
|
||||
cls.write(purchases, {
|
||||
'untaxed_amount_cache': None,
|
||||
'tax_amount_cache': None,
|
||||
'total_amount_cache': None,
|
||||
})
|
||||
for purchase in purchases:
|
||||
purchase.untaxed_amount_cache = purchase.untaxed_amount
|
||||
purchase.tax_amount_cache = purchase.tax_amount
|
||||
|
||||
@@ -119,10 +119,6 @@ class Amendment(Workflow, ModelSQL, ModelView):
|
||||
line.apply(purchase)
|
||||
# Force saved lines
|
||||
purchase.lines = purchase.lines
|
||||
# Force recompute cache
|
||||
purchase.untaxed_amount_cache = None
|
||||
purchase.tax_amount_cache = None
|
||||
purchase.total_amount_cache = None
|
||||
|
||||
Purchase.save(purchases)
|
||||
Purchase.store_cache(purchases)
|
||||
|
||||
@@ -247,6 +247,10 @@ class PurchaseRequisition(Workflow, ModelSQL, ModelView):
|
||||
|
||||
@classmethod
|
||||
def store_cache(cls, requisitions):
|
||||
requisitions = list(requisitions)
|
||||
cls.write(requisitions, {
|
||||
'total_amount_cache': None,
|
||||
})
|
||||
for requisition in requisitions:
|
||||
requisition.total_amount_cache = requisition.total_amount
|
||||
cls.save(requisitions)
|
||||
|
||||
@@ -866,6 +866,12 @@ class Sale(
|
||||
|
||||
@classmethod
|
||||
def store_cache(cls, sales):
|
||||
sales = list(sales)
|
||||
cls.write(sales, {
|
||||
'untaxed_amount_cache': None,
|
||||
'tax_amount_cache': None,
|
||||
'total_amount_cache': None,
|
||||
})
|
||||
for sale in sales:
|
||||
sale.untaxed_amount_cache = sale.untaxed_amount
|
||||
sale.tax_amount_cache = sale.tax_amount
|
||||
|
||||
@@ -119,10 +119,6 @@ class Amendment(Workflow, ModelSQL, ModelView):
|
||||
line.apply(sale)
|
||||
# Force saved lines
|
||||
sale.lines = sale.lines
|
||||
# Force recompute cache
|
||||
sale.untaxed_amount_cache = None
|
||||
sale.tax_amount_cache = None
|
||||
sale.total_amount_cache = None
|
||||
|
||||
Sale.save(sales)
|
||||
Sale.store_cache(sales)
|
||||
|
||||
Reference in New Issue
Block a user