[FIX] hr_expense: Make expense sheet report multi currency coherent

Purpose
=======

Currently, if we want to print an expense report that has several currencies in its expense lines, the total amount is hidden on the report. Otherwise, it is simply summed.

That could lead to confusing uses cases. Example.
1 expense line of 92 dollars.
1 expense report expressed in euros.

In the report we will have
- 1 line of 92 dollars
- Total amount: 92 euros

Which is obviously wrong.

Specification
=============

Always display the amount + Compute the amount in the expense report currency, by converting the amount with the rate at the day the expense has been made.
This commit is contained in:
Yannick Tivisse
2017-09-21 16:51:13 +02:00
parent e245135421
commit 8e2d7c2e3c
2 changed files with 19 additions and 18 deletions
+7 -4
View File
@@ -486,10 +486,13 @@ class HrExpenseSheet(models.Model):
@api.one
@api.depends('expense_line_ids', 'expense_line_ids.total_amount', 'expense_line_ids.currency_id')
def _compute_amount(self):
if len(self.expense_line_ids.mapped('currency_id')) < 2:
self.total_amount = sum(self.expense_line_ids.mapped('total_amount'))
else:
self.total_amount = 0.0
total_amount = 0.0
for expense in self.expense_line_ids:
total_amount += expense.currency_id.with_context(
date=expense.date,
company_id=expense.company_id.id
).compute(expense.total_amount, self.currency_id)
self.total_amount = total_amount
# FIXME: A 4 command is missing to explicitly declare the one2many relation
# between the sheet and the lines when using 'default_expense_line_ids':[ids]
@@ -77,21 +77,19 @@
</tbody>
</table>
<t t-if="len(o.mapped('expense_line_ids').mapped('currency_id')) &lt; 2">
<div class="row">
<div class="col-xs-4 pull-right">
<table class="table table-condensed">
<tr class="border-black">
<td><strong>Total</strong></td>
<td class="text-right">
<span t-field="o.total_amount"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</tr>
</table>
</div>
<div class="row">
<div class="col-xs-4 pull-right">
<table class="table table-condensed">
<tr class="border-black">
<td><strong>Total</strong></td>
<td class="text-right">
<span t-field="o.total_amount"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'/>
</td>
</tr>
</table>
</div>
</t>
</div>
<p>Certified honest and conform,<br/>(Date and signature).<br/><br/></p>
</div>
</t>