[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:
@@ -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')) < 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>
|
||||
|
||||
Reference in New Issue
Block a user