Improve sale amount computation and remove total from list view
issue3738 review4121003
This commit is contained in:
1 parent
087a4d55b5
commit
b73bb9445c
2 files changed
+15
-6
No files matched your search
@@ -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,
|
||||
|
||||
@@ -8,7 +8,6 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="warehouse"/>
|
||||
<field name="currency"/>
|
||||
<field name="untaxed_amount"/>
|
||||
<field name="total_amount"/>
|
||||
<field name="state"/>
|
||||
<field name="invoice_state"/>
|
||||
<field name="shipment_state"/>
|
||||
|
||||
Reference in new issue
Block a user