From 802b029e158964560e6b1401aa16705264b8e9ac Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Oct 2022 11:19:49 +0530 Subject: [PATCH 1/3] Report budgeted qty and amt updated not based on date --- cor_custom/models/project.py | 4 ++ .../report/project_revenue_custom_report3.py | 70 +++++++------------ 2 files changed, 30 insertions(+), 44 deletions(-) diff --git a/cor_custom/models/project.py b/cor_custom/models/project.py index f08f0a0..ae8c890 100755 --- a/cor_custom/models/project.py +++ b/cor_custom/models/project.py @@ -77,6 +77,10 @@ class Project(models.Model): tag_ids = fields.Many2many('custom.project.tags', string='Tags') is_check = fields.Boolean() + _sql_constraints = [ + ('name_uniq', 'unique(name)', "Project name already exists !"), + ] + @api.onchange('allowed_internal_user_ids') def onchange_add_allowed_internal_users(self): user_list = [] diff --git a/project_report/report/project_revenue_custom_report3.py b/project_report/report/project_revenue_custom_report3.py index dd9044d..6e622ef 100644 --- a/project_report/report/project_revenue_custom_report3.py +++ b/project_report/report/project_revenue_custom_report3.py @@ -167,7 +167,7 @@ data1 as ( (0.0 - (sum(AAL.amount) * -1)) AS profit_amt, 0.0 AS profit_per FROM pro_data - left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id + right join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id where pro_data.pricing_type = 'fixed_rate' and AAL.sub_project is null and COALESCE(pro_data.is_sub_project, FALSE) = False @@ -213,7 +213,7 @@ data1_sub as ( (0.0 - (sum(AAL.amount) * -1)) AS profit_amt, 0.0 AS profit_per FROM sub_pro_data - left join account_analytic_line AAL on AAL.sub_project=sub_pro_data.sub_project + right join account_analytic_line AAL on AAL.sub_project=sub_pro_data.sub_project where sub_pro_data.pricing_type = 'fixed_rate' and AAL.sub_project is not null and sub_pro_data.is_sub_project = TRUE @@ -259,7 +259,7 @@ data2 as ( 0.0 AS profit_amt, 0.0 AS profit_per FROM pro_data - left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id + right join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id WHERE pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_no_limit' and AAL.sub_project is null and COALESCE(pro_data.is_sub_project, FALSE) = False @@ -305,7 +305,7 @@ SELECT ((AAL.unit_amount * pro_data.pro_hourly_rate) - (AAL.amount * -1)) AS profit_amt, ((AAL.unit_amount * pro_data.pro_hourly_rate) - (AAL.amount * -1))/NULLIF((AAL.unit_amount * pro_data.pro_hourly_rate),0) AS profit_per FROM pro_data - left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id + right join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id WHERE pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_no_limit' AND AAL.sub_project is null AND COALESCE(pro_data.is_sub_project, FALSE) = False @@ -402,7 +402,7 @@ SELECT ((AAL.unit_amount * sub_pro_data.pro_hourly_rate) - (AAL.amount * -1)) AS profit_amt, ((AAL.unit_amount * sub_pro_data.pro_hourly_rate) - (AAL.amount * -1))/NULLIF((AAL.unit_amount * sub_pro_data.pro_hourly_rate),0) AS profit_per FROM sub_pro_data - left join account_analytic_line AAL on AAL.sub_project=sub_pro_data.sub_project + right join account_analytic_line AAL on AAL.sub_project=sub_pro_data.sub_project WHERE sub_pro_data.pricing_type='employee_rate' and sub_pro_data.project_type='hours_no_limit' and AAL.sub_project is not null and sub_pro_data.is_sub_project = TRUE @@ -455,7 +455,7 @@ SELECT 0.0 as profit_amt, 0.0 as profit_per FROM pro_data - left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id + right join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant' and AAL.sub_project is null and COALESCE(pro_data.is_sub_project, FALSE) = False @@ -473,9 +473,9 @@ SELECT pro_data.expenses_amt UNION SELECT - drange_data2.start_date, - drange_data2.end_date, - drange_data2.project_id, + null as start_date, + null as end_date, + cons_data1.project_id, pro_data.project_active, pro_data.project_type, pro_data.pricing_type, @@ -484,12 +484,12 @@ SELECT cons_data1.role, pro_data.tag_name, pro_data.partner_id, - drange_data2.employee_id, + cons_data1.employee_id, null::int As timesheet_id, null::timestamp as timesheet_sdatetime, 0 as overall_budgeted_revenue, - cons_data1.budgeted_revenue, - cons_data1.budgeted_hours, + sum(cons_data1.budgeted_revenue) as budgeted_revenue, + sum(cons_data1.budgeted_hours) as budgeted_hours, 0 as overall_hourly_rate, 0 as unit_amount, 0 as pro_hourly_rate, @@ -499,24 +499,18 @@ SELECT 0 as expenses_amt, 0 as profit_amt, 0 as profit_per - FROM drange_data2 - left join pro_data on pro_data.pproject_id = drange_data2.project_id - left join cons_data1 on cons_data1.project_id=drange_data2.project_id and cons_data1.employee_id=drange_data2.employee_id - and drange_data2.start_date >= cons_data1.start_date and drange_data2.end_date <= cons_data1.end_date + FROM pro_data + left join cons_data1 on cons_data1.project_id = pro_data.pproject_id where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant' and COALESCE(pro_data.is_sub_project, FALSE) = False and (cons_data1.budgeted_revenue>0 or cons_data1.budgeted_hours>0) group by - drange_data2.start_date, - drange_data2.end_date, - drange_data2.project_id, - drange_data2.employee_id, + cons_data1.project_id, + cons_data1.employee_id, pro_data.project_active, pro_data.project_type, pro_data.parent_project, cons_data1.role, - cons_data1.budgeted_revenue, - cons_data1.budgeted_hours, pro_data.tag_name, pro_data.pricing_type, pro_data.partner_id @@ -554,7 +548,7 @@ SELECT (((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) - case when cons_data1.cons_timesheet_cost is null then (AAL.amount * -1) else (AAL.unit_amount * cons_data1.cons_timesheet_cost) end) / NULLIF((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)), 0)) * 100 as profit_per FROM pro_data - left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id + right join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id left join cons_data1 on cons_data1.project_id=AAL.project_id and cons_data1.employee_id=AAL.employee_id --and (AAL.start_datetime, AAL.end_datetime) OVERLAPS (cons_data1.start_date::date, cons_data1.end_date::date) and AAL.start_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3) @@ -629,11 +623,9 @@ SELECT sub_pro_data.expenses_amt UNION SELECT - drange_data2.start_date, - drange_data2.end_date, + null as start_date, + null as end_date, sub_pro_data.pproject_id as project_id, - --sub_pro_data.parent_project as project_id, - --drange_data2.project_id, sub_pro_data.project_active, sub_pro_data.project_type, sub_pro_data.pricing_type, @@ -642,12 +634,12 @@ SELECT cons_data1.role, sub_pro_data.tag_name, sub_pro_data.partner_id, - drange_data2.employee_id, + cons_data1.employee_id, null::int As timesheet_id, null::timestamp as timesheet_sdatetime, 0 as overall_budgeted_revenue, - cons_data1.budgeted_revenue, - cons_data1.budgeted_hours, + sum(cons_data1.budgeted_revenue) as budgeted_revenue, + sum(cons_data1.budgeted_hours) as budgeted_hours, 0 as overall_hourly_rate, 0 as unit_amount, 0 as pro_hourly_rate, @@ -657,29 +649,19 @@ SELECT 0 as expenses_amt, 0 as profit_amt, 0 as profit_per - FROM drange_data2 - left join sub_pro_data on sub_pro_data.sub_project = drange_data2.project_id - left join cons_data1 on cons_data1.project_id = drange_data2.project_id - and cons_data1.employee_id=drange_data2.employee_id - and (drange_data2.start_date, drange_data2.end_date) OVERLAPS (cons_data1.start_date, cons_data1.end_date) - --and drange_data2.start_date >= cons_data1.start_date - --and drange_data2.end_date <= cons_data1.end_date + FROM sub_pro_data + left join cons_data1 on cons_data1.project_id = sub_pro_data.sub_project where sub_pro_data.pricing_type='employee_rate' and sub_pro_data.project_type='hours_in_consultant' and sub_pro_data.is_sub_project = True and (cons_data1.budgeted_revenue>0 or cons_data1.budgeted_hours>0) group by - drange_data2.start_date, - drange_data2.end_date, sub_pro_data.pproject_id, - --sub_pro_data.parent_project, - drange_data2.employee_id, + cons_data1.employee_id, sub_pro_data.project_active, sub_pro_data.project_type, sub_pro_data.parent_project, sub_pro_data.sub_project, cons_data1.role, - cons_data1.budgeted_revenue, - cons_data1.budgeted_hours, sub_pro_data.tag_name, sub_pro_data.pricing_type, sub_pro_data.partner_id @@ -717,7 +699,7 @@ SELECT (((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) - case when cons_data1.cons_timesheet_cost is null then (AAL.amount * -1) else (AAL.unit_amount * cons_data1.cons_timesheet_cost) end) / NULLIF((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)), 0)) * 100 as profit_per FROM sub_pro_data - left join account_analytic_line AAL on AAL.sub_project=sub_pro_data.sub_project + right join account_analytic_line AAL on AAL.sub_project=sub_pro_data.sub_project left join cons_data1 on cons_data1.project_id=AAL.sub_project and cons_data1.employee_id=AAL.employee_id --and (AAL.start_datetime, AAL.end_datetime) OVERLAPS (cons_data1.start_date::date, cons_data1.end_date::date) and AAL.start_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3) From f8863a95e9b9d30015d906f5018dd312f19a9f3d Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Oct 2022 11:50:14 +0530 Subject: [PATCH 2/3] Revert unique constraints --- cor_custom/models/project.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cor_custom/models/project.py b/cor_custom/models/project.py index ae8c890..f08f0a0 100755 --- a/cor_custom/models/project.py +++ b/cor_custom/models/project.py @@ -77,10 +77,6 @@ class Project(models.Model): tag_ids = fields.Many2many('custom.project.tags', string='Tags') is_check = fields.Boolean() - _sql_constraints = [ - ('name_uniq', 'unique(name)', "Project name already exists !"), - ] - @api.onchange('allowed_internal_user_ids') def onchange_add_allowed_internal_users(self): user_list = [] From 0a82aa75a36c8d3a88e8d2dcb8501069384381bb Mon Sep 17 00:00:00 2001 From: root Date: Fri, 21 Oct 2022 13:28:04 +0530 Subject: [PATCH 3/3] date to null added for bud, hrs, rev and exp amt --- .../report/project_revenue_custom_report3.py | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/project_report/report/project_revenue_custom_report3.py b/project_report/report/project_revenue_custom_report3.py index 6e622ef..a4bd4ef 100644 --- a/project_report/report/project_revenue_custom_report3.py +++ b/project_report/report/project_revenue_custom_report3.py @@ -232,8 +232,10 @@ data1_sub as ( ), data2 as ( SELECT - coalesce(min(pro_data.pro_sdate), min(AAL.start_datetime::date)) as start_date, - coalesce(max(pro_data.pro_edate), max(AAL.end_datetime::date)) as end_date, + --coalesce(min(pro_data.pro_sdate), min(AAL.start_datetime::date)) as start_date, + --coalesce(max(pro_data.pro_edate), max(AAL.end_datetime::date)) as end_date, + null::date as start_date, + null::date as end_date, pro_data.pproject_id as project_id, pro_data.project_active, pro_data.project_type, @@ -331,8 +333,10 @@ SELECT ), data2_sub_project as ( SELECT - min(sub_pro_data.pro_sdate) as start_date, - max(sub_pro_data.pro_edate)as end_date, + --min(sub_pro_data.pro_sdate) as start_date, + --max(sub_pro_data.pro_edate)as end_date, + null::date as start_date, + null::date as end_date, sub_pro_data.parent_project as project_id, sub_pro_data.project_active, sub_pro_data.project_type, @@ -428,8 +432,10 @@ SELECT ), data3 as ( SELECT - coalesce(min(pro_data.pro_sdate), min(AAL.start_datetime::date)) as start_date, - coalesce(max(pro_data.pro_edate), max(AAL.end_datetime::date)) as end_date, + --coalesce(min(pro_data.pro_sdate), min(AAL.start_datetime::date)) as start_date, + --coalesce(max(pro_data.pro_edate), max(AAL.end_datetime::date)) as end_date, + null::date as start_date, + null::date as end_date, pro_data.pproject_id as project_id, pro_data.project_active, pro_data.project_type, @@ -473,8 +479,8 @@ SELECT pro_data.expenses_amt UNION SELECT - null as start_date, - null as end_date, + null::date as start_date, + null::date as end_date, cons_data1.project_id, pro_data.project_active, pro_data.project_type, @@ -578,8 +584,10 @@ SELECT ), data3_sub_project as ( SELECT - min(sub_pro_data.pro_sdate) as start_date, - max(sub_pro_data.pro_edate) as end_date, + --min(sub_pro_data.pro_sdate) as start_date, + --max(sub_pro_data.pro_edate) as end_date, + null::date as start_date, + null::date as end_date, --sub_pro_data.parent_project as project_id, sub_pro_data.pproject_id as project_id, sub_pro_data.project_active, @@ -623,8 +631,8 @@ SELECT sub_pro_data.expenses_amt UNION SELECT - null as start_date, - null as end_date, + null::date as start_date, + null::date as end_date, sub_pro_data.pproject_id as project_id, sub_pro_data.project_active, sub_pro_data.project_type,