diff options
| author | Djamel (otd) <otd@odoo.com> | 2021-05-07 10:21:35 +0000 |
|---|---|---|
| committer | Djamel (otd) <otd@odoo.com> | 2021-05-17 12:19:19 +0000 |
| commit | 7f9cacd40d185bb7c943bd2adb7de1ef8a39c367 (patch) | |
| tree | 8e7565b910c21a038285128f8a2dc8df29ea8442 /addons/sale_timesheet | |
| parent | aa1e071191c90f8d67234aceb6adf009ccbcd2b1 (diff) | |
[FIX]sale_timesheet : Convert the project overview values to the current currency
Steps to reproduce the bug:
- Go to Project app
- See the overview of any project
- Select at the top right another company with a different currency. But keep the company assigned to the current project selected
Problem:
The new currency is changed in the project overview, but the values are not converted to this currency.
opw-2479364
closes odoo/odoo#70597
X-original-commit: eeeb18a28b0febd260c07069ce7a958b2e5038bb
Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
Diffstat (limited to 'addons/sale_timesheet')
| -rw-r--r-- | addons/sale_timesheet/models/project_overview.py | 34 | ||||
| -rw-r--r-- | addons/sale_timesheet/tests/test_project_overview.py | 13 |
2 files changed, 31 insertions, 16 deletions
diff --git a/addons/sale_timesheet/models/project_overview.py b/addons/sale_timesheet/models/project_overview.py index 1af36aac31f..8f2cd457dc6 100644 --- a/addons/sale_timesheet/models/project_overview.py +++ b/addons/sale_timesheet/models/project_overview.py @@ -11,6 +11,7 @@ from odoo.tools import float_round from odoo.tools.misc import get_lang from odoo.addons.web.controllers.main import clean_action +from datetime import date DEFAULT_MONTH_RANGE = 3 @@ -102,23 +103,26 @@ class Project(models.Model): # rates from non-invoiced timesheets that are linked to canceled so dashboard_values['rates']['canceled'] = float_round(100 * total_canceled_hours / (dashboard_total_hours or 1), precision_rounding=hour_rounding) - - other_revenues = self.env['account.analytic.line'].read_group([ - ('account_id', 'in', self.analytic_account_id.ids), - ('amount', '>=', 0), - ('project_id', '=', False)], ['amount'], [])[0].get('amount', 0) - + # profitability, using profitability SQL report - profit = dict.fromkeys(['invoiced', 'to_invoice', 'cost', 'expense_cost', 'expense_amount_untaxed_invoiced', 'total'], 0.0) - profitability_raw_data = self.env['project.profitability.report'].read_group([('project_id', 'in', self.ids)], ['project_id', 'amount_untaxed_to_invoice', 'amount_untaxed_invoiced', 'timesheet_cost', 'expense_cost', 'expense_amount_untaxed_invoiced'], ['project_id']) + field_map = { + 'amount_untaxed_invoiced': 'invoiced', + 'amount_untaxed_to_invoice': 'to_invoice', + 'timesheet_cost': 'cost', + 'expense_cost': 'expense_cost', + 'expense_amount_untaxed_invoiced': 'expense_amount_untaxed_invoiced', + 'other_revenues': 'other_revenues' + } + profit = dict.fromkeys(list(field_map.values()) + ['other_revenues', 'total'], 0.0) + profitability_raw_data = self.env['project.profitability.report'].read_group([('project_id', 'in', self.ids)], ['project_id'] + list(field_map), ['project_id']) for data in profitability_raw_data: - profit['invoiced'] += data.get('amount_untaxed_invoiced', 0.0) - profit['to_invoice'] += data.get('amount_untaxed_to_invoice', 0.0) - profit['cost'] += data.get('timesheet_cost', 0.0) - profit['expense_cost'] += data.get('expense_cost', 0.0) - profit['expense_amount_untaxed_invoiced'] += data.get('expense_amount_untaxed_invoiced', 0.0) - profit['other_revenues'] = other_revenues - data.get('amount_untaxed_invoiced', 0.0) if other_revenues else 0.0 - profit['other_revenues'] = profit['other_revenues'] - data.get('expense_amount_untaxed_invoiced', 0.0) if profit['other_revenues'] else 0.0 + company_id = self.env['project.project'].browse(data.get('project_id')[0]).company_id + from_currency = company_id.currency_id + for field in field_map: + value = data.get(field, 0.0) + if from_currency != currency: + value = from_currency._convert(value, currency, company_id, date.today()) + profit[field_map[field]] += value profit['total'] = sum([profit[item] for item in profit.keys()]) dashboard_values['profit'] = profit diff --git a/addons/sale_timesheet/tests/test_project_overview.py b/addons/sale_timesheet/tests/test_project_overview.py index 07ac601bfb0..8597c061c06 100644 --- a/addons/sale_timesheet/tests/test_project_overview.py +++ b/addons/sale_timesheet/tests/test_project_overview.py @@ -78,6 +78,16 @@ class TestSaleProject(TestReporting): 'product_uom_id': self.product_expense.uom_id.id, }) + other_revenues = self.env['account.analytic.line'].create({ + 'name': 'pther revenues on project_so', + 'account_id': project_so.analytic_account_id.id, + 'employee_id': self.employee_user.id, + 'unit_amount': 1, + 'amount': self.product_expense.list_price, + 'product_id': self.product_expense.id, + 'product_uom_id': self.product_expense.uom_id.id, + }) + view_id = self.env.ref('sale_timesheet.project_timesheet_action_client_timesheet_plan').id vals = self.env['project.project']._qweb_prepare_qcontext(view_id, [['id', '=', project_so.id]]) @@ -104,5 +114,6 @@ class TestSaleProject(TestReporting): self.assertEqual(float_compare(vals['dashboard']['profit']['invoiced'], project_invoiced, precision_rounding=rounding), 0, "The amount invoiced should be the one from the SO2 line, as we are in ordered quantity") self.assertEqual(float_compare(vals['dashboard']['profit']['cost'], project_timesheet_cost, precision_rounding=rounding), 0, "The amount cost should be the one from the SO2 line, as we are in ordered quantity") self.assertEqual(float_compare(vals['dashboard']['profit']['expense_cost'], expense.amount, precision_rounding=rounding), 0, "The amount expense-cost should be the one from the SO2 line, as we are in ordered quantity") - self.assertEqual(float_compare(vals['dashboard']['profit']['total'], project_invoiced + project_timesheet_cost + expense.amount, precision_rounding=rounding), 1, "The total amount should be the one from the SO2 line, as we are in ordered quantity") + self.assertEqual(float_compare(vals['dashboard']['profit']['other_revenues'], other_revenues.amount, precision_rounding=rounding), 0, "The amount of the other revenues should be equal to the created other_revenues account analytic line") + self.assertEqual(float_compare(vals['dashboard']['profit']['total'], project_invoiced + project_timesheet_cost + expense.amount + other_revenues.amount, precision_rounding=rounding), 0, "The total amount should be the sum of the SO2 line and the created other_revenues account analytic line") self.assertEqual(float_compare(vals['repartition_employee_max'], 11.0, precision_rounding=rounding), 0, "The amount of repartition-employee-max should be the one from SO2 line") |
