From 3519bc45ed07aef2e8072a0fe1b4cd8b8db5d4a0 Mon Sep 17 00:00:00 2001 From: projectsodoo Date: Sun, 24 Jan 2021 13:48:01 +0530 Subject: [PATCH] Bar chart Report updated --- .../report/project_budget_amt_analysis.py | 73 ++++++++++++++++++- .../project_budget_amt_analysis_views.xml | 10 ++- .../report/project_budget_hrs_analysis.py | 52 +++++++------ .../project_budget_hrs_analysis_views.xml | 7 +- 4 files changed, 111 insertions(+), 31 deletions(-) diff --git a/project_report/report/project_budget_amt_analysis.py b/project_report/report/project_budget_amt_analysis.py index 3503744..d79d1b3 100755 --- a/project_report/report/project_budget_amt_analysis.py +++ b/project_report/report/project_budget_amt_analysis.py @@ -25,6 +25,9 @@ class BudgetAmtAnalysis(models.Model): ('employee_rate', 'Consultant rate') ], string="Pricing", readonly=True) employee_id = fields.Many2one('hr.employee', string='Consultant', readonly=True) + start_date = fields.Date(string='Start Date', readonly=True) + end_date = fields.Date(string='End Date', readonly=True) + timesheet_date = fields.Date(string='Timesheet Date', readonly=True) #budgeted_revenue = fields.Float("Budgeted Revenue", digits=(16, 2), readonly=True, group_operator="sum") #actual_revenue = fields.Float("Actual Revenue", digits=(16, 2), readonly=True, group_operator="sum") @@ -33,47 +36,109 @@ class BudgetAmtAnalysis(models.Model): 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, partner_id, employee_id, amount_type, pricing_type, project_type, revenue from ( + SELECT ROW_NUMBER() OVER() as id, project_id, start_date, end_date, timesheet_date, partner_id, employee_id, amount_type, pricing_type, project_type, revenue from ( SELECT pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_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, + null::date AS timesheet_date, 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 + union SELECT pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_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, + null::date AS timesheet_date, (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 + union SELECT pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_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, + null::date AS timesheet_date, + pro.budgeted_hours2 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_no_limit' + union + SELECT + pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_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, + null::date AS timesheet_date, + (AAL.unit_amount) AS revenue + --(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_no_limit' + union + SELECT + pro.id AS project_id, + pro.date_start AS start_date, + pro.date AS end_date, 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.date AS timesheet_date, (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') + 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.date_start AS start_date, + pro.date AS end_date, + 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.date AS timesheet_date, + (AAL.amount * -1) AS revenue + --(AAL.unit_amount * pro_emp.employee_price) 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 + --and AAL.employee_id = pro_emp.employee_id + WHERE PRO.active = 't' and PRO.pricing_type = 'fixed_rate') as res order by project_id, diff --git a/project_report/report/project_budget_amt_analysis_views.xml b/project_report/report/project_budget_amt_analysis_views.xml index 1b34c31..9857fb1 100755 --- a/project_report/report/project_budget_amt_analysis_views.xml +++ b/project_report/report/project_budget_amt_analysis_views.xml @@ -34,14 +34,20 @@ - + + + + + - + + + diff --git a/project_report/report/project_budget_hrs_analysis.py b/project_report/report/project_budget_hrs_analysis.py index a06db37..1eb993e 100755 --- a/project_report/report/project_budget_hrs_analysis.py +++ b/project_report/report/project_budget_hrs_analysis.py @@ -23,39 +23,23 @@ 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) #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 + """@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 + 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, pricing_type, project_type, partner_id, employee_id, hours_type, + SELECT ROW_NUMBER() OVER() as id, project_id, start_date, end_date, timesheet_date, pricing_type, project_type, partner_id, employee_id, hours_type, hours from ( SELECT pro.id AS project_id, @@ -66,13 +50,14 @@ class BudgetHrsAnalysis(models.Model): pro.partner_id AS partner_id, pro_emp.employee_id AS employee_id, 'Budgeted Hours' as hours_type, + null::date AS timesheet_date, 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 Where pro.active = 't' - and PRO.pricing_type != 'fixed_rate' + and PRO.pricing_type = 'employee_rate' Union SELECT pro.id AS project_id, @@ -83,15 +68,36 @@ class BudgetHrsAnalysis(models.Model): pro.partner_id AS partner_id, AAL.employee_id AS employee_id, 'Actual Hours' as hours_type, + AAL.date AS timesheet_date, 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 = 'employee_rate' + --and PRO.project_type = 'hours_in_consultant' + Union + 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, + AAL.employee_id AS employee_id, + 'Actual Hours' as hours_type, + AAL.date AS timesheet_date, + 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' - and PRO.project_type = 'hours_in_consultant' + 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 58743ec..81678b7 100755 --- a/project_report/report/project_budget_hrs_analysis_views.xml +++ b/project_report/report/project_budget_hrs_analysis_views.xml @@ -51,14 +51,17 @@ - + + + + +