From 8e2d7c2e3c4e1f2e62a3f52f4152f21030946265 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 21 Sep 2017 16:51:13 +0200 Subject: [PATCH] [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. --- addons/hr_expense/models/hr_expense.py | 11 +++++--- .../report/report_expense_sheet.xml | 26 +++++++++---------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index 12a6eabf0cb..7af883a563e 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -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] diff --git a/addons/hr_expense/report/report_expense_sheet.xml b/addons/hr_expense/report/report_expense_sheet.xml index 55d5974d3e7..918f5d96280 100644 --- a/addons/hr_expense/report/report_expense_sheet.xml +++ b/addons/hr_expense/report/report_expense_sheet.xml @@ -77,21 +77,19 @@ - -
-
- - - - - -
Total - -
-
+
+
+ + + + + +
Total + +
- +

Certified honest and conform,
(Date and signature).