diff --git a/project_report/report/project_budget_hrs_analysis.py b/project_report/report/project_budget_hrs_analysis.py index b415a04..f71a2f6 100755 --- a/project_report/report/project_budget_hrs_analysis.py +++ b/project_report/report/project_budget_hrs_analysis.py @@ -30,7 +30,7 @@ class BudgetHrsAnalysis(models.Model): ('hours_in_consultant', 'Hours are budgeted according to a consultant'), ('hours_no_limit', 'Total hours are budgeted without division to consultant'), ], string="Project Type", readonly=True) - timesheet_date = fields.Date(string='Timesheet Date', readonly=True) + #timesheet_date = fields.Date(string='Timesheet Date', readonly=True) #budgeted_hours = fields.Float("Budgeted Hours", digits=(16, 2), readonly=True, group_operator="sum") #actual_hours = fields.Float("Actual Hours", digits=(16, 2), readonly=True, group_operator="sum") @@ -52,11 +52,6 @@ class BudgetHrsAnalysis(models.Model): parent_project, startdate as start_date, enddate as end_date, - --is_sub_project, - --sub_project, - --date_start AS start_date, - --date AS end_date, - timesheet_date, pricing_type as pricing_type, project_type as project_type, partner_id, @@ -70,7 +65,6 @@ class BudgetHrsAnalysis(models.Model): date_start AS startdate, date AS enddate, 'Budgeted Hours' as hours_type, - null::date AS timesheet_date, pro_emp.budgeted_qty as hours, pro.* FROM @@ -87,7 +81,6 @@ class BudgetHrsAnalysis(models.Model): date_start AS startdate, date AS enddate, 'Budgeted Hours' as hours_type, - null::date AS timesheet_date, pro.budgeted_hours2 as hours, pro.* FROM @@ -101,10 +94,9 @@ class BudgetHrsAnalysis(models.Model): pro.id AS project_id, (select project_id from project_subproject_rel as par where pro.id=par.id limit 1) as parent_project, AAL.employee_id AS employee_id, - start_datetime AS startdate, - end_datetime AS enddate, + coalesce(pro.date_start, (select min(al.start_datetime::date) from account_analytic_line as al where pro.id=al.project_id)) AS startdate, + (select max(al.end_datetime::date) from account_analytic_line as al) as enddate, 'Actual Hours' as hours_type, - AAL.date AS timesheet_date, unit_amount as hours, pro.* FROM project_project PRO @@ -112,28 +104,40 @@ class BudgetHrsAnalysis(models.Model): LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id and AAL.project_id = PRO.id and AAL.employee_id = pro_emp.employee_id Where - PRO.active = 't' and PRO.pricing_type = 'employee_rate' - --and PRO.project_type = 'hours_in_consultant' + PRO.active = 't' + and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_in_consultant' and AAL.employee_id is not null Union all SELECT pro.id AS project_id, (select project_id from project_subproject_rel as par where pro.id=par.id limit 1) as parent_project, AAL.employee_id AS employee_id, - start_datetime::DATE AS startdate, - end_datetime::DATE AS enddate, + coalesce(pro.date_start, (select min(al.start_datetime::date) from account_analytic_line as al where pro.id=al.project_id)) AS startdate, + (select max(al.end_datetime::date) from account_analytic_line as al) as enddate, + 'Actual Hours' as hours_type, + unit_amount as hours, + pro.* + FROM project_project PRO + LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id + LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id and AAL.project_id = PRO.id + Where + PRO.active = 't' + and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_no_limit' and AAL.employee_id is not null + Union all + SELECT + pro.id AS project_id, + (select project_id from project_subproject_rel as par where pro.id=par.id limit 1) as parent_project, + AAL.employee_id AS employee_id, + pro.date_start AS startdate, + (select max(al.end_datetime::date) from account_analytic_line as al) as enddate, 'Actual Hours' as hours_type, - AAL.date AS timesheet_date, unit_amount as hours, pro.* FROM project_project PRO - --Left JOIN project_sale_line_employee_map pro_emp ON pro_emp.project_id = pro.id LEFT JOIN account_analytic_account AA ON PRO.analytic_account_id = AA.id LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id and AAL.project_id = PRO.id - --and AAL.employee_id = pro_emp.employee_id Where PRO.active = 't' and PRO.pricing_type = 'fixed_rate' - --and PRO.project_type = 'hours_in_consultant' ) as res order by project_id desc, diff --git a/project_report/report/project_budget_hrs_analysis_views.xml b/project_report/report/project_budget_hrs_analysis_views.xml index 2928930..9f9ddf3 100755 --- a/project_report/report/project_budget_hrs_analysis_views.xml +++ b/project_report/report/project_budget_hrs_analysis_views.xml @@ -34,7 +34,7 @@ - + @@ -53,7 +53,7 @@ - + @@ -64,7 +64,7 @@ - + diff --git a/project_report/static/src/js/graph_renderer.js b/project_report/static/src/js/graph_renderer.js index 78e1f18..8ee2aaa 100755 --- a/project_report/static/src/js/graph_renderer.js +++ b/project_report/static/src/js/graph_renderer.js @@ -324,6 +324,32 @@ var MAX_LEGEND_LENGTH = 25 * (1 + config.device.size_class); boxColor: boxColor, }; }, + /** + * This function extracts the information from the data points in tooltipModel.dataPoints + * (corresponding to datapoints over a given label determined by the mouse position) + * that will be displayed in a custom tooltip. + * + * @private + * @param {Object} tooltipModel see chartjs documentation + * @return {Object[]} + */ + _getTooltipItems: function (tooltipModel) { + var self = this; + var data = this.chart.config.data; + + var orderedItems = tooltipModel.dataPoints.sort(function (dPt1, dPt2) { + return dPt2.yLabel - dPt1.yLabel; + }); + return orderedItems.reduce( + function (acc, item) { + if (item.value > 0) { + acc.push(self._getTooltipItemContent(item, data)); + } + return acc; + }, + [] + ); + }, _isRedirectionEnabled: function () { return !this.disableLinking && @@ -545,7 +571,8 @@ var MAX_LEGEND_LENGTH = 25 * (1 + config.device.size_class); // this.title = 'Time Line'; if (self.resModel == 'project.budget.hrs.report') { - var groupedData = _.groupBy(data.datasets, x => x.label.replace('Actual Hours', '').replace('Budgeted Hours', '')); + var groupedData = _.groupBy(data.datasets, x => x.label.replace('Actual Hours', '').replace('Budgeted Hours', '').split("/")[0]); + //var groupedData = _.groupBy(data.datasets, x => x.label.replace('Actual Hours', '').replace('Budgeted Hours', '')); _.map(groupedData, (y) => { if (y.length > 1) { var zipped_1 = _.zip.apply(null, [y[0].data, y[1].data]); @@ -678,7 +705,7 @@ var MAX_LEGEND_LENGTH = 25 * (1 + config.device.size_class); var data = this._prepareData(dataPoints); if (self.resModel == 'project.budget.hrs.report') { - var groupedData = _.groupBy(data.datasets, x => x.label.replace('Actual Hours', '').replace('Budgeted Hours', '')); + var groupedData = _.groupBy(data.datasets, x => x.label.replace('Actual Hours', '').replace('Budgeted Hours', '').split("/")[0]); _.map(groupedData, (y) => { if (y.length > 1) { var zipped_1 = _.zip.apply(null, [y[0].data, y[1].data]);