[IMP] sale_timesheet: remove the profitability report

This commit is contained in:
Xavier BOL (xbo)
2022-04-01 15:33:00 +02:00
committed by Laurent Stukkens (LTU)
parent 2562801d63
commit 3f098a782f
4 changed files with 16 additions and 41 deletions
-32
View File
@@ -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(),
+11 -6
View File
@@ -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),
}
@@ -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")
@@ -35,7 +35,7 @@
<div name="profitability" t-if="show_profitability">
<t t-if="project.analytic_account_id and project.allow_billable and user.has_group('project.group_project_manager')" name="costs">
<h3 style="font-weight: bolder"><u>Profitability</u></h3>
The cost of the project is now at <t t-esc="profitability['costs']"/>, for a revenue of <t t-esc="profitability['revenues']"/>, leading to a
The cost of the project is now at <t t-esc="profitability['costs_formatted']"/>, for a revenue of <t t-esc="profitability['revenues_formatted']"/>, leading to a
<span>
<font t-if="profitability['margin'] &gt; 0" style="color: rgb(0, 128, 0)">
<b><t t-esc="profitability['margin_formatted']"/></b>