From 130f1504d46e7884f4c810e15377551cc7150956 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 5 Sep 2022 13:43:47 +0530 Subject: [PATCH] Timezone related issue in report fixed --- cor_custom/models/project.py | 16 ++++++++---- .../report/project_revenue_custom_report3.py | 26 ++++++++++++------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/cor_custom/models/project.py b/cor_custom/models/project.py index e810341..e44dd27 100755 --- a/cor_custom/models/project.py +++ b/cor_custom/models/project.py @@ -2,7 +2,8 @@ from odoo import api, fields, models, _ from odoo.exceptions import UserError, AccessError, ValidationError - +import datetime +from pytz import timezone, UTC class Project(models.Model): _inherit = 'project.project' @@ -362,12 +363,17 @@ class InheritProjectProductEmployeeMap(models.Model): for val in self: date_clause = "" query_params = [val.project_id._origin.id, val.employee_id.id] + #tz = self.env.user.tz if val.start_date: - date_clause += "and start_datetime::date >= %s" - query_params.append(val.start_date) + s_datetime = datetime.datetime.combine(val.start_date, datetime.time(00, 00)) + #s_datetime1 = timezone(tz).localize(s_datetime).astimezone(UTC) + date_clause += "and start_datetime at time zone 'utc' at time zone (select tz from res_partner where id=3) >= %s" + query_params.append(s_datetime) if val.end_date: - date_clause += " and end_datetime::date <= %s" - query_params.append(val.end_date) + e_datetime = datetime.datetime.combine(val.end_date, datetime.time(23, 59, 59)) + #e_datetime1 = timezone(tz).localize(e_datetime).astimezone(UTC) + date_clause += " and end_datetime at time zone 'utc' at time zone (select tz from res_partner where id=3) <= %s" + query_params.append(e_datetime) query = """SELECT project_id, employee_id, SUM(unit_amount) FROM account_analytic_line where project_id = %s and employee_id = %s {date_clause} GROUP BY project_id, employee_id""".format(date_clause=date_clause) diff --git a/project_report/report/project_revenue_custom_report3.py b/project_report/report/project_revenue_custom_report3.py index 4e3139d..c1048c0 100644 --- a/project_report/report/project_revenue_custom_report3.py +++ b/project_report/report/project_revenue_custom_report3.py @@ -11,6 +11,7 @@ class ProjectRevenueCustomReport3(models.Model): _auto = False start_date = fields.Date(string='Start Date', readonly=True) + #start_datetime = fields.Datetime(string='Start Datetime111111111', readonly=True) end_date = fields.Date(string='End Date', readonly=True) project_id = fields.Many2one('project.project', string='Project', readonly=True) parent_project = fields.Many2one('project.project', string='Parent Project', readonly=True) @@ -151,7 +152,10 @@ 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::date >= drange_data1.start_date and AAL.end_datetime::date <= drange_data1.end_date + 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 where pro_data.pricing_type = 'fixed_rate' group by drange_data1.start_date, @@ -242,7 +246,10 @@ SELECT 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::date >= drange_data1.start_date and AAL.end_datetime::date <= drange_data1.end_date + 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 WHERE pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_no_limit' group by drange_data1.start_date, @@ -340,7 +347,6 @@ SELECT 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 and drange_data2.start_date >= cons_data1.start_date and drange_data2.end_date <= cons_data1.end_date where pro_data.pricing_type='employee_rate' and pro_data.project_type='hours_in_consultant' group by @@ -381,24 +387,26 @@ SELECT 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, case when cons_data1.cons_timesheet_cost is null then (AAL.amount * -1) else (AAL.unit_amount * cons_data1.cons_timesheet_cost) end as actual_cost, 0 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)) - case when cons_data1.cons_timesheet_cost is null 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))/NULLIF((AAL.unit_amount * COALESCE(cons_data1.cons_hourly_cost, 0)),0)) * 100 - --as profit_per, (((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::date >= drange_data1.start_date and AAL.end_datetime::date <= drange_data1.end_date + 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::date >= cons_data1.start_date and AAL.end_datetime::date <= cons_data1.end_date + 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' group by drange_data1.start_date,