[IMP] estimate_workload: add time configuration

This commit is contained in:
Rémy Taymans 2023-01-23 21:29:06 +01:00
parent a2423ec4f8
commit 312e654e88
3 changed files with 47 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,7 +65,7 @@
<thead> <thead>
<tr> <tr>
<th>&nbsp;</th> <th>&nbsp;</th>
<th>Estimated time (min)</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 %}
@ -132,7 +132,11 @@
</td> </td>
<td>{{odoo_module.workload}}</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) %}
@ -146,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

@ -500,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())