From 3f098a782f5ca80e36b2d69447ad01abef25acef Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Wed, 26 Jan 2022 18:00:40 +0100 Subject: [PATCH] [IMP] sale_timesheet: remove the profitability report --- addons/sale_timesheet/models/project.py | 32 ------------------- .../sale_timesheet/models/project_update.py | 17 ++++++---- .../tests/test_project_update.py | 6 ++-- .../views/project_update_templates.xml | 2 +- 4 files changed, 16 insertions(+), 41 deletions(-) diff --git a/addons/sale_timesheet/models/project.py b/addons/sale_timesheet/models/project.py index 18e54988a85..f2feddc0ae4 100644 --- a/addons/sale_timesheet/models/project.py +++ b/addons/sale_timesheet/models/project.py @@ -494,38 +494,6 @@ class Project(models.Model): ) return profitability_items - def _get_profitability_common(self): - # FIXME: used in project update model - self.ensure_one() - result = { - 'costs': 0.0, - 'margin': 0.0, - 'revenues': 0.0 - } - - profitability = self.env['project.profitability.report']._read_group( - [('project_id', '=', self.id)], - ['project_id', - 'amount_untaxed_to_invoice', - 'amount_untaxed_invoiced', - 'expense_amount_untaxed_to_invoice', - 'expense_amount_untaxed_invoiced', - 'other_revenues', - 'expense_cost', - 'timesheet_cost', - 'margin'], - ['project_id'], limit=1) - if profitability: - profitability = profitability[0] - result.update({ - 'costs': profitability['timesheet_cost'] + profitability['expense_cost'], - 'margin': profitability['margin'], - 'revenues': (profitability['amount_untaxed_invoiced'] + profitability['amount_untaxed_to_invoice'] + - profitability['expense_amount_untaxed_invoiced'] + profitability['expense_amount_untaxed_to_invoice'] + - profitability['other_revenues']), - }) - return result - def _get_service_policy_to_invoice_type(self): return { **super()._get_service_policy_to_invoice_type(), diff --git a/addons/sale_timesheet/models/project_update.py b/addons/sale_timesheet/models/project_update.py index 902b823a47a..9b0753191bb 100644 --- a/addons/sale_timesheet/models/project_update.py +++ b/addons/sale_timesheet/models/project_update.py @@ -69,14 +69,19 @@ class ProjectUpdate(models.Model): costs_revenues = project.analytic_account_id and project.allow_billable if not (self.user_has_groups('project.group_project_manager') and costs_revenues): return {} - profitability = project._get_profitability_common() + profitability_items = project._get_profitability_items(False) + costs = sum(profitability_items['costs']['total'].values()) + revenues = sum(profitability_items['revenues']['total'].values()) + margin = revenues + costs return { 'analytic_account_id': project.analytic_account_id, - 'costs': format_amount(self.env, -profitability['costs'], self.env.company.currency_id), - 'revenues': format_amount(self.env, profitability['revenues'], self.env.company.currency_id), - 'margin': profitability['margin'], - 'margin_formatted': format_amount(self.env, profitability['margin'], self.env.company.currency_id), + 'costs': costs, + 'costs_formatted': format_amount(self.env, -costs, project.currency_id), + 'revenues': revenues, + 'revenues_formatted': format_amount(self.env, revenues, project.currency_id), + 'margin': margin, + 'margin_formatted': format_amount(self.env, margin, project.currency_id), 'margin_percentage': formatLang(self.env, - not float_utils.float_is_zero(profitability['costs'], precision_digits=2) and -(profitability['margin'] / profitability['costs']) * 100 or 0.0, + not float_utils.float_is_zero(costs, precision_digits=2) and (margin / -costs) * 100 or 0.0, digits=0), } diff --git a/addons/sale_timesheet/tests/test_project_update.py b/addons/sale_timesheet/tests/test_project_update.py index 0b79256a552..4b117d68812 100644 --- a/addons/sale_timesheet/tests/test_project_update.py +++ b/addons/sale_timesheet/tests/test_project_update.py @@ -11,8 +11,10 @@ class TestProjectUpdateSaleTimesheet(TestProjectUpdate): def test_project_update_description_profitability(self): self.project_pigs.allow_billable = True template_values = self.env['project.update']._get_template_values(self.project_pigs) - self.assertEqual(template_values['profitability']['costs'], "$\xa00.00", "Project costs used in the template should be well defined") - self.assertEqual(template_values['profitability']['revenues'], "$\xa00.00", "Project revenues used in the template should be well defined") + self.assertEqual(template_values['profitability']['costs'], 0.0, "Project costs used in the template should be well defined") + self.assertEqual(template_values['profitability']['costs_formatted'], "$\xa00.00", "Project costs used in the template should be well defined") + self.assertEqual(template_values['profitability']['revenues'], 0.0, "Project revenues used in the template should be well defined") + self.assertEqual(template_values['profitability']['revenues_formatted'], "$\xa00.00", "Project revenues used in the template should be well defined") self.assertEqual(template_values['profitability']['margin'], 0, "Margin used in the template should be well defined") self.assertEqual(template_values['profitability']['margin_formatted'], "$\xa00.00", "Margin formatted used in the template should be well defined") self.assertEqual(template_values['profitability']['margin_percentage'], "0", "Margin percentage used in the template should be well defined") diff --git a/addons/sale_timesheet/views/project_update_templates.xml b/addons/sale_timesheet/views/project_update_templates.xml index 2a623101631..d1396388a78 100644 --- a/addons/sale_timesheet/views/project_update_templates.xml +++ b/addons/sale_timesheet/views/project_update_templates.xml @@ -35,7 +35,7 @@

Profitability

-The cost of the project is now at , for a revenue of , leading to a +The cost of the project is now at , for a revenue of , leading to a