New timesheet report added

This commit is contained in:
projectsodoo 2021-03-05 10:18:35 +05:30
parent 128ce82d23
commit 4a6d324fec
5 changed files with 142 additions and 1 deletions

View File

@ -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",

View File

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

View File

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

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="project_timesheet_report_view_tree" model="ir.ui.view">
<field name="name">project.timesheet.report.tree</field>
<field name="model">project.timesheet.report</field>
<field name="arch" type="xml">
<tree string="Timesheet Report" create="false" edit="false" delete="false">
<field name="start_date"/>
<field name="employee_id"/>
<field name="project_id"/>
<field name="task_id"/>
<field name="duration" widget="float_time"/>
<field name="timestamp"/>
<field name="sub_project" widget="many2many_tags"/>
<field name="description"/>
</tree>
</field>
</record>
<record id="project_timesheet_report_view_search" model="ir.ui.view">
<field name="name">project.timesheet.report.search</field>
<field name="model">project.timesheet.report</field>
<field name="arch" type="xml">
<search string="Timesheet Report">
<field name="project_id"/>
<field name="employee_id"/>
<field name="start_date"/>
<field name="task_id"/>
<group expand="1" string="Group By">
<filter string="Project" name="project" context="{'group_by':'project_id'}"/>
<filter string="Employee" name="employee" context="{'group_by':'employee_id'}"/>
<filter string="Start Date" name="sdate" domain="[]" context="{'group_by':'start_date:month'}"/>
<filter string="Task" name="task" context="{'group_by':'task_id'}"/>
</group>
</search>
</field>
</record>
<record id="project_timesheet_report_view_action" model="ir.actions.act_window">
<field name="name">Timesheets Report</field>
<field name="res_model">project.timesheet.report</field>
<field name="view_mode">tree</field>
<field name="search_view_id" ref="project_timesheet_report_view_search"/>
<field name="context">{}</field>
</record>
<menuitem id="menu_project_timesheets_report"
parent="hr_timesheet.menu_timesheets_reports_timesheet"
action="project_timesheet_report_view_action"
name="Timesheets Report"
sequence="50"/>
</odoo>

View File

@ -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
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
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
6 access_project_budget_amt_report_user project.budget.amt.report.user model_project_budget_amt_report project.group_project_user 1 0 0 0
7 access_project_create_expense_user access_project_create_expense_project_user model_project_create_expense project.group_project_user 1 0 0 0
8 access_project_timeline_report_manager project.timeline.report model_project_timeline_report project.group_project_manager 1 1 1 1
9 access_project_timeline_report_user project.timeline.report model_project_timeline_report project.group_project_user 1 0 0 0
10 access_project_timesheet_report_manager project.timesheet.report model_project_timesheet_report project.group_project_manager 1 1 1 1
11 access_project_timesheet_report_user project.timesheet.report model_project_timesheet_report project.group_project_user 1 0 0 0