From a5f43f8090f1f937537baa5b4a16864bd857788f Mon Sep 17 00:00:00 2001 From: projectsodoo Date: Sat, 23 Jan 2021 09:20:23 +0530 Subject: [PATCH] Updated bar chart related reports --- cor_custom/__init__.py | 2 +- cor_custom/__manifest__.py | 1 + cor_custom/report/__init__.py | 3 +- cor_custom/security/ir.model.access.csv | 4 +- cor_custom/views/project_hours_view.xml | 1 - .../report/project_budget_amt_analysis.py | 100 ++++++++---------- .../report/project_budget_hrs_analysis.py | 93 ++++++++++------ .../project_budget_hrs_analysis_views.xml | 23 +++- .../static/src/js/graph_renderer.js | 8 +- 9 files changed, 136 insertions(+), 99 deletions(-) diff --git a/cor_custom/__init__.py b/cor_custom/__init__.py index a41b57f..1099cf8 100755 --- a/cor_custom/__init__.py +++ b/cor_custom/__init__.py @@ -3,4 +3,4 @@ from . import controllers from . import models from . import wizard -#from . import report \ No newline at end of file +from . import report \ No newline at end of file diff --git a/cor_custom/__manifest__.py b/cor_custom/__manifest__.py index 7450cb6..392550b 100755 --- a/cor_custom/__manifest__.py +++ b/cor_custom/__manifest__.py @@ -33,6 +33,7 @@ 'views/hr_employee_views.xml', 'views/hr_timesheet_templates.xml', 'views/analytic_view.xml', + 'report/project_hours_report_view.xml', 'report/project_profitability_report_analysis_views.xml', 'views/views.xml', 'views/templates.xml', diff --git a/cor_custom/report/__init__.py b/cor_custom/report/__init__.py index 22d6147..be2239a 100755 --- a/cor_custom/report/__init__.py +++ b/cor_custom/report/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from . import project_profitability_report_analysis +#from . import project_profitability_report_analysis +from . import project_hours_report diff --git a/cor_custom/security/ir.model.access.csv b/cor_custom/security/ir.model.access.csv index 371580d..872b016 100755 --- a/cor_custom/security/ir.model.access.csv +++ b/cor_custom/security/ir.model.access.csv @@ -7,4 +7,6 @@ access_project_consultant_hrs_pmanager,project.consultant.hrs,model_project_cons access_model_project_multi_budget_assign_puser,project.multi.budget.assign,model_project_multi_budget_assign,project.group_project_user,1,0,0,0 access_model_project_multi_budget_assign_pmanager,project.multi.budget.assign,model_project_multi_budget_assign,project.group_project_manager,1,1,1,1 access_model_project_multi_budget_assign_line_puser,project.multi.budget.assign.line,model_project_multi_budget_assign_line,project.group_project_user,1,0,0,0 -access_model_project_multi_budget_assign_line_pmanager,project.multi.budget.assign.line,model_project_multi_budget_assign_line,project.group_project_manager,1,1,1,1 \ No newline at end of file +access_model_project_multi_budget_assign_line_pmanager,project.multi.budget.assign.line,model_project_multi_budget_assign_line,project.group_project_manager,1,1,1,1 +access_project_consultant_hrs_report_puser,project.consultant.hrs.report,model_project_consultant_hrs_report,project.group_project_user,1,0,0,0 +access_project_consultant_hrs_report_pmanager,project.consultant.hrs.report,model_project_consultant_hrs_report,project.group_project_manager,1,1,1,1 \ No newline at end of file diff --git a/cor_custom/views/project_hours_view.xml b/cor_custom/views/project_hours_view.xml index 46c1057..bee126d 100755 --- a/cor_custom/views/project_hours_view.xml +++ b/cor_custom/views/project_hours_view.xml @@ -63,7 +63,6 @@ - Project Consul Hours project.project diff --git a/project_report/report/project_budget_amt_analysis.py b/project_report/report/project_budget_amt_analysis.py index 02b12f9..3503744 100755 --- a/project_report/report/project_budget_amt_analysis.py +++ b/project_report/report/project_budget_amt_analysis.py @@ -35,62 +35,50 @@ class BudgetAmtAnalysis(models.Model): CREATE OR REPLACE VIEW %s AS ( SELECT ROW_NUMBER() OVER() as id, project_id, partner_id, employee_id, amount_type, pricing_type, project_type, revenue from ( SELECT - PRO.id AS project_id, - PRO.create_date AS create_date, - PRO.partner_id AS partner_id, - null::int AS employee_id, - 'Budgeted Revenue' as amount_type, - PRO.pricing_type as pricing_type, - PRO.project_type as project_type, - PRO.budgeted_revenue AS revenue - FROM project_project PRO - WHERE PRO.active = 't' - --and (PRO.pricing_type = 'fixed_rate' OR PRO.project_type = 'hours_no_limit') - --union - --SELECT - --PRO.id AS project_id, - --PRO.create_date AS create_date, - --PRO.partner_id AS partner_id, - --Pro_emp.employee_id AS employee_id, - --'Budgeted Revenue' as amount_type, - --PRO.pricing_type as pricing_type, - --PRO.project_type as project_type, - --Pro_emp.cost AS revenue - --FROM project_project PRO - --Left JOIN project_sale_line_employee_map Pro_emp ON Pro_emp.project_id = Pro.id - --WHERE PRO.active = 't' and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_in_consultant' - --union - --SELECT - --PRO.id AS project_id, - --PRO.create_date AS create_date, - --PRO.partner_id AS partner_id, - --AAL.employee_id AS employee_id, - --'Actual Revenue' as amount_type, - --PRO.pricing_type as pricing_type, - --PRO.project_type as project_type, - --(AAL.amount * -1) AS revenue - --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_in_consultant' - union - SELECT - PRO.id AS project_id, - PRO.create_date AS create_date, - PRO.partner_id AS partner_id, - null::int AS employee_id, - 'Actual Revenue' as amount_type, - PRO.pricing_type as pricing_type, - PRO.project_type as project_type, - --(AAL.amount * -1) + pro.expenses_amt AS revenue - pro.total_expenses AS revenue - 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 = 'fixed_rate' OR PRO.project_type = 'hours_no_limit') - group by Pro.id, PRO.partner_id, Pro.budgeted_revenue, AAL.amount - order by create_date desc, project_id, amount_type desc) as res + pro.id AS project_id, + pro.partner_id AS partner_id, + pro_emp.employee_id AS employee_id, + 'Budgeted Revenue' as amount_type, + pro.pricing_type as pricing_type, + pro.project_type as project_type, + pro_emp.cost AS revenue + FROM project_project pro + Left JOIN project_sale_line_employee_map pro_emp ON pro_emp.project_id = pro.id + WHERE PRO.active = 't' and pro.pricing_type = 'employee_rate' and pro.project_type = 'hours_in_consultant' + union + SELECT + pro.id AS project_id, + pro.partner_id AS partner_id, + AAL.employee_id AS employee_id, + 'Actual Revenue' as amount_type, + pro.pricing_type as pricing_type, + pro.project_type as project_type, + (AAL.unit_amount * pro_emp.price_unit) AS revenue + 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 = 'employee_rate' and PRO.project_type = 'hours_in_consultant' + union + SELECT + pro.id AS project_id, + pro.partner_id AS partner_id, + AAL.employee_id AS employee_id, + 'Actual Cost' as amount_type, + pro.pricing_type as pricing_type, + pro.project_type as project_type, + (AAL.amount * -1) AS revenue + --(AAL.unit_amount * pro_emp.employee_price) AS revenue + 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 = 'employee_rate' and PRO.project_type = 'hours_in_consultant') + as res + order by + project_id, + amount_type desc + --group by Pro.id, PRO.partner_id, Pro.budgeted_revenue, AAL.amount )""" % (self._table,)) diff --git a/project_report/report/project_budget_hrs_analysis.py b/project_report/report/project_budget_hrs_analysis.py index 78aa89e..a06db37 100755 --- a/project_report/report/project_budget_hrs_analysis.py +++ b/project_report/report/project_budget_hrs_analysis.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models, tools +from odoo import fields, models, tools, api class BudgetHrsAnalysis(models.Model): @@ -19,56 +19,75 @@ class BudgetHrsAnalysis(models.Model): employee_id = fields.Many2one('hr.employee', string='Consultant', readonly=True) hours_type = fields.Char(string="Hours Type", readonly=True) hours = fields.Float("Hours", digits=(16, 2), readonly=True, group_operator="sum") - #project_type = fields.Selection([ - # ('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) + project_type = fields.Selection([ + ('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) #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") + @api.model + def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True): + print("rrr>>>>>>>>>>>>>>>>>>>>>>>>>.", 'hours_type' not in groupby) + if 'hours_type' not in groupby: + groupby.append('hours_type') + print("rrr>>>>>>>>>>>>>>>>>>>>>>>>>.", groupby, orderby) + """fields.remove('on_time_rate') + if 'qty_total' not in fields: + fields.append('qty_total') + if 'qty_on_time' not in fields: + fields.append('qty_on_time') + res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) + for group in res: + if group['qty_total'] == 0: + on_time_rate = 100 + else: + on_time_rate = group['qty_on_time'] / group['qty_total'] * 100 + group.update({'on_time_rate': on_time_rate}""" + print("rrr>>>>>>>>>>>>>>>>>>>>>>>>>.", groupby, orderby) + res = super().read_group(domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy) + print("Res", res) + return res + def init(self): '''Create the view''' tools.drop_view_if_exists(self._cr, self._table) self._cr.execute(""" CREATE OR REPLACE VIEW %s AS ( - SELECT ROW_NUMBER() OVER() as id, project_id, start_date, end_date, partner_id, employee_id, hours_type, + SELECT ROW_NUMBER() OVER() as id, project_id, start_date, end_date, pricing_type, project_type, partner_id, employee_id, hours_type, hours from ( - SELECT - PRO.id AS project_id, - Pro_emp_hours.start_date AS start_date, - Pro_emp_hours.end_date AS end_date, - PRO.partner_id AS partner_id, - Pro_emp_hours.employee_id AS employee_id, + SELECT + pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_date, + pro.pricing_type as pricing_type, + pro.project_type as project_type, + pro.partner_id AS partner_id, + pro_emp.employee_id AS employee_id, 'Budgeted Hours' as hours_type, - Pro_emp_hours.budgeted_hours as hours + pro_emp.budgeted_qty as hours FROM project_project PRO - Left JOIN project_sale_line_employee_map Pro_emp ON Pro_emp.project_id = Pro.id - Left JOIN project_consultant_hrs Pro_emp_hours ON Pro_emp_hours.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 + Left JOIN project_sale_line_employee_map pro_emp ON pro_emp.project_id = pro.id Where - PRO.active = 't' + pro.active = 't' and PRO.pricing_type != 'fixed_rate' - and PRO.project_type = 'hours_in_consultant' - Union + Union SELECT - PRO.id AS project_id, - Pro_emp_hours.start_date AS start_date, - Pro_emp_hours.end_date AS end_date, - PRO.partner_id AS partner_id, - Pro_emp_hours.employee_id AS employee_id, - 'Actual Hours' as hours_type, - Pro_emp_hours.actual_hours AS hours - FROM - project_project PRO - Left JOIN project_sale_line_employee_map Pro_emp ON Pro_emp.project_id = Pro.id - Left JOIN project_consultant_hrs Pro_emp_hours ON Pro_emp_hours.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 + pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_date, + pro.pricing_type as pricing_type, + pro.project_type as project_type, + pro.partner_id AS partner_id, + AAL.employee_id AS employee_id, + 'Actual Hours' as hours_type, + unit_amount as hours + 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' @@ -76,6 +95,10 @@ class BudgetHrsAnalysis(models.Model): ) as res order by project_id desc, + start_date, + end_date, + pricing_type, + project_type, hours_type asc, employee_id )""" % (self._table,)) diff --git a/project_report/report/project_budget_hrs_analysis_views.xml b/project_report/report/project_budget_hrs_analysis_views.xml index 83ea9ac..58743ec 100755 --- a/project_report/report/project_budget_hrs_analysis_views.xml +++ b/project_report/report/project_budget_hrs_analysis_views.xml @@ -25,6 +25,21 @@ + + project.budget.hrs.report.tree + project.budget.hrs.report + + + + + + + + + + + + project.budget.hrs.report.search @@ -34,8 +49,10 @@ + + + --> @@ -52,9 +69,9 @@ Projects Hours Acutal Vs Budget project.budget.hrs.report - graph,pivot + graph,tree,pivot - {'search_default_group_by_project': 1,'search_default_group_by_hours_type': 1} + {'search_default_group_by_project': 1,'search_default_group_by_hours_type': 1, 'default_res_model': 'project.budget.hrs.report'}