[FIX] hr_expense: apply old rates to total expenses

Issue:

- Expenses entered in currencies other than the company currency are
incorrectly calculated using today's exchange rate instead of the rate
applicable on the date the expense was made. This results in inaccurate
totals in the "totals to submit" section of the Expenses application.

Steps To Reproduce:

- Go to Expenses.
- See that the expenses to submit is $4,216.44.
- Create a new expense that is 999,999 EUR but $1.00 USD.
- See that the expenses to submit is $783395.96.

Solution:

- summing up total_amount_company directly instead of total_amount and
then converting to the company currency.

opw-3731445

closes odoo/odoo#156591

X-original-commit: 2c8b13e9270d2ccd6651e7618cbc363c1dd49f43
Signed-off-by: William André (wan) <wan@odoo.com>
Signed-off-by: Kawtar Drissi El Bouzaidi (kdeb) <kdeb@odoo.com>
This commit is contained in:
kdeb@odoo.com
2024-03-06 00:01:16 +00:00
parent 5af3cfc2b9
commit 6178be67c8
2 changed files with 22 additions and 5 deletions
+3 -5
View File
@@ -905,13 +905,11 @@ class HrExpense(models.Model):
('employee_id', 'in', self.env.user.employee_ids.ids),
'|', '&', ('payment_mode', 'in', ('own_account', 'company_account')), ('state', 'in', ('draft', 'reported', 'submitted')),
'&', ('payment_mode', '=', 'own_account'), ('state', '=', 'approved')
], ['state', 'currency_id'], ['total_amount_currency:sum'])
for state, currency, total_amount_sum in expenses:
], ['state'], ['total_amount:sum'])
for state, total_amount_sum in expenses:
if state in {'draft', 'reported'}: # Fuse the two states into only one "To Submit" state
state = 'to_submit'
currency = currency or target_currency
amount = currency._convert(total_amount_sum, target_currency, self.env.company, fields.Date.today())
expense_state[state]['amount'] += amount
expense_state[state]['amount'] += total_amount_sum
return expense_state
# ----------------------------------------
+19
View File
@@ -965,3 +965,22 @@ class TestExpenses(TestExpenseCommon):
{'name': 'test sheet no update', 'price_unit': 100.0, 'quantity': 1, 'total_amount': 100.0},
{'name': 'test sheet update', 'price_unit': 250.0, 'quantity': 1, 'total_amount': 250.0}, # no update
])
def test_foreign_currencies_total(self):
Expense = self.env['hr.expense'].with_user(self.expense_user_employee)
Expense.create([{
'name': 'Company expense',
'payment_mode': 'company_account',
'total_amount_currency': 1000.00,
'employee_id': self.expense_employee.id,
},
{
'name': 'Company expense 2',
'payment_mode': 'company_account',
'currency_id': self.currency_data['currency'].id,
'total_amount_currency': 1000.00,
'total_amount': 2000.00,
'employee_id': self.expense_employee.id,
}])
expense_state = Expense.get_expense_dashboard()
self.assertEqual(expense_state['to_submit']['amount'], 3000.00)