Skip to content
Snippets Groups Projects
Commit d6fd7301 authored by Adrien Widart's avatar Adrien Widart
Browse files

[FIX] hr_expense: convert base amount if different currency


In a multi-currencies environment, if the user creates an expense with a
different currency than the company's, one of the associated account
move lines will have an incorrect base amount.

To reproduce the issue:
(Need account_accountant. Let USD be the company's currency)
1. In Settings, enable "Multi-Currencies"
2. Edit the currency rates:
    - EUR: 2
    - USD: 1
3. Create an expense:
    - Currency: EUR
    - Unit Price: 700
    - tax: 15%
4. Create Report, Submit, Approve, Post Journal Entries
5. Accounting > Reporting > Tax Report, This Financial Year
6. Audit of "Tax 15.00%"

Error: Base amount of the expense is $700, which is incorrect. It should
be either 700€ or $350

OPW-2613547

closes odoo/odoo#74963

X-original-commit: b57cdc9d
Signed-off-by: default avatarYannick Tivisse (yti) <yti@odoo.com>
parent e7748ca3
Branches
Tags
No related merge requests found
......@@ -460,6 +460,7 @@ Or send your receipts at <a href="mailto:%(email)s?subject=Lunch%%20with%%20cust
if tax['tax_repartition_line_id']:
rep_ln = self.env['account.tax.repartition.line'].browse(tax['tax_repartition_line_id'])
base_amount = self.env['account.move']._get_base_amount_to_display(tax['base'], rep_ln)
base_amount = expense.currency_id._convert(base_amount, company_currency, expense.company_id, account_date)
else:
base_amount = None
......
......@@ -140,6 +140,75 @@ class TestExpenses(TestExpenseCommon):
},
])
def test_account_entry_multi_currency(self):
""" Checking accounting move entries and analytic entries when submitting expense. With
multi-currency. And taxes. """
# Clean-up the rates
self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.env.ref('base.USD').id, self.env.company.id])
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'currency_id': self.env.ref('base.EUR').id,
'company_id': self.env.company.id,
'rate': 2.0,
'name': '2010-01-01',
})
expense = self.env['hr.expense.sheet'].create({
'name': 'Expense for Dick Tracy',
'employee_id': self.expense_employee.id,
})
tax = self.env['account.tax'].create({
'name': 'Expense 10%',
'amount': 10,
'amount_type': 'percent',
'type_tax_use': 'purchase',
'price_include': True,
})
expense_line = self.env['hr.expense'].create({
'name': 'Choucroute Saucisse',
'employee_id': self.expense_employee.id,
'product_id': self.product_a.id,
'unit_amount': 700.00,
'tax_ids': [(6, 0, tax.ids)],
'sheet_id': expense.id,
'analytic_account_id': self.analytic_account_1.id,
'currency_id': self.env.ref('base.EUR').id,
})
# State should default to draft
self.assertEqual(expense.state, 'draft', 'Expense should be created in Draft state')
# Submitted to Manager
expense.action_submit_sheet()
self.assertEqual(expense.state, 'submit', 'Expense is not in Reported state')
# Approve
expense.approve_expense_sheets()
self.assertEqual(expense.state, 'approve', 'Expense is not in Approved state')
# Create Expense Entries
expense.action_sheet_move_create()
self.assertEqual(expense.state, 'post', 'Expense is not in Waiting Payment state')
self.assertTrue(expense.account_move_id.id, 'Expense Journal Entry is not created')
# Should get this result [(0.0, 350.0, -700.0), (318.18, 0.0, 636.36), (31.82, 0.0, 63.64)]
for line in expense.account_move_id.line_ids:
if line.credit:
self.assertAlmostEqual(line.credit, 350.0)
self.assertAlmostEqual(line.amount_currency, -700.0)
self.assertEqual(len(line.analytic_line_ids), 0, "The credit move line should not have analytic lines")
self.assertFalse(line.product_id, "Product of credit move line should be false")
else:
if not line.tax_line_id == tax:
self.assertAlmostEqual(line.debit, 318.18)
self.assertAlmostEqual(line.amount_currency, 636.36)
self.assertEqual(len(line.analytic_line_ids), 1, "The debit move line should have 1 analytic lines")
self.assertEqual(line.product_id, self.product_a, "Product of debit move line should be the one from the expense")
else:
self.assertEqual(line.tax_base_amount, 318.18)
self.assertAlmostEqual(line.debit, 31.82)
self.assertAlmostEqual(line.amount_currency, 63.64)
self.assertEqual(len(line.analytic_line_ids), 0, "The tax move line should not have analytic lines")
self.assertFalse(line.product_id, "Product of tax move line should be false")
def test_expenses_with_tax_and_lockdate(self):
''' Test creating a journal entry for multiple expenses using taxes. A lock date is set in order to trigger
the recomputation of the taxes base amount.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment