Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10.0-BR001143-T23294-timesheet_activity_report #191

Open
wants to merge 4 commits into
base: 10.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion timesheet_activity_report/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ Contributors

* Eric Caudal <[email protected]>
* Sébastien Maillard <[email protected]>



Maintainer
----------

.. image:: https://www.elico-corp.com/logo.png
:alt: Elico Corp
:target: https://www.elico-corp.com

This module is maintained by Elico Corporation.

Expand Down
2 changes: 1 addition & 1 deletion timesheet_activity_report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Elico corp (www.elico-corp.com)
# Copyright 2015-2017 Elico corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import report
13 changes: 7 additions & 6 deletions timesheet_activity_report/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# -*- coding: utf-8 -*-
# © 2015 Elico corp (www.elico-corp.com)
# Copyright 2015-2017 Elico corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Timesheet Activities Report',
'version': '10.0.1.1.0',
'category': 'Human Resources',
'depends': [
'project_timesheet',
'hr_timesheet',
'project_issue_sheet',
'business_requirement_deliverable_project',
'project_task_category'
'project_project_category',
'project_task_category',
],
'author': 'Elico Corp',
'support': '[email protected]',
'license': 'AGPL-3',
'website': 'https://www.elico-corp.com',
'data': [
'report/timesheet_activity_report_view.xml',
'security/ir.model.access.csv',
'report/timesheet_activity_report_view.xml',
],
'installable': False,
'application': False
'installable': True,
'application': True
}
2 changes: 1 addition & 1 deletion timesheet_activity_report/report/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# © 2015 Elico corp (www.elico-corp.com)
# Copyright 2015-2017 Elico corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import timesheet_activity_report
239 changes: 148 additions & 91 deletions timesheet_activity_report/report/timesheet_activity_report.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# © 2015 Elico corp (www.elico-corp.com)
# Copyright 2015-2017 Elico corp (https://www.elico-corp.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, fields, tools
from odoo import api, models, fields, tools


class TimesheetReport(models.Model):
Expand All @@ -16,106 +16,163 @@ class TimesheetReport(models.Model):
# Field used for the Name
_rec_name = 'activity_name'

id = fields.Integer('Id', readonly=True)
id = fields.Integer(
'Id',
readonly=True
)
activity_type = fields.Selection(
[
('task', 'Task'),
('issue', 'Issue'),
('timesheet', 'Timesheet'),
], 'Type', readonly=True,
help="Type is based on the origin of the input (Task, Issue or "
"Timesheet Activities)")
description = fields.Char('Description', readonly=True)
[('task', 'Task'),
('issue', 'Issue'),
('timesheet', 'Timesheet'),
],
'Type',
readonly=True,
help="""Type is based on the origin of the input (Task, Issue or
Timesheet Activities)"""
)
description = fields.Char(
'Description',
readonly=True
)
hours = fields.Float(
'Time spent', digits=(16, 2), readonly=True,
help="Time spent on timesheet")
user_id = fields.Many2one('res.users', 'User', readonly=True)
product_id = fields.Many2one('product.product', 'Product', readonly=True)
date = fields.Date('Date', readonly=True)
project_id = fields.Many2one('project.project', 'Project', readonly=True)
project_state = fields.Char('State', readonly=True, help="Project State")
'Time spent',
digits=(16, 2),
readonly=True,
help="Time spent on timesheet"
)
user_id = fields.Many2one(
'res.users',
'User',
readonly=True
)
product_id = fields.Many2one(
'product.product',
'Product',
readonly=True
)
date = fields.Date(
'Date',
readonly=True
)
project_id = fields.Many2one(
'project.project',
'Project',
readonly=True
)
activity_stage_id = fields.Many2one(
'project.task.type', 'Stage',
readonly=True, help="Activity Stage")
'project.task.type',
'Stage',
readonly=True,
help="Activity Stage"
)
account_id = fields.Many2one(
'account.analytic.account', 'Analytic account', readonly=True)
'account.analytic.account',
'Analytic account',
readonly=True
)
activity_id = fields.Char(
'Activity id', readonly=True, help="Task id or Issue id")
'Activity id',
readonly=True,
help="Task id or Issue id"
)
activity_name = fields.Char(
'Activity name', readonly=True, help="Task name or Issue name")
'Activity name',
readonly=True,
help="Task name or Issue name"
)
categ_id = fields.Many2one(
'project.category.main', 'Task Cat.',
readonly=True, help="Task Category")
'project.category',
'Task Cat.',
readonly=True,
help="Task Category"
)
br_id = fields.Many2one(
'business.requirement', 'Bus. requ.',
readonly=True, help="Business requirement")
'business.requirement',
'Bus. requ.',
readonly=True,
help="Business requirement"
)
partner_id = fields.Many2one(
'res.partner', 'Customer', readonly=True)
'res.partner',
'Customer',
readonly=True
)
project_categ_id = fields.Many2one(
'project.project.category',
'Project Cat.', readonly=True, help="Project Category")
'Project Cat.',
readonly=True,
help="Project Category"
)

