diff --git a/project_report/report/project_revenue_custom_report3.py b/project_report/report/project_revenue_custom_report3.py
index 7c43ac0..95c68ca 100644
--- a/project_report/report/project_revenue_custom_report3.py
+++ b/project_report/report/project_revenue_custom_report3.py
@@ -41,7 +41,7 @@ class ProjectRevenueCustomReport3(models.Model):
project_active = fields.Boolean('Active')
tag_name = fields.Char("Tag Name")
role = fields.Selection([('Manager', 'Manager'), ('Employee', 'Employee')], string="Role")
- is_sub_project = fields.Boolean("Is Sub Project")
+ #is_sub_project = fields.Boolean("Is Sub Project")
sub_project = fields.Many2one('project.project', string='Sub Project')
@@ -50,299 +50,346 @@ class ProjectRevenueCustomReport3(models.Model):
tools.drop_view_if_exists(self._cr, self._table)
self._cr.execute("""
CREATE OR REPLACE VIEW %s AS (
-with pro_tsheet as (SELECT
- date_trunc('month', min(AAL.start_datetime::date)) AS min,
- date_trunc('month', max(AAL.end_datetime::date)) AS max,
- AAL.start_datetime::date as t_startdate,
- AAL.end_datetime::date as t_enddate,
- PRO.date_start as pro_sdate,
- PRO.date as pro_edate,
+with pro_data as (
+ SELECT
PRO.id as pproject_id,
- AAL.project_id as project_id,
+ PRO.date_start as pro_sdate,
+ PRO.date as pro_edate,
PRO.active as project_active,
PRO.project_type,
PRO.pricing_type,
- (select PRO.id from project_subproject_rel as PAR where PRO.id=PAR.project_id limit 1) as parent_project,
- --CASE WHEN PRO.sub_project is not null then True else False END as is_sub_project,
- PRO.is_sub_project,
- AAL.sub_project as sub_project,
+ (select PRO.id from project_subproject_rel as PAR where PRO.id=PAR.project_id limit 1) as parent_project,
+ PRO.sub_project as sub_project,
STRING_AGG(distinct tag_master.name, ', ') as tag_name,
PRO.partner_id AS partner_id,
- AAL.id as timesheet_id,
PRO.budgeted_revenue as budgeted_revenue,
PRO.budgeted_hours2 as budgeted_hours,
- PRO.expenses_amt,
- pro.hourly_rate AS pro_hourly_rate,
- AAL.employee_id,
- AAL.unit_amount as unit_amount,
- (AAL.unit_amount * pro.hourly_rate) AS actual_revenue,
- (AAL.amount * -1) as actual_cost
+ PRO.expenses_amt as expenses_amt,
+ PRO.hourly_rate AS pro_hourly_rate
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
- LEFT JOIN custom_project_tags_project_project_rel AS cus_pro_tag ON pro.id = cus_pro_tag.project_project_id
- LEFT JOIN custom_project_tags as tag_master ON tag_master.id = cus_pro_tag.custom_project_tags_id
- LEFT JOIN project_subproject_rel as sub_pro ON sub_pro.project_id = PRO.id
- GROUP BY PRO.id, AAL.start_datetime::date, AAL.end_datetime::date, AAL.project_id, PRO.active,
- PRO.project_type, PRO.pricing_type, PRO.is_sub_project, AAL.sub_project, AAL.project_id,
- PRO.partner_id, --sub_pro.id,
- AAL.id, PRO.id, PRO.budgeted_revenue, PRO.budgeted_hours2, PRO.expenses_amt,
- pro.hourly_rate, AAL.employee_id, AAL.unit_amount, AAL.amount
- ),
-input_data as (SELECT generate_series(min, max,'1 month'):: date AS start_date,
- (generate_series(min, max, '1 month'):: date + '1 month' :: interval - '1 day' :: interval):: date AS end_date,
- pro_tsheet.project_id, pro_tsheet.employee_id
- from pro_tsheet),
-cons_data as (
-SELECT PRO_EMP.start_date as cons_start_date, PRO_EMP.end_date as cons_end_date,
- sum(PRO_EMP.price_unit) as price_unit, PRO_EMP.project_id, PRO_EMP.employee_id,
- sum(PRO_EMP.employee_price) as cons_price, sum(PRO_EMP.cost) AS cons_budgeted_revenue,
- sum(PRO_EMP.budgeted_qty) AS cons_budgeted_hours
- from project_sale_line_employee_map PRO_EMP
- GROUP BY PRO_EMP.start_date, PRO_EMP.end_date, PRO_EMP.project_id, PRO_EMP.employee_id
+ LEFT JOIN custom_project_tags_project_project_rel AS cus_pro_tag ON pro.id = cus_pro_tag.project_project_id
+ LEFT JOIN custom_project_tags as tag_master ON tag_master.id = cus_pro_tag.custom_project_tags_id
+ group by pro.id
+),
+cons_data1 as (
+ SELECT
+ date_trunc('month', min(PRO_EMP.start_date)) AS min,
+ date_trunc('month', max(coalesce(PRO_EMP.end_date, current_date))) AS max,
+ PRO_EMP.start_date as start_date,
+ coalesce(PRO_EMP.end_date, current_date) as end_date,
+ PRO_EMP.project_id,
+ PRO_EMP.employee_id,
+ PRO_EMP.role,
+ PRO_EMP.budgeted_qty as budgeted_hours,
+ PRO_EMP.cost as budgeted_revenue,
+ PRO_EMP.employee_price as cons_timesheet_cost,
+ PRO_EMP.price_unit as cons_hourly_cost
+ FROM project_sale_line_employee_map PRO_EMP
+ group by start_date, end_date, project_id, employee_id, role, budgeted_hours, budgeted_revenue, cons_timesheet_cost, cons_hourly_cost
+),
+tsheet_data1 as (
+ SELECT
+ date_trunc('month', min(AAL.start_datetime::date)) AS min,
+ date_trunc('month', max(AAL.end_datetime::date)) AS max,
+ AAL.project_id,
+ AAL.employee_id
+ FROM account_analytic_line AAL
+ group by AAL.project_id, AAL.employee_id
+),
+drange_data1 as (
+ SELECT
+ tsheet_data1.project_id,
+ tsheet_data1.employee_id,
+ generate_series(min, max,'1 month'):: date AS start_date,
+ (generate_series(min, max, '1 month'):: date + '1 month' :: interval - '1 day' :: interval):: date AS end_date
+ FROM tsheet_data1
+),
+drange_data2 as (
+ SELECT
+ cons_data1.project_id,
+ cons_data1.employee_id,
+ generate_series(min, max,'1 month'):: date AS start_date,
+ (generate_series(min, max, '1 month'):: date + '1 month' :: interval - '1 day' :: interval):: date AS end_date
+ FROM cons_data1
),
invoice_date as (
SELECT
date,
project_id,
(SELECT id FROM hr_employee WHERE LOWER(name)=LOWER('Fixed amount') limit 1) as employee_id,
- fixed_amount from project_revenue_lines),
-fixed_rate as (
+ fixed_amount from project_revenue_lines
+),
+data1 as (
SELECT
- input_data.start_date,
- input_data.end_date,
- input_data.project_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
+ drange_data1.start_date,
+ drange_data1.end_date,
+ drange_data1.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
null::char as role,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.timesheet_id,
- input_data.employee_id,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ --pro_tsheet.timesheet_id,
+ drange_data1.employee_id,
0 as overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
0 as overall_hourly_rate,
0 AS pro_hourly_rate,
- pro_tsheet.unit_amount,
- ((pro_tsheet.actual_cost)/NULLIF(pro_tsheet.unit_amount, 0)) as timesheet_cost,
+ sum(AAL.unit_amount) as unit_amount,
+ ((sum(AAL.amount) * -1)/NULLIF(sum(AAL.unit_amount), 0)) as timesheet_cost,
0.0 AS actual_revenue,
- pro_tsheet.actual_cost,
+ (sum(AAL.amount) * -1) as actual_cost,
0.0 AS expenses_amt,
- (0.0 - pro_tsheet.actual_cost) AS profit_amt,
+ (0.0 - (sum(AAL.amount) * -1)) AS profit_amt,
0.0 AS profit_per
- from input_data
- left join pro_tsheet on pro_tsheet.project_id = input_data.project_id and pro_tsheet.employee_id = input_data.employee_id
- and pro_tsheet.t_startdate >= input_data.start_date and pro_tsheet.t_enddate <= input_data.end_date
- where pro_tsheet.pricing_type = 'fixed_rate'
- group by
- input_data.start_date,
- input_data.end_date,
- input_data.project_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.timesheet_id,
- input_data.employee_id,
- pro_tsheet.unit_amount,
- pro_tsheet.actual_cost
+ FROM drange_data1
+ left join pro_data on pro_data.pproject_id = drange_data1.project_id
+ left join tsheet_data1 on tsheet_data1.project_id=drange_data1.project_id and tsheet_data1.employee_id=drange_data1.employee_id
+ left join account_analytic_line AAL on AAL.project_id=tsheet_data1.project_id and AAL.employee_id=tsheet_data1.employee_id
+ and AAL.start_datetime >= drange_data1.start_date and AAL.end_datetime <= drange_data1.end_date
+ where pro_data.pricing_type = 'fixed_rate'
+ group by
+ drange_data1.start_date,
+ drange_data1.end_date,
+ drange_data1.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ --pro_tsheet.timesheet_id,
+ drange_data1.employee_id
+ --AAL.unit_amount,
+ --AAL.amount
),
-cons_no_limit1 as (SELECT
- coalesce(pro_tsheet.pro_sdate, pro_tsheet.t_startdate) as start_date,
- coalesce(pro_tsheet.pro_edate, pro_tsheet.t_enddate) as end_date,
- pro_tsheet.pproject_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
+data2 as (
+ SELECT
+ coalesce(pro_data.pro_sdate, drange_data1.start_date) as start_date,
+ coalesce(pro_data.pro_edate, drange_data1.end_date) as end_date,
+ drange_data1.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
null::char as role,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- null::int AS timesheet_id,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ --pro_tsheet.timesheet_id,
null::int AS employee_id,
0 as overall_budgeted_revenue,
- pro_tsheet.budgeted_revenue,
- pro_tsheet.budgeted_hours,
+ pro_data.budgeted_revenue,
+ pro_data.budgeted_hours,
0 as overall_hourly_rate,
- 0 as pro_hourly_rate,
- 0 as unit_amount,
+ 0 AS pro_hourly_rate,
+ 0 as unit_amount,
0 as timesheet_cost,
- 0 AS actual_revenue,
- 0 AS actual_cost,
- pro_tsheet.expenses_amt AS expenses_amt,
- 0 AS profit_amt,
- 0 AS profit_per
- from input_data
- left join pro_tsheet on pro_tsheet.project_id = input_data.project_id and pro_tsheet.employee_id = input_data.employee_id
- and coalesce(pro_tsheet.pro_sdate, pro_tsheet.min) >= input_data.start_date and pro_tsheet.t_enddate <= coalesce(pro_tsheet.pro_edate, pro_tsheet.max)
- WHERE pro_tsheet.pricing_type='employee_rate' and pro_tsheet.project_type='hours_no_limit'
+ 0.0 AS actual_revenue,
+ 0 as actual_cost,
+ pro_data.expenses_amt,
+ 0.0 AS profit_amt,
+ 0.0 AS profit_per
+ FROM drange_data1
+ left join pro_data on pro_data.pproject_id = drange_data1.project_id
+ WHERE pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_no_limit'
group by
- pro_tsheet.pro_sdate,
- pro_tsheet.pro_edate,
- pro_tsheet.t_startdate,
- pro_tsheet.t_enddate,
- pro_tsheet.pproject_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.budgeted_revenue,
- pro_tsheet.budgeted_hours,
- pro_tsheet.unit_amount,
- pro_tsheet.pro_hourly_rate,
- pro_tsheet.expenses_amt
- ),
-cons_no_limit2 as (
- SELECT
- input_data.start_date,
- input_data.end_date,
- input_data.project_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
+ drange_data1.start_date,
+ drange_data1.end_date,
+ pro_data.pro_sdate,
+ pro_data.pro_edate,
+ drange_data1.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ drange_data1.employee_id,
+ pro_data.budgeted_revenue,
+ pro_data.budgeted_hours,
+ pro_data.expenses_amt
+UNION
+SELECT
+ drange_data1.start_date,
+ drange_data1.end_date,
+ drange_data1.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
null::char as role,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.timesheet_id,
- input_data.employee_id,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ --pro_tsheet.timesheet_id,
+ drange_data1.employee_id,
0 as overall_budgeted_revenue,
- pro_tsheet.budgeted_revenue,
- pro_tsheet.budgeted_hours,
+ 0 as budgeted_revenue,
+ 0 as budgeted_hours,
0 as overall_hourly_rate,
- pro_tsheet.pro_hourly_rate,
- pro_tsheet.unit_amount,
- ((pro_tsheet.actual_cost)/NULLIF(pro_tsheet.unit_amount, 0)) as timesheet_cost,
- pro_tsheet.actual_revenue AS actual_revenue,
- pro_tsheet.actual_cost,
- pro_tsheet.expenses_amt AS expenses_amt,
- 0 AS profit_amt,
- 0 AS profit_per
- from input_data
- left join pro_tsheet on pro_tsheet.project_id = input_data.project_id and pro_tsheet.employee_id = input_data.employee_id
- and pro_tsheet.t_startdate >= input_data.start_date and pro_tsheet.t_enddate <= input_data.end_date
- WHERE pro_tsheet.pricing_type='employee_rate' and pro_tsheet.project_type='hours_no_limit'
+ pro_data.pro_hourly_rate,
+ AAL.unit_amount,
+ ((AAL.amount * -1)/NULLIF(AAL.unit_amount, 0)) as timesheet_cost,
+ (AAL.unit_amount * pro_data.pro_hourly_rate) AS actual_revenue,
+ (AAL.amount * -1) as actual_cost,
+ pro_data.expenses_amt AS expenses_amt,
+ 0.0 AS profit_amt,
+ 0.0 AS profit_per
+ FROM drange_data1
+ left join pro_data on pro_data.pproject_id = drange_data1.project_id
+ left join account_analytic_line AAL on AAL.project_id=drange_data1.project_id and AAL.employee_id=drange_data1.employee_id
+ and AAL.start_datetime >= drange_data1.start_date and AAL.end_datetime <= drange_data1.end_date
+ WHERE pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_no_limit'
group by
- input_data.start_date,
- input_data.end_date,
- input_data.project_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.timesheet_id,
- input_data.employee_id,
- pro_tsheet.budgeted_revenue,
- pro_tsheet.budgeted_hours,
- input_data.employee_id,
- pro_tsheet.unit_amount,
- pro_tsheet.pro_hourly_rate,
- pro_tsheet.actual_cost,
- pro_tsheet.actual_revenue,
- pro_tsheet.actual_cost,
- pro_tsheet.expenses_amt
+ drange_data1.start_date,
+ drange_data1.end_date,
+ pro_data.pro_sdate,
+ pro_data.pro_edate,
+ drange_data1.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ drange_data1.employee_id,
+ pro_data.pro_hourly_rate,
+ aal.unit_amount,
+ aal.amount,
+ pro_data.budgeted_revenue,
+ pro_data.budgeted_hours,
+ pro_data.expenses_amt
),
-hrs_in_cons as (
- SELECT
- input_data.start_date,
- input_data.end_date,
- input_data.project_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
- null::char as role,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.timesheet_id,
- input_data.employee_id,
- 0 as overall_budgeted_revenue,
- coalesce(cons_data.cons_budgeted_revenue, 0) as budgeted_revenue,
- coalesce(cons_data.cons_budgeted_hours, 0) as budgeted_hours,
- 0 as overall_hourly_rate,
- pro_tsheet.pro_hourly_rate,
- pro_tsheet.unit_amount,
- COALESCE(cons_data.cons_price, (pro_tsheet.unit_amount * cons_data.cons_price), 0) as timesheet_cost,
- COALESCE((pro_tsheet.unit_amount * cons_data.price_unit), 0) as actual_revenue,
- COALESCE(pro_tsheet.actual_cost, cons_data.cons_price, 0) as actual_cost,
- 0 AS expenses_amt,
- 0 AS profit_amt,
- 0 AS profit_per
- from input_data
- left join pro_tsheet on pro_tsheet.project_id = input_data.project_id and pro_tsheet.employee_id = input_data.employee_id
- and pro_tsheet.t_startdate >= input_data.start_date and pro_tsheet.t_enddate <= input_data.end_date
- left join cons_data on cons_data.project_id = input_data.project_id and cons_data.employee_id = input_data.employee_id
- and cons_data.cons_start_date >= input_data.start_date and cons_data.cons_end_date <= input_data.end_date
- WHERE pro_tsheet.pricing_type='employee_rate' and pro_tsheet.project_type='hours_in_consultant'
- --and budgeted_hours>0 and pro_tsheet.unit_amount > 0
- group by
- input_data.start_date,
- input_data.end_date,
- input_data.project_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.timesheet_id,
- input_data.employee_id,
- cons_data.cons_budgeted_revenue,
- cons_data.cons_budgeted_hours,
- input_data.employee_id,
- pro_tsheet.unit_amount,
- pro_tsheet.pro_hourly_rate,
- cons_data.cons_price,
- cons_data.price_unit,
- pro_tsheet.actual_cost,
- pro_tsheet.actual_revenue,
- pro_tsheet.actual_cost,
- pro_tsheet.expenses_amt
+data3 as (
+SELECT
+ drange_data1.start_date,
+ drange_data1.end_date,
+ drange_data1.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
+ cons_data1.role,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ drange_data1.employee_id,
+ 0 as overall_budgeted_revenue,
+ 0 as budgeted_revenue,
+ 0 as budgeted_hours,
+ 0 as overall_hourly_rate,
+ 0 as pro_hourly_rate,
+ AAL.unit_amount as unit_amount,
+ coalesce(((AAL.amount * -1)/NULLIF(AAL.unit_amount, 0)), cons_data1.cons_timesheet_cost) as timesheet_cost,
+ (AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) as actual_revenue,
+ coalesce((AAL.amount * -1), cons_data1.cons_timesheet_cost, 0) as actual_cost,
+ pro_data.expenses_amt as expenses_amt,
+ (AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)) as profit_amt,
+ ((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0))/NULLIF((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)),0)) * 100
+ as profit_per
+ FROM drange_data1
+ left join pro_data on pro_data.pproject_id = drange_data1.project_id
+ left join tsheet_data1 on tsheet_data1.project_id=drange_data1.project_id and tsheet_data1.employee_id=drange_data1.employee_id
+ left join cons_data1 on cons_data1.project_id=drange_data1.project_id and cons_data1.employee_id=drange_data1.employee_id
+ left join account_analytic_line AAL on AAL.project_id=tsheet_data1.project_id and AAL.employee_id=tsheet_data1.employee_id
+ and AAL.start_datetime >= drange_data1.start_date and AAL.end_datetime <= drange_data1.end_date
+ where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
+ group by
+ drange_data1.start_date,
+ drange_data1.end_date,
+ drange_data1.project_id,
+ drange_data1.employee_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
+ cons_data1.role,
+ pro_data.tag_name,
+ pro_data.pricing_type,
+ pro_data.partner_id,
+ pro_data.pro_hourly_rate,
+ pro_data.expenses_amt,
+ AAL.unit_amount,
+ AAL.amount,
+ cons_data1.cons_timesheet_cost,
+ cons_data1.cons_hourly_cost,
+ pro_data.budgeted_revenue,
+ pro_data.pro_hourly_rate
+UNION
+SELECT
+ drange_data2.start_date,
+ drange_data2.end_date,
+ drange_data2.project_id,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
+ cons_data1.role,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ drange_data2.employee_id,
+ 0 as overall_budgeted_revenue,
+ cons_data1.budgeted_revenue,
+ cons_data1.budgeted_hours,
+ pro_data.budgeted_revenue as overall_hourly_rate,
+ pro_data.pro_hourly_rate,
+ 0 as unit_amount,
+ 0 as timesheet_cost,
+ 0.0 as actual_revenue,
+ 0.0 as actual_cost,
+ pro_data.expenses_amt as expenses_amt,
+ 0.0 as profit_amt,
+ 0.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 cons_data1.start_date >= drange_data2.start_date and cons_data1.end_date <= drange_data2.end_date
+ where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
+ group by
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
+ cons_data1.role,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ drange_data2.start_date,
+ drange_data2.end_date,
+ drange_data2.project_id,
+ drange_data2.employee_id,
+ pro_data.budgeted_revenue,
+ pro_data.pro_hourly_rate,
+ cons_data1.budgeted_revenue,
+ cons_data1.budgeted_hours,
+ pro_data.expenses_amt
),
invoice_data as (SELECT
invoice_date.date as start_date,
invoice_date.date as end_date,
- --null::int as timesheet_id,
invoice_date.project_id,
- pro_tsheet.project_active,
- pro_tsheet.project_type,
- pro_tsheet.pricing_type,
- pro_tsheet.parent_project,
- pro_tsheet.is_sub_project,
- pro_tsheet.sub_project,
+ pro_data.project_active,
+ pro_data.project_type,
+ pro_data.pricing_type,
+ pro_data.parent_project,
+ pro_data.sub_project,
null::char as role,
- pro_tsheet.tag_name,
- pro_tsheet.partner_id,
- pro_tsheet.timesheet_id,
+ pro_data.tag_name,
+ pro_data.partner_id,
+ --pro_tsheet.timesheet_id,
invoice_date.employee_id,
0 as overall_budgeted_revenue,
0 as budgeted_revenue,
- pro_tsheet.budgeted_hours,
+ 0 as budgeted_hours,
0 as overall_hourly_rate,
0 as pro_hourly_rate,
0 as unit_amount,
@@ -353,49 +400,71 @@ invoice_data as (SELECT
0.0 AS profit_amt,
0.0 AS profit_per
from invoice_date
- left join pro_tsheet on pro_tsheet.project_id = invoice_date.project_id and pro_tsheet.employee_id = invoice_date.employee_id
- left join input_data on input_data.project_id = invoice_date.project_id and input_data.employee_id = invoice_date.employee_id
- and invoice_date.date >= input_data.start_date and invoice_date.date <= input_data.end_date),
-final_res as (
- select * from fixed_rate
- UNION
- select * from cons_no_limit1
- UNION
- select * from cons_no_limit2
- UNION
- select * from hrs_in_cons
- UNION
- select * from invoice_data
-)
- SELECT
- ROW_NUMBER() OVER() as id,
- start_date,
- end_date,
- project_id,
- project_active,
- project_type,
- pricing_type,
- parent_project,
- is_sub_project,
- sub_project,
- role,
- tag_name,
- partner_id,
- timesheet_id,
- employee_id,
- overall_budgeted_revenue,
- budgeted_revenue,
- budgeted_hours,
- overall_hourly_rate,
- pro_hourly_rate,
- unit_amount,
- timesheet_cost,
- actual_revenue,
- actual_cost,
- expenses_amt,
- profit_amt,
- profit_per
- from final_res
+ left join pro_data on pro_data.pproject_id = invoice_date.project_id --and pro_data.employee_id = invoice_date.employee_id
+ left join drange_data1 on invoice_date.project_id = drange_data1.project_id and invoice_date.employee_id = drange_data1.employee_id
+ and invoice_date.date >= drange_data1.start_date and invoice_date.date <= drange_data1.end_date
+ ),
+res as (
+select * from data1
+UNION
+select * from data2
+UNION
+select * from data3
+UNION
+select * from invoice_data
+)
+select
+ ROW_NUMBER() OVER() as id,
+ start_date,
+ end_date,
+ project_id,
+ project_active,
+ project_type,
+ pricing_type,
+ parent_project,
+ sub_project,
+ role,
+ tag_name,
+ partner_id,
+ employee_id,
+ overall_budgeted_revenue,
+ budgeted_revenue,
+ budgeted_hours,
+ overall_hourly_rate,
+ pro_hourly_rate,
+ unit_amount,
+ timesheet_cost,
+ actual_revenue,
+ actual_cost,
+ expenses_amt,
+ profit_amt,
+ profit_per
+ from res
+group by
+ start_date,
+ end_date,
+ project_id,
+ project_active,
+ project_type,
+ pricing_type,
+ parent_project,
+ sub_project,
+ role,
+ tag_name,
+ partner_id,
+ employee_id,
+ overall_budgeted_revenue,
+ budgeted_revenue,
+ budgeted_hours,
+ overall_hourly_rate,
+ pro_hourly_rate,
+ unit_amount,
+ timesheet_cost,
+ actual_revenue,
+ actual_cost,
+ expenses_amt,
+ profit_amt,
+ profit_per
)""" % (self._table,))
@api.model
diff --git a/project_report/report/project_revenue_custom_report3_views.xml b/project_report/report/project_revenue_custom_report3_views.xml
index 9f745db..94c7a15 100644
--- a/project_report/report/project_revenue_custom_report3_views.xml
+++ b/project_report/report/project_revenue_custom_report3_views.xml
@@ -76,7 +76,7 @@
-
+