This commit is contained in:
pawan.sharma 2022-09-29 11:24:41 +05:30
commit 35d6df63e9
4 changed files with 46 additions and 66 deletions

View File

@ -6,7 +6,7 @@
<field name="model">project.revenue.custom.report2</field>
<field name="arch" type="xml">
<pivot string="Revenue Analysis" disable_linking="True" sample="1">
<field name="project_id" type="row"/>
<field name="project_id"/>
<field name="overall_budgeted_revenue" type="measure"/>
<field name="budgeted_revenue" type="measure"/>
<field name="actual_revenue" type="measure"/>

View File

@ -76,9 +76,9 @@ with pro_data as (
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,
date_trunc('month', coalesce(max(PRO_EMP.end_date), current_date AT TIME ZONE 'UTC')) AS max,
PRO_EMP.start_date as start_date,
coalesce(PRO_EMP.end_date, current_date) as end_date,
coalesce(PRO_EMP.end_date, current_date AT TIME ZONE 'UTC') as end_date,
PRO_EMP.project_id,
PRO_EMP.employee_id,
PRO_EMP.role,
@ -123,9 +123,9 @@ invoice_date as (
),
data1 as (
SELECT
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
TO_CHAR(start_datetime, 'YYYY-MM-01')::date as start_date,
(date_trunc('month', end_datetime) + interval '1 month' - interval '1 day')::date as end_date,
pro_data.pproject_id as project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -134,7 +134,7 @@ data1 as (
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.employee_id,
AAL.id as timesheet_id,
AAL.start_datetime as timesheet_sdatetime,
0 as overall_budgeted_revenue,
@ -149,19 +149,11 @@ data1 as (
0.0 AS expenses_amt,
(0.0 - (sum(AAL.amount) * -1)) 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 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 at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= drange_data1.start_date::date + '00:00:00'::time
and AAL.end_datetime at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= drange_data1.end_date::date + '23:59:59'::time
FROM pro_data
left join account_analytic_line AAL on AAL.project_id=pro_data.pproject_id
where pro_data.pricing_type = 'fixed_rate' and COALESCE(pro_data.is_sub_project, FALSE) = False
group by
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -169,7 +161,7 @@ data1 as (
AAL.sub_project,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.employee_id,
AAL.id,
AAL.start_datetime
),
@ -218,9 +210,9 @@ data2 as (
pro_data.expenses_amt
UNION
SELECT
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
TO_CHAR(start_datetime, 'YYYY-MM-01')::date as start_date,
(date_trunc('month', end_datetime) + interval '1 month' - interval '1 day')::date as end_date,
pro_data.pproject_id as project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -229,35 +221,28 @@ SELECT
null::char as role,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.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,
AAL.unit_amount,
pro_data.pro_hourly_rate,
AAL.unit_amount as unit_amount,
pro_data.pro_hourly_rate as 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,
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 at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= drange_data1.start_date::date + '00:00:00'::time
and AAL.end_datetime at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= drange_data1.end_date::date + '23:59:59'::time
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_no_limit' and COALESCE(pro_data.is_sub_project, FALSE) = False
group by
drange_data1.start_date,
drange_data1.end_date,
pro_data.pro_sdate,
pro_data.pro_edate,
drange_data1.project_id,
pro_data.pproject_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -265,12 +250,12 @@ SELECT
AAL.sub_project,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.employee_id,
AAL.id,
AAL.start_datetime,
pro_data.pro_hourly_rate,
aal.unit_amount,
aal.amount,
AAL.unit_amount,
AAL.amount,
pro_data.budgeted_hours,
pro_data.expenses_amt
),
@ -366,9 +351,9 @@ SELECT
pro_data.partner_id
UNION
SELECT
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
TO_CHAR(start_datetime, 'YYYY-MM-01')::date as start_date,
(date_trunc('month', end_datetime) + interval '1 month' - interval '1 day')::date as end_date,
pro_data.pproject_id as project_id,
pro_data.project_active,
pro_data.project_type,
pro_data.pricing_type,
@ -377,7 +362,7 @@ SELECT
cons_data1.role,
pro_data.tag_name,
pro_data.partner_id,
drange_data1.employee_id,
AAL.employee_id,
AAL.id as timesheet_id,
AAL.start_datetime as timesheet_sdatetime,
0 as overall_budgeted_revenue,
@ -395,25 +380,18 @@ SELECT
then (AAL.amount * -1) else (AAL.unit_amount * cons_data1.cons_timesheet_cost) end as profit_amt,
(((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 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 at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= drange_data1.start_date::date + '00:00:00'::time
and AAL.end_datetime at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= drange_data1.end_date::date + '23:59:59'::time
left join cons_data1 on cons_data1.project_id=drange_data1.project_id and cons_data1.employee_id=drange_data1.employee_id
and AAL.start_datetime at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= cons_data1.start_date::date + '00:00:00'::time
and AAL.end_datetime at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= cons_data1.end_date::date + '23:59:59'::time
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant' and COALESCE(pro_data.is_sub_project, FALSE) = False
FROM pro_data
left 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 --at time zone 'utc' at time zone (select tz from res_partner where id=3)
>= cons_data1.start_date::date + '00:00:00'::time AT TIME ZONE 'UTC'
and AAL.end_datetime --at time zone 'utc' at time zone (select tz from res_partner where id=3)
<= cons_data1.end_date::date + '23:59:59'::time AT TIME ZONE 'UTC'
where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant'
and COALESCE(pro_data.is_sub_project, FALSE) = False
group by
drange_data1.start_date,
drange_data1.end_date,
drange_data1.project_id,
drange_data1.employee_id,
pro_data.pproject_id,
AAL.employee_id,
AAL.id,
AAL.start_datetime,
pro_data.project_active,
@ -458,8 +436,8 @@ invoice_data as (SELECT
0.0 AS profit_per
from invoice_date
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
--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

View File

@ -6,7 +6,7 @@
<field name="model">project.revenue.custom.report3</field>
<field name="arch" type="xml">
<pivot string="Revenue Analysis" disable_linking="True" sample="1">
<field name="project_id" type="row"/>
<field name="project_id"/>
<field name="overall_budgeted_revenue" type="measure"/>
<field name="budgeted_revenue" type="measure"/>
<field name="actual_revenue" type="measure"/>
@ -57,6 +57,7 @@
<field name="timesheet_cost"/>
<field name="start_date"/>
<field name="end_date"/>
<field name="timesheet_sdatetime"/>
</tree>
</field>
</record>
@ -107,9 +108,10 @@
<field name="res_model">project.revenue.custom.report3</field>
<field name="view_mode">pivot,tree,graph</field>
<field name="search_view_id" ref="project_revenue_custom_report3_view_search"/>
<field name="context">{'search_default_group_project': 1, 'search_default_group_employee': 1,
<field name="context">{}</field>
<!--<field name="context">{'search_default_group_project': 1, 'search_default_group_employee': 1,
'search_default_group_enddate': 1}
</field>
</field>-->
</record>

View File

@ -10,10 +10,10 @@
<div name="button_box" position="inside">
<button class="oe_stat_button" type="object" name="action_view_allocation_custom_report3"
icon="fa-tasks"
attrs="{'invisible':['|',('pricing_type','!=','employee_rate'),('project_type','!=','hours_in_consultant')]}"
string="View Allocation" widget="statinfo">
</button>
</div>
<!--attrs="{'invisible':['|',('pricing_type','!=','employee_rate'),('project_type','!=','hours_in_consultant')]}"-->
<!--<div name="button_box" position="inside">
<button class="oe_stat_button" type="action" name="%(project_report.project_project_action_multi_create_project_expense)d" icon="fa-usd"
attrs="{'invisible': [('allow_billable','=',False)]}" string="Create Expense" widget="statinfo">