Merge branch 'imp-estimate_workload-report' into 'main'

[IMP] estimate-workload: add total column in report

Closes #29

See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!27
This commit is contained in:
LE GAL SYLVAIN 2023-02-22 10:47:23 +00:00
commit 9a212eeeb5
3 changed files with 58 additions and 5 deletions

View File

@ -26,11 +26,40 @@ from odoo_openupgrade_wizard.tools.tools_system import (
" file will be used to define the list of module to analyse." " file will be used to define the list of module to analyse."
"Ex: 'account,product,base'", "Ex: 'account,product,base'",
) )
@click.option(
"--time-unit",
type=click.Choice(["hour", "minute", "separator"]),
default="separator",
show_default=True,
help="Select unit to display time in the report. "
"*separator* display time as `HHH<sep>MM`, "
"*hour* display time as decimal hour, "
"*min* display time as minute (rounded).",
)
@click.option(
"--time-separator",
default=":",
help="Specify time separator, if time-unit is separator. "
"Default to `:` (it will produce time like this HHH:MM).",
)
@click.pass_context @click.pass_context
def estimate_workload(ctx, analysis_file_path, extra_modules_list): def estimate_workload(
ctx, analysis_file_path, extra_modules_list, time_unit, time_separator
):
# Analyse # Analyse
analysis = Analysis(ctx) analysis = Analysis(ctx)
def time_to_text(minutes):
"""Return a text representation for minutes"""
hours, mins = divmod(minutes, 60)
if time_unit == "hour":
result = str(hours)
elif time_unit == "minute":
result = str(minutes)
else:
result = "{}{}{:02d}".format(hours, time_separator, mins)
return result
if extra_modules_list: if extra_modules_list:
module_list = extra_modules_list.split(",") module_list = extra_modules_list.split(",")
else: else:
@ -51,4 +80,5 @@ def estimate_workload(ctx, analysis_file_path, extra_modules_list):
ctx=ctx, ctx=ctx,
analysis=analysis, analysis=analysis,
current_date=datetime.now().strftime("%d/%m/%Y %H:%M:%S"), current_date=datetime.now().strftime("%d/%m/%Y %H:%M:%S"),
time_to_text=time_to_text,
) )

View File

@ -65,6 +65,7 @@
<thead> <thead>
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>Total</th>
{%- for odoo_version in ctx.obj['config']['odoo_versions'] -%} {%- for odoo_version in ctx.obj['config']['odoo_versions'] -%}
<th>{{ odoo_version }}</th> <th>{{ odoo_version }}</th>
{% endfor %} {% endfor %}
@ -87,7 +88,7 @@
and odoo_module.module_type != 'odoo') %} and odoo_module.module_type != 'odoo') %}
{% set ns.current_module_type = odoo_module.module_type %} {% set ns.current_module_type = odoo_module.module_type %}
<tr> <tr>
<th colspan="{{1 + ctx.obj['config']['odoo_versions']|length}}"> <th colspan="{{2 + ctx.obj['config']['odoo_versions']|length}}">
{{ ns.current_module_type}} {{ ns.current_module_type}}
</th> </th>
<tr> <tr>
@ -102,7 +103,7 @@
{% if ns.current_repository %} {% if ns.current_repository %}
<tr> <tr>
<th colspan="{{1 + ctx.obj['config']['odoo_versions']|length}}"> <th colspan="{{2 + ctx.obj['config']['odoo_versions']|length}}">
{{ ns.current_repository}} {{ ns.current_repository}}
</th> </th>
<tr> <tr>
@ -130,6 +131,13 @@
{% endif %} {% endif %}
</td> </td>
<td>
{% if odoo_module.workload %}
{{time_to_text(odoo_module.workload)}}
{% endif %}
</td>
{% for version in odoo_module.analyse.all_versions %} {% for version in odoo_module.analyse.all_versions %}
{% set module_version = odoo_module.get_module_version(version) %} {% set module_version = odoo_module.get_module_version(version) %}
{% if module_version %} {% if module_version %}
@ -142,7 +150,7 @@
{% if workload %} {% if workload %}
<span style="background-color:lightblue;"> <span style="background-color:lightblue;">
({{ module_version.workload_hour_text()}}) ({{time_to_text(workload)}})
</span> </span>
{% endif %} {% endif %}
{% if size_text %} {% if size_text %}

View File

@ -328,6 +328,13 @@ class OdooModule(object):
else: else:
self.module_type = "custom" self.module_type = "custom"
@property
def workload(self):
return sum(
round(module_version.workload)
for _, module_version in self.module_versions.items()
)
def get_module_version(self, current_version): def get_module_version(self, current_version):
res = self.module_versions.get(current_version, False) res = self.module_versions.get(current_version, False)
return res return res
@ -493,12 +500,20 @@ class OdooModuleVersion(object):
self.python_code = 0 self.python_code = 0
self.xml_code = 0 self.xml_code = 0
self.javascript_code = 0 self.javascript_code = 0
self.workload = 0 self._workload = 0
self.analysis_file = False self.analysis_file = False
self.openupgrade_model_lines = 0 self.openupgrade_model_lines = 0
self.openupgrade_field_lines = 0 self.openupgrade_field_lines = 0
self.openupgrade_xml_lines = 0 self.openupgrade_xml_lines = 0
@property
def workload(self):
return int(round(self._workload))
@workload.setter
def workload(self, value):
self._workload = int(round(value))
def get_last_existing_version(self): def get_last_existing_version(self):
if self.odoo_module.module_type != "not_found": if self.odoo_module.module_type != "not_found":
versions = list(self.odoo_module.module_versions.values()) versions = list(self.odoo_module.module_versions.values())