diff --git a/project_report/report/project_budget_amt_analysis.py b/project_report/report/project_budget_amt_analysis.py index 8b33fc6..fee3449 100755 --- a/project_report/report/project_budget_amt_analysis.py +++ b/project_report/report/project_budget_amt_analysis.py @@ -77,6 +77,25 @@ class BudgetAmtAnalysis(models.Model): LEFT JOIN account_analytic_line AAL ON AAL.account_id = AA.id and AAL.project_id = PRO.id and AAL.employee_id = pro_emp.employee_id WHERE PRO.active = 't' and AAL.employee_id is not null and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_in_consultant' group by pro.id, aal.employee_id, aal.date, aal.start_datetime, pro_emp.employee_price + union + SELECT + pro.id AS project_id, + (select project_id from project_subproject_rel as par where pro.id=par.id limit 1) as parentproject, + pro.date_start AS start_date, + pro.date AS end_date, + pro.partner_id AS partner_id, + AAL.employee_id AS employee_id, + 'Actual Cost' as amount_type, + pro.pricing_type as pricing_type, + pro.project_type as project_type, + AAL.date AS timesheet_date, + AAL.start_datetime AS timesheet_sdatetime, + (sum(AAL.unit_amount) * pro.budgeted_hours2) AS revenue + 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 + WHERE PRO.active = 't' and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_no_limit' + group by pro.id, aal.employee_id, aal.date, aal.unit_amount, aal.start_datetime union SELECT pro.id AS project_id, @@ -101,20 +120,19 @@ class BudgetAmtAnalysis(models.Model): pro.date_start AS start_date, pro.date AS end_date, pro.partner_id AS partner_id, - null::int AS employee_id, + AAL.employee_id AS employee_id, 'Actual Revenue' as amount_type, pro.pricing_type as pricing_type, pro.project_type as project_type, - null::date AS timesheet_date, - null::timestamp with time zone AS timesheet_sdatetime, - (pro.hourly_rate * pro.timesheet_hour) AS revenue + AAL.date AS timesheet_date, + AAL.start_datetime AS timesheet_sdatetime, + (sum(AAL.unit_amount) * EMP.timesheet_cost) AS revenue FROM project_project PRO - --Left JOIN project_sale_line_employee_map pro_emp ON pro_emp.project_id = pro.id - --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 - --and AAL.employee_id = pro_emp.employee_id + 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 hr_employee EMP ON AAL.employee_id = EMP.id WHERE PRO.active = 't' and PRO.pricing_type = 'employee_rate' and PRO.project_type = 'hours_no_limit' - --group by pro.id + group by pro.id, aal.employee_id, aal.date, aal.start_datetime, aal.unit_amount, emp.timesheet_cost union SELECT pro.id AS project_id,