From b73bb9445cabbcb7ee588d8603236ff25e79739a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 10 Mar 2014 20:22:42 +0100 Subject: [PATCH] Improve sale amount computation and remove total from list view issue3738 review4121003 --- sale.py | 20 +++++++++++++++----- view/sale_tree.xml | 1 - 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/sale.py b/sale.py index 70ecad78c6..41802220a0 100644 --- a/sale.py +++ b/sale.py @@ -488,21 +488,31 @@ class Sale(Workflow, ModelSQL, ModelView): tax_amount = {} total_amount = {} + if {'tax_amount', 'total_amount'} & set(names): + 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) for sale in sales: if (sale.state in cls._states_cached and sale.untaxed_amount_cache is not None and sale.tax_amount_cache is not None and sale.total_amount_cache is not None): untaxed_amount[sale.id] = sale.untaxed_amount_cache - tax_amount[sale.id] = sale.tax_amount_cache - total_amount[sale.id] = sale.total_amount_cache + if compute_taxes: + tax_amount[sale.id] = sale.tax_amount_cache + total_amount[sale.id] = sale.total_amount_cache else: untaxed_amount[sale.id] = sum( (line.amount for line in sale.lines if line.type == 'line'), _ZERO) - tax_amount[sale.id] = sale.get_tax_amount() - total_amount[sale.id] = ( - untaxed_amount[sale.id] + tax_amount[sale.id]) + if compute_taxes: + tax_amount[sale.id] = sale.get_tax_amount() + total_amount[sale.id] = ( + untaxed_amount[sale.id] + tax_amount[sale.id]) result = { 'untaxed_amount': untaxed_amount, diff --git a/view/sale_tree.xml b/view/sale_tree.xml index abdf83c6d6..e4b7fc16f4 100644 --- a/view/sale_tree.xml +++ b/view/sale_tree.xml @@ -8,7 +8,6 @@ this repository contains the full copyright notices and license terms. --> -