diff --git a/odoo_openupgrade_wizard/cli/cli_estimate_workload.py b/odoo_openupgrade_wizard/cli/cli_estimate_workload.py index c8507c7..8a2f93c 100644 --- a/odoo_openupgrade_wizard/cli/cli_estimate_workload.py +++ b/odoo_openupgrade_wizard/cli/cli_estimate_workload.py @@ -26,11 +26,40 @@ from odoo_openupgrade_wizard.tools.tools_system import ( " file will be used to define the list of module to analyse." "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 `HHHMM`, " + "*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 -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 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: module_list = extra_modules_list.split(",") else: @@ -51,4 +80,5 @@ def estimate_workload(ctx, analysis_file_path, extra_modules_list): ctx=ctx, analysis=analysis, current_date=datetime.now().strftime("%d/%m/%Y %H:%M:%S"), + time_to_text=time_to_text, ) diff --git a/odoo_openupgrade_wizard/templates/analysis.html.j2 b/odoo_openupgrade_wizard/templates/analysis.html.j2 index 6359a2f..1f2b837 100644 --- a/odoo_openupgrade_wizard/templates/analysis.html.j2 +++ b/odoo_openupgrade_wizard/templates/analysis.html.j2 @@ -65,6 +65,7 @@   + Total {%- for odoo_version in ctx.obj['config']['odoo_versions'] -%} {{ odoo_version }} {% endfor %} @@ -87,7 +88,7 @@ and odoo_module.module_type != 'odoo') %} {% set ns.current_module_type = odoo_module.module_type %} - + {{ ns.current_module_type}} @@ -102,7 +103,7 @@ {% if ns.current_repository %} - + {{ ns.current_repository}} @@ -130,6 +131,13 @@ {% endif %} + + + {% if odoo_module.workload %} + {{time_to_text(odoo_module.workload)}} + {% endif %} + + {% for version in odoo_module.analyse.all_versions %} {% set module_version = odoo_module.get_module_version(version) %} {% if module_version %} @@ -142,7 +150,7 @@ {% if workload %} - ({{ module_version.workload_hour_text()}}) + ({{time_to_text(workload)}}) {% endif %} {% if size_text %} diff --git a/odoo_openupgrade_wizard/tools/tools_odoo_module.py b/odoo_openupgrade_wizard/tools/tools_odoo_module.py index 15bd050..a07580a 100644 --- a/odoo_openupgrade_wizard/tools/tools_odoo_module.py +++ b/odoo_openupgrade_wizard/tools/tools_odoo_module.py @@ -328,6 +328,13 @@ class OdooModule(object): else: 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): res = self.module_versions.get(current_version, False) return res @@ -493,12 +500,20 @@ class OdooModuleVersion(object): self.python_code = 0 self.xml_code = 0 self.javascript_code = 0 - self.workload = 0 + self._workload = 0 self.analysis_file = False self.openupgrade_model_lines = 0 self.openupgrade_field_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): if self.odoo_module.module_type != "not_found": versions = list(self.odoo_module.module_versions.values())