def init(self, cr):
def _select(self):
select_str = """
SELECT
ts.id,
-- Check if the timesheet is linked to a task
-- or an issue
CASE WHEN (select id from project_task where id = al.task_id)
IS NOT NULL THEN 'task'
ELSE (
CASE WHEN (select id from project_issue where id =
al.issue_id) IS NOT NULL THEN 'issue'
-- Timesheet created in the timesheet
-- activities panel
ELSE (
CASE WHEN al.id IS NOT NULL THEN 'timesheet'
-- No timesheet attached to this
-- task/project/BR
ELSE NULL
END
)
END
)
END AS activity_type,
-- Description from the task first
-- because the one in the timesheet
-- is wrong when it's linked to a task
COALESCE((select name from project_task where id =
al.task_id), al.name) AS description,
al.unit_amount AS hours,
al.user_id,
al.product_id,
al.date,
al.project_id,
COALESCE((select stage_id from project_task where id =
al.task_id), (select stage_id from project_issue where id =
al.issue_id)) AS activity_stage_id,
COALESCE(a.id, al.account_id) AS account_id,
COALESCE((select id from project_task where id = al.task_id),
(select id from project_issue where id = al.issue_id))
AS activity_id,
COALESCE((select name from project_task where id =
al.task_id), (select name from project_issue where id =
al.issue_id)) AS activity_name,
(select categ_id from project_task where id =
al.task_id) AS categ_id,
b.id AS br_id,
a.partner_id,
(select project_categ_id from project_project where id =
al.project_id)
"""
Timesheet Activities Report.
return select_str

def _from(self):
from_str = """
hr_timesheet_sheet_sheet ts
LEFT OUTER JOIN account_analytic_line al
ON ts.id = al.sheet_id
LEFT OUTER JOIN account_analytic_account a
ON a.id = al.account_id
LEFT OUTER JOIN business_requirement b
ON b.id = (select business_requirement_id from project_project
where id = al.project_id)
"""
tools.drop_view_if_exists(cr, 'timesheet_activity_report')
cr.execute("""
CREATE OR REPLACE VIEW timesheet_activity_report AS (
SELECT
ts.id,
-- Check if the timesheet is linked to a task
-- or an issue
CASE WHEN tw.id IS NOT NULL THEN 'task'
ELSE (
CASE WHEN i.id IS NOT NULL THEN 'issue'
-- Timesheet created in the timesheet
-- activities panel
ELSE (
CASE WHEN ts.id IS NOT NULL THEN 'timesheet'
-- No timesheet attached to this
-- task/project/BR
ELSE NULL
END
)
END
)
END AS activity_type,
-- Description from the task first
-- because the one in the timesheet
-- is wrong when it's linked to a task
COALESCE(tw.name, al.name) AS description,
al.unit_amount AS hours,
al.user_id,
al.product_id,
al.date,
p.id AS project_id,
p.state AS project_state,
COALESCE(t.stage_id, i.stage_id) AS activity_stage_id,
COALESCE(a.id, al.account_id) AS account_id,
COALESCE(t.id, i.id) AS activity_id,
COALESCE(t.name, i.name) AS activity_name,
t.categ_id,
b.id AS br_id,
a.partner_id,
p.project_categ_id
FROM
hr_analytic_timesheet ts
INNER JOIN account_analytic_line al
ON al.id = ts.line_id
-- Link with the task
LEFT OUTER JOIN project_task_work tw
ON tw.hr_analytic_timesheet_id = ts.id
LEFT OUTER JOIN project_task t ON t.id = tw.task_id
-- Link with the issue
LEFT OUTER JOIN project_issue i ON i.id = ts.issue_id
-- Link with the project
LEFT OUTER JOIN project_project p
ON p.id = COALESCE(t.project_id, i.project_id)
-- Link with the analytic account
LEFT OUTER JOIN account_analytic_account a
ON a.id = p.analytic_account_id
-- Link with the BR
LEFT OUTER JOIN business_requirement b
ON b.id = p.business_requirement_id
)""")
return from_str

@api.model_cr
def init(self):
tools.drop_view_if_exists(self.env.cr, self._table)
self.env.cr.execute("""CREATE or REPLACE VIEW %s as (
%s
FROM ( %s )
)""" % (self._table, self._select(), self._from()))
Loading