diff --git a/project_forecast_line_bokeh_chart/README.rst b/project_forecast_line_bokeh_chart/README.rst new file mode 100644 index 0000000000..4dc3fe8053 --- /dev/null +++ b/project_forecast_line_bokeh_chart/README.rst @@ -0,0 +1,90 @@ +================================== +Project Forecast Lines Bokeh Chart +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:c3531fb0c734d3d8fc5b939e61ebcdb3578fb6f36ffa26ee23a2a21c90907610 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png + :target: https://odoo-community.org/page/development-status + :alt: Alpha +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fproject-lightgray.png?logo=github + :target: https://github.com/OCA/project/tree/14.0/project_forecast_line_bokeh_chart + :alt: OCA/project +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/project-14-0/project-14-0-project_forecast_line_bokeh_chart + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/project&target_branch=14.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module improves the reports of project_forecast_line by using the bokeh widget available in OCA/web. + +.. IMPORTANT:: + This is an alpha version, the data model and design can change at any time without warning. + Only for development or testing purpose, do not use in production. + `More details on development status `_ + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Camptocamp SA + +Contributors +~~~~~~~~~~~~ + +* Alexandre Fayolle +* Nikos Tsirintanis + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-ntsirintanis| image:: https://github.com/ntsirintanis.png?size=40px + :target: https://github.com/ntsirintanis + :alt: ntsirintanis + +Current `maintainer `__: + +|maintainer-ntsirintanis| + +This module is part of the `OCA/project `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/project_forecast_line_bokeh_chart/__init__.py b/project_forecast_line_bokeh_chart/__init__.py new file mode 100644 index 0000000000..bf588bc8b8 --- /dev/null +++ b/project_forecast_line_bokeh_chart/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import report diff --git a/project_forecast_line_bokeh_chart/__manifest__.py b/project_forecast_line_bokeh_chart/__manifest__.py new file mode 100644 index 0000000000..e350cb4085 --- /dev/null +++ b/project_forecast_line_bokeh_chart/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Project Forecast Lines Bokeh Chart", + "summary": "Project Forecast Lines Bokeh Chart", + "version": "14.0.1.0.1", + "author": "Camptocamp SA, Odoo Community Association (OCA)", + "maintainers": ["ntsirintanis"], + "license": "AGPL-3", + "category": "Project", + "website": "https://github.com/OCA/project", + "depends": ["project_forecast_line", "web_widget_bokeh_chart"], + "data": [ + "security/ir.model.access.csv", + "report/forecast_line_reporting_views.xml", + ], + "development_status": "Alpha", + "installable": True, +} diff --git a/project_forecast_line_bokeh_chart/i18n/fr.po b/project_forecast_line_bokeh_chart/i18n/fr.po new file mode 100644 index 0000000000..f3ef41984d --- /dev/null +++ b/project_forecast_line_bokeh_chart/i18n/fr.po @@ -0,0 +1,181 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_forecast_line_bokeh_chart +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-08-09 13:06+0000\n" +"PO-Revision-Date: 2021-09-10 14:59+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Available" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__bokeh_chart +msgid "Bokeh Chart" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__create_uid +msgid "Created by" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__create_date +msgid "Created on" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__date_from +msgid "Date From" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields.selection,name:project_forecast_line_bokeh_chart.selection__forecast_line_reporting__granularity__day +msgid "Day" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__employee_ids +msgid "Employee" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.actions.act_window,name:project_forecast_line_bokeh_chart.action_forecast_lines_reporting +#: model:ir.ui.menu,name:project_forecast_line_bokeh_chart.menu_forecast_line_reporting +#: model_terms:ir.ui.view,arch_db:project_forecast_line_bokeh_chart.view_forecast_line_reporting +msgid "Forecast Reporting" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model,name:project_forecast_line_bokeh_chart.model_forecast_line_reporting +msgid "Forecast reporting wizard" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__granularity +msgid "Granularity" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__id +msgid "ID" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__write_date +#, fuzzy +msgid "Last Updated on" +msgstr "Dernière modification le" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields.selection,name:project_forecast_line_bokeh_chart.selection__forecast_line_reporting__granularity__month +msgid "Month" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__nb_months +msgid "Nb Months" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Not assigned to an employee" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Nothing to plot. Select some employees" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Overload" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__project_ids +msgid "Project" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,help:project_forecast_line_bokeh_chart.field_forecast_line_reporting__project_ids +msgid "" +"Setting this will automatically add all employees assigned to tasks on the " +"project" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields.selection,name:project_forecast_line_bokeh_chart.selection__forecast_line_reporting__granularity__week +msgid "Week" +msgstr "" + +#, fuzzy +#~ msgid "Sale line" +#~ msgstr "Bon de commande" + +#~ msgid "Sales Order" +#~ msgstr "Bon de commande" + +#, fuzzy +#~ msgid "Sales Order Line" +#~ msgstr "Bon de commande" + +#~ msgid "Indicate if a signed contract has been received for this SO" +#~ msgstr "Indique si un contrat signé a été reçu pour cette commande" + +#~ msgid "Log reception of signed contract" +#~ msgstr "Enregistrer la réception d'un contrat signé" + +#~ msgid "Missing contract" +#~ msgstr "Contrat manquant" + +#~ msgid "Record when the SO has (most recently) been marked as signed " +#~ msgstr "" +#~ "Enregistre quand la commande a été marquée comme signée (le plus " +#~ "récemment)" + +#~ msgid "Signed Date" +#~ msgstr "Date de signature" + +#~ msgid "Signed Status" +#~ msgstr "Statut signature" + +#~ msgid "" +#~ "You are not allowed to change the signed status of Sales Orders.\n" +#~ "Only members of the 'Log reception of signed contract' group can." +#~ msgstr "" +#~ "Vous n'êtes pas autorisé à changer le statut de signature des commandes " +#~ "de vente.\n" +#~ "Seuls les membres du goupe 'Enregistrer la réception d'un contrat signé' " +#~ "le peuvent." diff --git a/project_forecast_line_bokeh_chart/i18n/project_forecast_line_bokeh_chart.pot b/project_forecast_line_bokeh_chart/i18n/project_forecast_line_bokeh_chart.pot new file mode 100644 index 0000000000..4fbcd3c7d2 --- /dev/null +++ b/project_forecast_line_bokeh_chart/i18n/project_forecast_line_bokeh_chart.pot @@ -0,0 +1,142 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * project_forecast_line_bokeh_chart +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Available" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__bokeh_chart +msgid "Bokeh Chart" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__create_uid +msgid "Created by" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__create_date +msgid "Created on" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__date_from +msgid "Date From" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields.selection,name:project_forecast_line_bokeh_chart.selection__forecast_line_reporting__granularity__day +msgid "Day" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__display_name +msgid "Display Name" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__employee_ids +msgid "Employee" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.actions.act_window,name:project_forecast_line_bokeh_chart.action_forecast_lines_reporting +#: model:ir.ui.menu,name:project_forecast_line_bokeh_chart.menu_forecast_line_reporting +#: model_terms:ir.ui.view,arch_db:project_forecast_line_bokeh_chart.view_forecast_line_reporting +msgid "Forecast Reporting" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model,name:project_forecast_line_bokeh_chart.model_forecast_line_reporting +msgid "Forecast reporting wizard" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__granularity +msgid "Granularity" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__id +msgid "ID" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting____last_update +msgid "Last Modified on" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__write_date +msgid "Last Updated on" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields.selection,name:project_forecast_line_bokeh_chart.selection__forecast_line_reporting__granularity__month +msgid "Month" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__nb_months +msgid "Nb Months" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Not assigned to an employee" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Nothing to plot. Select some employees" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#: code:addons/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py:0 +#, python-format +msgid "Overload" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,field_description:project_forecast_line_bokeh_chart.field_forecast_line_reporting__project_ids +msgid "Project" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields,help:project_forecast_line_bokeh_chart.field_forecast_line_reporting__project_ids +msgid "" +"Setting this will automatically add all employees assigned to tasks on the " +"project" +msgstr "" + +#. module: project_forecast_line_bokeh_chart +#: model:ir.model.fields.selection,name:project_forecast_line_bokeh_chart.selection__forecast_line_reporting__granularity__week +msgid "Week" +msgstr "" diff --git a/project_forecast_line_bokeh_chart/models/__init__.py b/project_forecast_line_bokeh_chart/models/__init__.py new file mode 100644 index 0000000000..d4f5b72ba7 --- /dev/null +++ b/project_forecast_line_bokeh_chart/models/__init__.py @@ -0,0 +1 @@ +from . import forecast_line diff --git a/project_forecast_line_bokeh_chart/models/forecast_line.py b/project_forecast_line_bokeh_chart/models/forecast_line.py new file mode 100644 index 0000000000..da05c66d2a --- /dev/null +++ b/project_forecast_line_bokeh_chart/models/forecast_line.py @@ -0,0 +1,47 @@ +# Copyright 2022 Therp BV . +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, models + + +class ForecastLine(models.Model): + + _inherit = "forecast.line" + + @api.model + def _read_group_raw( + self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True + ): + """ + Inherit and add __range key, like in odoo 15 + https://github.com/odoo/odoo/blob/15.0/odoo/models.py#L2431 + """ + result = super()._read_group_raw( + domain, + fields, + groupby, + offset=offset, + limit=limit, + orderby=orderby, + lazy=lazy, + ) + dt = [ + f + for f in groupby + if self._fields[f.split(":")[0]].type + in ("date", "datetime") # e.g. 'date:month' + ] + for group in result: + if dt: + group["__range"] = {} + for df in dt: + field_name = df.split(":")[0] + if group.get(df): + range_from, range_to = group[df][0].split("/") + group["__range"][field_name] = {"from": range_from, "to": range_to} + # Inject another date key in the result + # for easier retrieval later on + group["forecast_date_start"] = range_from + else: + group["__range"][field_name] = False + group["forecast_date_start"] = False + return result diff --git a/project_forecast_line_bokeh_chart/readme/CONTRIBUTORS.rst b/project_forecast_line_bokeh_chart/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..b3c64a952a --- /dev/null +++ b/project_forecast_line_bokeh_chart/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Alexandre Fayolle +* Nikos Tsirintanis diff --git a/project_forecast_line_bokeh_chart/readme/DESCRIPTION.rst b/project_forecast_line_bokeh_chart/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..a6a54ca06a --- /dev/null +++ b/project_forecast_line_bokeh_chart/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module improves the reports of project_forecast_line by using the bokeh widget available in OCA/web. diff --git a/project_forecast_line_bokeh_chart/report/__init__.py b/project_forecast_line_bokeh_chart/report/__init__.py new file mode 100644 index 0000000000..e8dbc4d1d1 --- /dev/null +++ b/project_forecast_line_bokeh_chart/report/__init__.py @@ -0,0 +1 @@ +from . import forecast_line_reporting diff --git a/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py b/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py new file mode 100644 index 0000000000..468ab92206 --- /dev/null +++ b/project_forecast_line_bokeh_chart/report/forecast_line_reporting.py @@ -0,0 +1,219 @@ +# Copyright 2022 Camptocamp SA +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +# pylint: disable=W7936 +from bokeh import palettes +from bokeh.embed import components +from bokeh.layouts import column +from bokeh.models import ColumnDataSource, FactorRange +from bokeh.plotting import figure +from dateutil.relativedelta import relativedelta + +from odoo import _, api, fields, models +from odoo.tools import date_utils + + +class ForecastLineReporting(models.TransientModel): + _name = "forecast.line.reporting" + _description = "Forecast reporting wizard" + + bokeh_chart = fields.Text(compute="_compute_bokeh_chart") + date_from = fields.Date(default=fields.Date.today) + nb_months = fields.Integer(default=2) + granularity = fields.Selection( + [("day", "Day"), ("week", "Week"), ("month", "Month")], + default=lambda r: r.env.company.forecast_line_granularity, + required=True, + ) + + employee_ids = fields.Many2many("hr.employee") + + project_ids = fields.Many2many( + "project.project", + help="Setting this will automatically add " + "all employees assigned to tasks on the project", + ) + + @api.onchange("project_ids") + def onchange_project_ids(self): + if self.project_ids: + self.employee_ids |= self.project_ids.mapped("task_ids.user_id.employee_id") + + @api.depends("date_from", "nb_months", "employee_ids", "granularity", "project_ids") + def _compute_bokeh_chart(self): + """compute the chart to be displayed""" + # the current implementation shows 1 chart per selected employee over + # the next nb_month months with the selected granularity. For each + # employee, the chart displays the consolidated_forecast field + # grouped by project on which the employee is planned for a given + # period. + plots = self._build_plots() + grid = column(*plots) + script, div = components(grid) + self.bokeh_chart = "%s%s" % (div, script) + + def _prepare_bokeh_chart_data(self): + """compute the data that will be plotted. + + :return: a tuple with 2 elements: (projects list, plot_data + dictionary). + + The plot data dictionary is nested dictionary defined as follows: + + { + employee: { + project: { + date: forecast + for dates with a forecast on that project + } + for all projects scheduled on employee + } + for all selected employees + } + + """ + end_date = self.date_from + relativedelta(months=self.nb_months) + domain = [ + ("date_from", ">=", self.date_from), + ("date_to", "<=", end_date), + ] + if self.employee_ids: + if self.project_ids: + domain += [ + "|", + "&", + ("employee_id", "=", False), + ("project_id", "in", self.project_ids.ids), + ("employee_id", "in", self.employee_ids.ids), + ] + else: + domain += [("employee_id", "in", self.employee_ids.ids)] + else: + domain.append(("employee_id", "=", False)) + groups = [ + "date_from:%s" % self.granularity, + "employee_id", + "project_id", + ] + groupdata = self.env["forecast.line"].read_group( + domain, ["consolidated_forecast"], groups, lazy=False + ) + employees = set() + projects = set() + data_project = {} + data_overload = {} + for d in groupdata: + employee = d.get("employee_id") + if employee: + employee = employee[1]._value + else: + employee = _("Not assigned to an employee") + employees.add(employee) + if employee not in data_project: + data_project[employee] = {} + data_overload[employee] = {} + forecast = d["consolidated_forecast"] + date = d["forecast_date_start"] + project = d.get("project_id") + if project: + project = project[1]._value + data = data_project + elif forecast >= 0: + project = _("Available") + data = data_project + else: + project = _("Overload") + data = data_overload + projects.add(project) + if project not in data[employee]: + data[employee][project] = {} + x_key = date + data[employee][project][x_key] = forecast + employees = list(employees) + employees.sort() + if _("Not assigned to an employee") in employees: + # make sure it is the last one + employees.remove(_("Not assigned to an employee")) + employees.append(_("Not assigned to an employee")) + projects = list(projects) + projects.sort() + for name in [_("Available"), _("Overload")]: + if name in projects: + # make sure these two get in the first tow positions + projects.remove(name) + projects.insert(0, name) + return employees, projects, data_project, data_overload + + def _get_time_range(self): + end_date = self.date_from + relativedelta(months=self.nb_months) + dates = [] + granularity = self.granularity + date = self.date_from + delta = date_utils.get_timedelta(1, granularity) + while date < end_date: + dates.append(date.strftime("%Y-%m-%d")) + date += delta + return dates + + def _build_empty_plot(self, height=300, width=1024): + dates = self._get_time_range() + p = figure(height=height, width=width, x_range=FactorRange(*dates)) + p.title.text = _("Nothing to plot. Select some employees") + return [p] + + def _get_palette(self, projects): + """return a dictionary mapping project names to colors""" + if len(projects) <= 20: + project_colors = palettes.Category20[max(len(projects), 3)][: len(projects)] + else: + step = len(palettes.Turbo256) // len(projects) + project_colors = palettes.Turbo256[::step][: len(projects)] + return dict(zip(projects, project_colors)) + + def _build_plots(self, height=300, width=1024): + employees, projects, data, data_overload = self._prepare_bokeh_chart_data() + if not data: + return self._build_empty_plot(height, width) + project_color_map = self._get_palette(projects) + dates = self._get_time_range() + plots = [] + for employee in employees: + plot_data = {"dates": dates} + plot_data_overload = {"dates": dates} + for project in data[employee]: + forecast = data[employee][project] + plot_data[project] = [forecast.get(date, 0) for date in dates] + for project in data_overload[employee]: + forecast = data_overload[employee][project] + plot_data_overload[project] = [forecast.get(date, 0) for date in dates] + plot_projects = [ + p + for p in projects + if p in data[employee] or p in data_overload[employee] + ] + source = ColumnDataSource(data=plot_data) + source_overload = ColumnDataSource(data=plot_data_overload) + p = figure( + x_range=FactorRange(*dates), + height=max(height, len(plot_projects) * 30), + width=width, + ) + for src in (source, source_overload): + p.vbar_stack( + plot_projects, + x="dates", + source=src, + width=0.4, + alpha=0.5, + color=[project_color_map[p] for p in plot_projects], + legend_label=[ + (proj_name if len(proj_name) < 20 else proj_name[:19] + "…") + for proj_name in plot_projects + ], + ) + p.xaxis.major_label_orientation = "vertical" + p.title.text = employee + p.legend.click_policy = "mute" + p.add_layout(p.legend[0], "right") + plots.append(p) + return plots diff --git a/project_forecast_line_bokeh_chart/report/forecast_line_reporting_views.xml b/project_forecast_line_bokeh_chart/report/forecast_line_reporting_views.xml new file mode 100644 index 0000000000..53647c89ee --- /dev/null +++ b/project_forecast_line_bokeh_chart/report/forecast_line_reporting_views.xml @@ -0,0 +1,41 @@ + + + + forecast.line.reporting + +
+ +

