Report timesheet id and date added

This commit is contained in:
root 2022-08-31 11:59:40 +05:30
parent 4ca38c471e
commit 6b3dea023d
2 changed files with 137 additions and 82 deletions

View File

@ -25,7 +25,7 @@ class ProjectRevenueCustomReport3(models.Model):
('hours_no_limit', 'Total hours are budgeted without division to consultant'),
], string="Project Type", readonly=True)
employee_id = fields.Many2one('hr.employee', string='Consultant', readonly=True)
#timesheet_sdatetime = fields.Datetime(string='Timesheet Start Time', readonly=True)
timesheet_sdatetime = fields.Datetime(string='Timesheet Start Time', readonly=True)
unit_amount = fields.Float('Timesheet Hours', digits=(16, 2))
timesheet_cost = fields.Float('Hourly Cost', digits=(16, 2))
profit_per = fields.Float(string='Profit (%)', digits=(16, 2))
@ -80,12 +80,12 @@ cons_data1 as (
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.budgeted_qty as budgeted_hours,
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
group by start_date, end_date, project_id, employee_id, role, budgeted_revenue, budgeted_hours, cons_timesheet_cost, cons_hourly_cost
),
tsheet_data1 as (
SELECT
@ -132,14 +132,15 @@ data1 as (
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
--pro_tsheet.timesheet_id,
drange_data1.employee_id,
AAL.id as timesheet_id,
AAL.start_datetime as timesheet_sdatetime,
0 as overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
0 as overall_hourly_rate,
0 AS pro_hourly_rate,
sum(AAL.unit_amount) as unit_amount,
0 AS pro_hourly_rate,
((sum(AAL.amount) * -1)/NULLIF(sum(AAL.unit_amount), 0)) as timesheet_cost,
0.0 AS actual_revenue,
(sum(AAL.amount) * -1) as actual_cost,
@ -150,7 +151,7 @@ data1 as (
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
and AAL.start_datetime::date >= drange_data1.start_date and AAL.end_datetime::date <= drange_data1.end_date
where pro_data.pricing_type = 'fixed_rate'
group by
drange_data1.start_date,
@ -163,16 +164,15 @@ data1 as (
AAL.sub_project,
pro_data.tag_name,
pro_data.partner_id,
--pro_tsheet.timesheet_id,
drange_data1.employee_id
--AAL.unit_amount,
--AAL.amount
drange_data1.employee_id,
AAL.id,
AAL.start_datetime
),
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,
pro_data.pproject_id,
pro_data.pproject_id as project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -181,14 +181,15 @@ data2 as (
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
--pro_tsheet.timesheet_id,
null::int AS employee_id,
null::int As timesheet_id,
null::timestamp as timesheet_sdatetime,
0 as overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
pro_data.budgeted_revenue,
pro_data.budgeted_hours,
0 as overall_hourly_rate,
pro_data.pro_hourly_rate,
0 as unit_amount,
0.0 AS pro_hourly_rate,
0 as timesheet_cost,
0.0 AS actual_revenue,
0 as actual_cost,
@ -196,14 +197,9 @@ data2 as (
0.0 AS profit_amt,
0.0 AS profit_per
FROM pro_data
--left join pro_data on pro_data.pproject_id = drange_data1.project_id
left 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'
group by
--drange_data1.start_date,
--drange_data1.end_date,
--pro_data.pro_sdate,
--pro_data.pro_edate,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
@ -212,9 +208,8 @@ data2 as (
sub_project,
pro_data.tag_name,
pro_data.partner_id,
--drange_data1.employee_id,
--pro_data.budgeted_revenue,
pro_data.pro_hourly_rate,
pro_data.budgeted_revenue,
pro_data.budgeted_hours,
pro_data.expenses_amt
UNION
SELECT
@ -229,24 +224,25 @@ SELECT
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
--pro_tsheet.timesheet_id,
drange_data1.employee_id,
AAL.id as timesheet_id,
AAL.start_datetime as timesheet_sdatetime,
0 as overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
0 as overall_hourly_rate,
pro_data.pro_hourly_rate,
AAL.unit_amount,
pro_data.pro_hourly_rate,
((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
0 AS expenses_amt,
((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 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
and AAL.start_datetime::date >= drange_data1.start_date and AAL.end_datetime::date <= drange_data1.end_date
WHERE pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_no_limit'
group by
drange_data1.start_date,
@ -262,55 +258,105 @@ SELECT
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.id,
AAL.start_datetime,
pro_data.pro_hourly_rate,
aal.unit_amount,
aal.amount,
--pro_data.budgeted_revenue,
pro_data.budgeted_hours,
pro_data.expenses_amt
),
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,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
pro_data.parent_project,
null::int as sub_project,
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
null::int AS employee_id,
pro_data.budgeted_revenue as overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
0 as overall_hourly_rate,
pro_data.pro_hourly_rate,
0 as unit_amount,
0 as timesheet_cost,
0.0 AS actual_revenue,
0 as actual_cost,
pro_data.expenses_amt,
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
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
group by
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
pro_data.parent_project,
--sub_project,
pro_data.tag_name,
pro_data.partner_id,
pro_data.budgeted_revenue,
pro_data.pro_hourly_rate,
pro_data.expenses_amt
UNION
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,
pro_data.pproject_id as project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
pro_data.parent_project,
null::int as sub_project,
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
null::int as employee_id,
null::int As timesheet_id,
null::timestamp as timesheet_sdatetime,
pro_data.budgeted_revenue AS overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
pro_data.pro_hourly_rate AS overall_hourly_rate,
0.0 as unit_amount,
0.0 as pro_hourly_rate,
0.0 as timesheet_cost,
0.0 as actual_revenue,
0.0 as actual_cost,
pro_data.expenses_amt,
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
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
group by
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.parent_project,
pro_data.budgeted_revenue,
pro_data.tag_name,
pro_data.pricing_type,
pro_data.partner_id,
pro_data.pro_hourly_rate,
pro_data.expenses_amt
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,
--AAL.sub_project,
null::int as sub_project,
cons_data1.role,
pro_data.tag_name,
pro_data.partner_id,
drange_data2.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,
0 as overall_hourly_rate,
0 as unit_amount,
0 as pro_hourly_rate,
0 as timesheet_cost,
0 as actual_revenue,
0 as actual_cost,
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 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
drange_data2.start_date,
drange_data2.end_date,
drange_data2.project_id,
drange_data2.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
UNION
SELECT
drange_data1.start_date,
drange_data1.end_date,
@ -324,12 +370,14 @@ SELECT
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.id as timesheet_id,
AAL.start_datetime as timesheet_sdatetime,
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,
0 as pro_hourly_rate,
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,
@ -342,13 +390,15 @@ SELECT
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
and AAL.start_datetime::date >= drange_data1.start_date and AAL.end_datetime::date <= 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,
AAL.id,
AAL.start_datetime,
pro_data.project_active,
pro_data.project_type,
pro_data.parent_project,
@ -378,14 +428,15 @@ invoice_data as (SELECT
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
--pro_tsheet.timesheet_id,
invoice_date.employee_id,
null::int As timesheet_id,
null::timestamp as timesheet_sdatetime,
0 as overall_budgeted_revenue,
0 as budgeted_revenue,
0 as budgeted_hours,
0 as overall_hourly_rate,
0 as pro_hourly_rate,
0 as unit_amount,
0 as pro_hourly_rate,
0 as timesheet_cost,
invoice_date.fixed_amount as actual_revenue,
0 as actual_cost,
@ -420,12 +471,14 @@ select
tag_name,
partner_id,
employee_id,
timesheet_id,
timesheet_sdatetime,
overall_budgeted_revenue,
budgeted_revenue,
budgeted_hours,
overall_hourly_rate,
pro_hourly_rate,
unit_amount,
pro_hourly_rate,
timesheet_cost,
actual_revenue,
actual_cost,
@ -446,12 +499,14 @@ group by
tag_name,
partner_id,
employee_id,
timesheet_id,
timesheet_sdatetime,
overall_budgeted_revenue,
budgeted_revenue,
budgeted_hours,
overall_hourly_rate,
pro_hourly_rate,
unit_amount,
pro_hourly_rate,
timesheet_cost,
actual_revenue,
actual_cost,

View File

@ -8,17 +8,17 @@
<pivot string="Revenue Analysis" disable_linking="True" sample="1">
<field name="project_id" type="row"/>
<field name="overall_budgeted_revenue" type="measure"/>
<field name="budgeted_hours" type="measure"/>
<field name="budgeted_revenue" type="measure"/>
<field name="overall_hourly_rate" type="measure"/>
<field name="timesheet_cost" type="measure"/>
<field name="pro_hourly_rate" type="measure"/>
<field name="unit_amount" widget="float_time" type="measure"/>
<field name="actual_revenue" type="measure"/>
<field name="actual_cost" type="measure"/>
<field name="budgeted_hours" type="measure"/>
<field name="overall_hourly_rate" type="measure"/>
<field name="pro_hourly_rate" type="measure"/>
<field name="expenses_amt" type="measure"/>
<field name="profit_amt" type="measure"/>
<field name="profit_per" type="measure"/>
<field name="unit_amount" widget="float_time" type="measure"/>
<field name="timesheet_cost" type="measure"/>
</pivot>
</field>
</record>