[FIX] hr_expense: force company currency on company payment

Activate Multicurrency (USD company curr, EUR foreign currency, 1 EUR = 2 USD)
Have a Bank account in both currencies.
Create an expense of 100€, paid by company
Create report, set EUR journal as Bank Journal
Send To manager > Approve > Post Journal Entries
Open created payment

Issue:
- Payment amount is 200€
- In journal items, amount_currency and balance is 200$

Do the same with "Paid by employee".
Open the vendor bill

Issue:
- Invoice lines are expressed in the wrong currency

opw-3269009

closes odoo/odoo#119490

X-original-commit: 5eab4469d87a4d1ca80916ca5790691ffed68e38
Signed-off-by: Laurent Smet <las@odoo.com>
Signed-off-by: Grazioso Andrea (agr) <agr@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2023-04-24 23:49:12 +02:00
parent 7c94decb77
commit ff35bf57a7
2 changed files with 75 additions and 2 deletions
+2 -2
View File
@@ -586,7 +586,6 @@ class HrExpense(models.Model):
'expense_id': self.id,
'partner_id': False if self.payment_mode == 'company_account' else self.employee_id.sudo().address_home_id.commercial_partner_id.id,
'tax_ids': [Command.set(self.tax_ids.ids)],
'currency_id': self.company_currency_id.id,
}
@api.model
@@ -1249,7 +1248,7 @@ class HrExpenseSheet(models.Model):
company_account_sheets = self - own_account_sheets
moves = self.env['account.move'].create([sheet._prepare_bill_vals() for sheet in own_account_sheets])
payments = self.env['account.payment'].create([sheet._prepare_payment_vals() for sheet in company_account_sheets])
payments = self.env['account.payment'].with_context(default_currency_id=self.company_id.currency_id.id).create([sheet._prepare_payment_vals() for sheet in company_account_sheets])
moves |= payments.move_id
moves.action_post()
@@ -1300,6 +1299,7 @@ class HrExpenseSheet(models.Model):
'invoice_date': self.accounting_date or fields.Date.context_today(self), # expense payment behave as bills
'ref': self.name,
'expense_sheet_id': [Command.set(self.ids)],
'currency_id': self.company_id.currency_id.id,
'line_ids':[
Command.create(expense._prepare_move_line_vals())
for expense in self.expense_line_ids
+73
View File
@@ -387,6 +387,79 @@ class TestExpenses(TestExpenseCommon):
'amount_total': 350.0,
})
def test_account_entry_multi_currency_company_account(self):
""" Checking accounting payment entry when payment_mode is 'Company'. With multi-currency."""
expense = self.env['hr.expense'].create({
'name': 'Company expense',
'date': '2022-11-17',
'total_amount': 1000.0,
'payment_mode': 'company_account',
'employee_id': self.expense_employee.id,
'product_id': self.product_a.id,
'currency_id': self.currency_data['currency'].id, # rate is 1:2
})
foreign_bank_journal = self.company_data['default_journal_bank'].copy()
foreign_bank_journal.currency_id = self.currency_data['currency'].id
foreign_bank_journal_account = foreign_bank_journal.default_account_id.copy()
foreign_bank_journal_account.currency_id = self.currency_data['currency'].id
foreign_bank_journal.default_account_id = foreign_bank_journal_account.id
expense_sheet = self.env['hr.expense.sheet'].create({
'name': "test_account_entry_multi_currency_own_account",
'employee_id': self.expense_employee.id,
'accounting_date': '2020-01-01',
'payment_method_line_id': foreign_bank_journal.outbound_payment_method_line_ids[0].id,
'expense_line_ids': [Command.set(expense.ids)],
})
expense_sheet.action_submit_sheet()
expense_sheet.action_approve_expense_sheets()
expense_sheet.action_sheet_move_create()
self.assertRecordValues(expense_sheet.account_move_id.payment_id, [{
'currency_id': self.env.company.currency_id.id,
}])
self.assertRecordValues(expense_sheet.account_move_id.line_ids, [
{'currency_id': self.env.company.currency_id.id},
{'currency_id': self.env.company.currency_id.id},
{'currency_id': self.env.company.currency_id.id},
])
def test_account_entry_multi_currency_own_account(self):
""" Checking accounting payment entry when payment_mode is 'Company'. With multi-currency."""
expense = self.env['hr.expense'].create({
'name': 'Company expense',
'date': '2022-11-17',
'total_amount': 1000.0,
'payment_mode': 'own_account',
'employee_id': self.expense_employee.id,
'product_id': self.product_a.id,
'currency_id': self.currency_data['currency'].id, # rate is 1:2
})
foreign_sale_journal = self.company_data['default_journal_sale'].copy()
foreign_sale_journal.currency_id = self.currency_data['currency'].id
expense_sheet = self.env['hr.expense.sheet'].create({
'name': "test_account_entry_multi_currency_own_account",
'employee_id': self.expense_employee.id,
'accounting_date': '2020-01-01',
'journal_id': foreign_sale_journal.id,
'expense_line_ids': [Command.set(expense.ids)],
})
expense_sheet.action_submit_sheet()
expense_sheet.action_approve_expense_sheets()
expense_sheet.action_sheet_move_create()
self.assertRecordValues(expense_sheet.account_move_id, [{
'currency_id': self.env.company.currency_id.id,
}])
self.assertRecordValues(expense_sheet.account_move_id.line_ids, [
{'currency_id': self.env.company.currency_id.id},
{'currency_id': self.env.company.currency_id.id},
{'currency_id': self.env.company.currency_id.id},
])
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.