Skip to content

Commit

Permalink
[FIX] hr_expense: display expenses amounts to be paid
Browse files Browse the repository at this point in the history
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#162182

Signed-off-by: John Laterre (jol) <jol@odoo.com>
  • Loading branch information
yosa-odoo committed Apr 25, 2024
1 parent 5063f8f commit cdfd196
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
9 changes: 7 additions & 2 deletions addons/hr_expense/models/account_journal_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -23,7 +27,8 @@ def _fill_sale_purchase_dashboard_data(self, dashboard_data):
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)
Expand Down
1 change: 1 addition & 0 deletions addons/hr_expense/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions addons/hr_expense/tests/test_account_journal_dashboard.py
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit cdfd196

Please sign in to comment.