From cdfd196a0e2a8e6b8254ff31506469a6b60b62cd Mon Sep 17 00:00:00 2001 From: yosa-odoo Date: Wed, 17 Apr 2024 11:40:37 +0200 Subject: [PATCH] [FIX] hr_expense: display expenses amounts to be paid Steps to reproduce: - create-aprove-post an expense - Go to the accounting dashboard Issue: expenses' amount is 0 Cause: In `_count_results_and_sum_amounts`, since the expense.currency is the same as the company we don't get the correct result: https://github.com/odoo/odoo/blob/d29a622740f6c34d25c52add5367bfdf58bbaf49/addons/account/models/account_journal_dashboard.py#L641-L644 Solution: Get the right columns. We also change the domain to make sure that expenses partially paid are also displayed. Note: For the test we check that even partially paid expenses are displayed. In Master we want the residual amount to be displayed. In master: Use the amount_residual (discussed with po Laura) opw-3849036 closes odoo/odoo#162182 Signed-off-by: John Laterre (jol) --- .../models/account_journal_dashboard.py | 9 ++++-- addons/hr_expense/tests/__init__.py | 1 + .../tests/test_account_journal_dashboard.py | 28 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 addons/hr_expense/tests/test_account_journal_dashboard.py diff --git a/addons/hr_expense/models/account_journal_dashboard.py b/addons/hr_expense/models/account_journal_dashboard.py index 6c0046737fb..4a03fc6f87f 100644 --- a/addons/hr_expense/models/account_journal_dashboard.py +++ b/addons/hr_expense/models/account_journal_dashboard.py @@ -9,8 +9,12 @@ class AccountJournal(models.Model): def _prepare_expense_sheet_data_domain(self): return [ - ('state', '=', 'post'), ('journal_id', 'in', self.ids), + '|', + ('state', '=', 'post'), + '&', + ('state', '=', 'done'), + ('payment_state', '=', 'partial'), ] def _get_expense_to_pay_query(self): @@ -23,7 +27,8 @@ class AccountJournal(models.Model): return field_list = [ "hr_expense_sheet.journal_id", - "hr_expense_sheet.total_amount AS amount_total", + # todo master: "hr_expense_sheet.amount_residual AS amount_total_company", + "hr_expense_sheet.total_amount AS amount_total_company", "hr_expense_sheet.currency_id AS currency", ] query, params = sale_purchase_journals._get_expense_to_pay_query().select(*field_list) diff --git a/addons/hr_expense/tests/__init__.py b/addons/hr_expense/tests/__init__.py index 01f8b5dcd31..f6ef5cb0bde 100644 --- a/addons/hr_expense/tests/__init__.py +++ b/addons/hr_expense/tests/__init__.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import common +from . import test_account_journal_dashboard from . import test_expenses from . import test_expenses_access_rights from . import test_expenses_mail_import diff --git a/addons/hr_expense/tests/test_account_journal_dashboard.py b/addons/hr_expense/tests/test_account_journal_dashboard.py new file mode 100644 index 00000000000..683189b35e9 --- /dev/null +++ b/addons/hr_expense/tests/test_account_journal_dashboard.py @@ -0,0 +1,28 @@ +from odoo.tools.misc import format_amount + +from odoo.addons.hr_expense.tests.common import TestExpenseCommon +from odoo.tests import tagged + + +@tagged('post_install', '-at_install') +class TestAccountJournalDashboard(TestExpenseCommon): + + def test_expense_journal_numbers_and_sums(self): + journal = self.company_data['default_journal_purchase'] + company_currency = self.env.company.currency_id + expense_sheet = self.create_expense_report() + expense_sheet.action_submit_sheet() + expense_sheet.action_approve_expense_sheets() + expense_sheet.action_sheet_move_create() + + expense_sheet.flush_recordset() + dashboard_data = journal._get_journal_dashboard_data_batched()[journal.id] + self.assertEqual(dashboard_data['sum_expenses_to_pay'], format_amount(self.env, 1000, company_currency)) + + payment = self.get_new_payment(expense_sheet, 250.0) + expense_sheet.flush_recordset() + payment.flush_recordset() + dashboard_data = journal._get_journal_dashboard_data_batched()[journal.id] + # todo master: have 750 (residual amount will be used) + # we still want to assert a second time in order to make sure that partially paid expenses are displayed + self.assertEqual(dashboard_data['sum_expenses_to_pay'], format_amount(self.env, 1000, company_currency))