From 4a6d324feca05f1eef232ef0ed61cc8f92a07068 Mon Sep 17 00:00:00 2001 From: projectsodoo Date: Fri, 5 Mar 2021 10:18:35 +0530 Subject: [PATCH] New timesheet report added --- project_report/__manifest__.py | 1 + project_report/report/__init__.py | 1 + .../report/project_timesheet_report.py | 81 +++++++++++++++++++ .../report/project_timesheet_report_views.xml | 56 +++++++++++++ project_report/security/ir.model.access.csv | 4 +- 5 files changed, 142 insertions(+), 1 deletion(-) create mode 100755 project_report/report/project_timesheet_report.py create mode 100755 project_report/report/project_timesheet_report_views.xml diff --git a/project_report/__manifest__.py b/project_report/__manifest__.py index 549e4b3..8cae31e 100755 --- a/project_report/__manifest__.py +++ b/project_report/__manifest__.py @@ -20,6 +20,7 @@ 'report/project_budget_hrs_analysis_views.xml', 'report/project_budget_amt_analysis_views.xml', 'report/project_timeline_report_views.xml', + 'report/project_timesheet_report_views.xml', ], 'qweb': [ "static/src/xml/base.xml", diff --git a/project_report/report/__init__.py b/project_report/report/__init__.py index 643d4d2..d635724 100755 --- a/project_report/report/__init__.py +++ b/project_report/report/__init__.py @@ -4,3 +4,4 @@ from . import project_budget_hrs_analysis from . import project_budget_amt_analysis from . import project_timeline_report +from . import project_timesheet_report diff --git a/project_report/report/project_timesheet_report.py b/project_report/report/project_timesheet_report.py new file mode 100755 index 0000000..bfe6d40 --- /dev/null +++ b/project_report/report/project_timesheet_report.py @@ -0,0 +1,81 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models, tools, api +from datetime import datetime, time, timedelta +from odoo.tools.float_utils import float_round + +class ProjectTimelineReport(models.Model): + + _name = "project.timesheet.report" + _description = "Project Timesheet Report" + _order = 'start_date desc, project_id desc' + _auto = False + + start_date = fields.Date(string='Start Date', readonly=True) + employee_id = fields.Many2one('hr.employee', string='Employee', readonly=True) + project_id = fields.Many2one('project.project', string='Project', readonly=True) + #sub_project = fields.Many2one('project.project', string='Sub Project', readonly=True) + duration = fields.Float('Duration', readonly=True) + timestamp = fields.Char('Timestamp', readonly=True) + task_id = fields.Many2one('project.task', string='Task', readonly=True) + description = fields.Char('Description', readonly=True) + sub_project = fields.Many2many('project.project', compute='_compute_related_subproject') + + @api.depends('project_id') + def _compute_related_subproject(self): + for val in self: + val.sub_project = val.project_id.sub_project.ids + + @api.model + def export_data(self, fields): + index = range(len(fields)) + fields_name = dict(zip(fields, index)) + res = super(ProjectTimelineReport, self).export_data(fields) + for index, val in enumerate(res['datas']): + if fields_name.get('start_date') is not None: + tdateindex = fields_name.get('start_date') + tdate = res['datas'][index][tdateindex] + if tdate: + res['datas'][index][tdateindex] = datetime.strftime(tdate, "%d/%m/%Y") + if fields_name.get('task_id') is not None: + taskindex = fields_name.get('task_id') + ttask = res['datas'][index][taskindex] + if type(ttask) == bool: + res['datas'][index][taskindex] = '' + if fields_name.get('project_id') is not None: + projectindex = fields_name.get('project_id') + project = res['datas'][index][projectindex] + if type(project) == bool: + res['datas'][index][projectindex] = '' + if fields_name.get('sub_project') is not None: + subindex = fields_name.get('sub_project') + subproject = res['datas'][index][subindex] + if type(subproject) == bool: + res['datas'][index][subindex] = '' + if fields_name.get('duration') is not None: + durationindex = fields_name.get('duration') + duration = res['datas'][index][durationindex] and float(res['datas'][index][durationindex]) + if duration: + duration_time = tools.format_duration(duration) + res['datas'][index][durationindex] = duration_time + return res + + def init(self): + '''Create the view''' + tools.drop_view_if_exists(self._cr, self._table) + self._cr.execute(""" + CREATE OR REPLACE VIEW %s AS ( + SELECT + ROW_NUMBER() OVER() as id, + start_datetime::date as start_date, + employee_id, + project_id, + unit_amount as duration, + CONCAT(to_char(start_datetime at time zone 'utc', 'HH24:MI'), '-', to_char(end_datetime at time zone 'utc', 'HH24:MI')) as timestamp, + task_id, + name as description + from account_analytic_line + )""" % (self._table,)) + + diff --git a/project_report/report/project_timesheet_report_views.xml b/project_report/report/project_timesheet_report_views.xml new file mode 100755 index 0000000..09ad54b --- /dev/null +++ b/project_report/report/project_timesheet_report_views.xml @@ -0,0 +1,56 @@ + + + + + + project.timesheet.report.tree + project.timesheet.report + + + + + + + + + + + + + + + + + project.timesheet.report.search + project.timesheet.report + + + + + + + + + + + + + + + + + + Timesheets Report + project.timesheet.report + tree + + {} + + + + + diff --git a/project_report/security/ir.model.access.csv b/project_report/security/ir.model.access.csv index f653d5a..d29c722 100755 --- a/project_report/security/ir.model.access.csv +++ b/project_report/security/ir.model.access.csv @@ -6,4 +6,6 @@ access_project_budget_hrs_report_user,project.budget.hrs.report.user,model_proje access_project_budget_amt_report_user,project.budget.amt.report.user,model_project_budget_amt_report,project.group_project_user,1,0,0,0 access_project_create_expense_user,access_project_create_expense_project_user,model_project_create_expense,project.group_project_user,1,0,0,0 access_project_timeline_report_manager,project.timeline.report,model_project_timeline_report,project.group_project_manager,1,1,1,1 -access_project_timeline_report_user,project.timeline.report,model_project_timeline_report,project.group_project_user,1,0,0,0 \ No newline at end of file +access_project_timeline_report_user,project.timeline.report,model_project_timeline_report,project.group_project_user,1,0,0,0 +access_project_timesheet_report_manager,project.timesheet.report,model_project_timesheet_report,project.group_project_manager,1,1,1,1 +access_project_timesheet_report_user,project.timesheet.report,model_project_timesheet_report,project.group_project_user,1,0,0,0 \ No newline at end of file