Forecast Reporting

+ + + + + + + + + + + + + +
+
+
+
+ + Forecast Reporting + ir.actions.act_window + forecast.line.reporting + form + + + + +
diff --git a/project_forecast_line_bokeh_chart/security/ir.model.access.csv b/project_forecast_line_bokeh_chart/security/ir.model.access.csv new file mode 100644 index 0000000000..e27c0edcc1 --- /dev/null +++ b/project_forecast_line_bokeh_chart/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +project_forecast_line_bokeh_chart.access_forecast_line_reporting,access_forecast_line_reporting,project_forecast_line_bokeh_chart.model_forecast_line_reporting,base.group_user,1,1,1,1 diff --git a/project_forecast_line_bokeh_chart/static/description/icon.png b/project_forecast_line_bokeh_chart/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/project_forecast_line_bokeh_chart/static/description/icon.png differ diff --git a/project_forecast_line_bokeh_chart/static/description/index.html b/project_forecast_line_bokeh_chart/static/description/index.html new file mode 100644 index 0000000000..cddaf0c312 --- /dev/null +++ b/project_forecast_line_bokeh_chart/static/description/index.html @@ -0,0 +1,430 @@ + + + + + + +Project Forecast Lines Bokeh Chart + + + +
+

Project Forecast Lines Bokeh Chart

+ + +

Alpha License: AGPL-3 OCA/project Translate me on Weblate Try me on Runboat

+

This module improves the reports of project_forecast_line by using the bokeh widget available in OCA/web.

+
+

Important

+

This is an alpha version, the data model and design can change at any time without warning. +Only for development or testing purpose, do not use in production. +More details on development status

+
+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp SA
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

ntsirintanis

+

This module is part of the OCA/project project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/setup/project_forecast_line_bokeh_chart/odoo/addons/project_forecast_line_bokeh_chart b/setup/project_forecast_line_bokeh_chart/odoo/addons/project_forecast_line_bokeh_chart new file mode 120000 index 0000000000..8ec3407d10 --- /dev/null +++ b/setup/project_forecast_line_bokeh_chart/odoo/addons/project_forecast_line_bokeh_chart @@ -0,0 +1 @@ +../../../../project_forecast_line_bokeh_chart \ No newline at end of file diff --git a/setup/project_forecast_line_bokeh_chart/setup.py b/setup/project_forecast_line_bokeh_chart/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/project_forecast_line_bokeh_chart/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)