Report budgeted qty and amt updated not based on date

This commit is contained in:
root 2022-10-21 11:19:49 +05:30
parent 01370f96e5
commit 802b029e15
2 changed files with 30 additions and 44 deletions

View File

@ -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 = []

View File

@ -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)