diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index fd4fdf57291..46adcb51559 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -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 diff --git a/addons/hr_expense/tests/test_expenses.py b/addons/hr_expense/tests/test_expenses.py index 11676c0cbf1..14affef3b22 100644 --- a/addons/hr_expense/tests/test_expenses.py +++ b/addons/hr_expense/tests/test_expenses.py @@ -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.