Skip to content

Commit

Permalink
[IMP+FIX] project_timesheet_time_control
Browse files Browse the repository at this point in the history
* Decorate methods correctly + README imp
* Add tests
* Add button on tasks
* README
* open/close behaviour
  • Loading branch information
pedrobaeza committed Mar 14, 2017
1 parent 1ce7692 commit a5c6a11
Show file tree
Hide file tree
Showing 13 changed files with 263 additions and 185 deletions.
35 changes: 18 additions & 17 deletions project_timesheet_time_control/README.rst
Expand Up @@ -3,19 +3,20 @@
:alt: License: AGPL-3

==============================
Project TimeSheet time Control
Project Timesheet Time Control
==============================

This module adds a button at account analytic line level to compute minutes
lasted from start date to the current moment.

Adds a datetime field that replaces ``date`` field in tree view, and write date
field with datetime field value.

Adds filters by user and groups by tasks and user.

Also allow open and close tasks from account analytic lines.
* This module adds a button at account analytic line level to compute the spent
time, in minutes, from start date to the current moment.
* It adds a datetime field that replaces ``date`` field in tree view, and write
date field with datetime field value.
* It also adds a task filter and a group by task options in the search.
* Finally, it allows to open and close tasks from account analytic lines.
The selected closed stage is the first one that is found with the mark
"Closed" checked.

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
Expand All @@ -24,20 +25,20 @@ Also allow open and close tasks from account analytic lines.
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/project-service/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/project/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/project-service/issues/new?body=module:%20project_timesheet_time_control%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us smashing it by providing a detailed and
welcomed feedback `here <https://github.com/OCA/project/issues/new>`_.

Credits
=======

Contributors
------------
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Antonio Espinosa <antonioea@antiun.com>
* Carlos Dauden <carlos@incaser.es>
* Sergio Teruel <sergio@incaser.es>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
* Antonio Espinosa <antonioea@tecnativa.com>
* Carlos Dauden <carlos@tecnativa.es>
* Sergio Teruel <sergio@tecnativa.es>

Maintainer
----------
Expand Down
4 changes: 1 addition & 3 deletions project_timesheet_time_control/__init__.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# © 2016 Antonio Espinosa
# © 2016 Pedro M. Baeza
# © 2016 Sergio Teruel
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import models
from .hooks import post_init_hook
20 changes: 12 additions & 8 deletions project_timesheet_time_control/__openerp__.py
@@ -1,21 +1,25 @@
# -*- coding: utf-8 -*-
# © 2016 Antonio Espinosa
# © 2016 Pedro M. Baeza
# © 2016 Sergio Teruel
# Copyright 2016 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Sergio Teruel
# Copyright 2016-2017 Tecnativa - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': 'Project timesheet time control',
'version': '9.0.1.0.0',
'category': 'Project',
'author': 'Serv. Tecnol. Avanzados - Pedro M. Baeza, '
'Antiun Ingeniería S.L.',
'author': 'Tecnativa,'
'Odoo Community Association (OCA)',
'website': 'http://www.serviciosbaeza.com',
'depends': ['project_timesheet'],
'depends': [
'project_timesheet',
'project_stage_closed',
],
'data': [
'security/project_security.xml',
'view/account_analytic_line_view.xml',
'views/account_analytic_line_view.xml',
'views/project_task_view.xml',
],
'license': 'AGPL-3',
'installable': True,
'post_init_hook': 'post_init_hook',
}
12 changes: 12 additions & 0 deletions project_timesheet_time_control/hooks.py
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2017 Tecnativa - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html


def post_init_hook(cr, registry):
"""Put the date with 00:00:00 as the date_time for the line."""
cr.execute("""
UPDATE account_analytic_line
SET date_time = to_timestamp(date || ' 00:00:00',
'YYYY/MM/DD HH24:MI:SS')
""")
88 changes: 35 additions & 53 deletions project_timesheet_time_control/i18n/es.po
@@ -1,82 +1,64 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * project_work_time_control
# * project_timesheet_time_control
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 9.0c\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-03-21 17:58+0000\n"
"PO-Revision-Date: 2016-03-21 19:01+0100\n"
"Last-Translator: Sergio Teruel <sergio@incaser.es>\n"
"POT-Creation-Date: 2017-03-14 13:31+0000\n"
"PO-Revision-Date: 2017-03-14 13:31+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: es_ES\n"
"X-Generator: Poedit 1.5.4\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: project_work_time_control
#: model:ir.model,name:project_work_time_control.model_account_analytic_line
#. module: project_timesheet_time_control
#: model:ir.model,name:project_timesheet_time_control.model_account_analytic_line
msgid "Analytic Line"
msgstr "Línea analítica"
msgstr "Línea Analítica"

#. module: project_work_time_control
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_timesheet_account_analytic_line_tree
#. module: project_timesheet_time_control
#: model:ir.ui.view,arch_db:project_timesheet_time_control.account_analytic_line_tree
msgid "Close task"
msgstr "Cerrar tarea"

#. module: project_work_time_control
#: model:ir.model.fields,field_description:project_work_time_control.field_account_analytic_line_date_time
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_analytic_line_search
#. module: project_timesheet_time_control
#: model:ir.model.fields,field_description:project_timesheet_time_control.field_account_analytic_line_closed
msgid "Closed"
msgstr "Cerrado"

#. module: project_timesheet_time_control
#: model:ir.model.fields,field_description:project_timesheet_time_control.field_account_analytic_line_date_time
msgid "Date"
msgstr "Fecha"

#. module: project_work_time_control
#: model:ir.model.fields,field_description:project_work_time_control.field_account_analytic_line_folded
msgid "Folded in Tasks Pipeline"
msgstr "Replegado en la vista Kanban"

#. module: project_work_time_control
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_analytic_line_search
msgid "Group By..."
msgstr "Agrupar por..."

#. module: project_work_time_control
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_timesheet_account_analytic_line_tree
#. module: project_timesheet_time_control
#: model:ir.ui.view,arch_db:project_timesheet_time_control.account_analytic_line_tree
msgid "Open task"
msgstr "Abrir tarea"

#. module: project_work_time_control
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_analytic_line_search
#, fuzzy
msgid "Search task work"
msgstr "Actualizar Modo Trabajo"

#. module: project_work_time_control
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_timesheet_account_analytic_line_tree
#. module: project_timesheet_time_control
#: model:ir.ui.view,arch_db:project_timesheet_time_control.account_analytic_line_tree
#: model:ir.ui.view,arch_db:project_timesheet_time_control.view_task_form2_inherited
msgid "Stop"
msgstr "Stop"
msgstr "Detener"

#. module: project_work_time_control
#: model:ir.model,name:project_work_time_control.model_project_task
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_analytic_line_search
#. module: project_timesheet_time_control
#: model:ir.ui.view,arch_db:project_timesheet_time_control.account_analytic_line_search
msgid "Task"
msgstr "Tarea"

#. module: project_work_time_control
#: model:ir.model,name:project_work_time_control.model_project_task_type
msgid "Task Stage"
msgstr "Estado actual"
#. module: project_timesheet_time_control
#: model:ir.model.fields,help:project_timesheet_time_control.field_account_analytic_line_closed
msgid "Tasks in this stage are considered closed."
msgstr "Las tareas en esta etapa se consideran cerradas."

#. module: project_work_time_control
#: model:ir.model.fields,help:project_work_time_control.field_account_analytic_line_folded
msgid ""
"This stage is folded in the kanban view when there are no records in that "
"stage to display."
msgstr ""
#. module: project_timesheet_time_control
#: code:addons/project_timesheet_time_control/models/account_analytic_line.py:75
#, python-format
msgid "There isn't any stage with closed check. Please mark any."
msgstr "No hay ninguna etapa con la casilla Cerrado. Por favor marque alguna."

#. module: project_work_time_control
#: model:ir.ui.view,arch_db:project_work_time_control.work_time_control_analytic_line_search
msgid "User"
msgstr "Usuario"
3 changes: 0 additions & 3 deletions project_timesheet_time_control/models/__init__.py
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# © 2016 Antonio Espinosa
# © 2016 Pedro M. Baeza
# © 2016 Sergio Teruel
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import account_analytic_line
62 changes: 38 additions & 24 deletions project_timesheet_time_control/models/account_analytic_line.py
@@ -1,31 +1,31 @@
# -*- coding: utf-8 -*-
# © 2016 Antonio Espinosa
# © 2016 Pedro M. Baeza
# © 2016 Sergio Teruel
# Copyright 2016 Tecnativa - Antonio Espinosa
# Copyright 2016 Tecnativa - Sergio Teruel
# Copyright 2016-2017 Tecnativa - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, fields, api
from openerp import _, api, fields, exceptions, models
from datetime import datetime


class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'

date_time = fields.Datetime(default=fields.Datetime.now, string='Date')
folded = fields.Boolean(related='task_id.stage_id.fold')
closed = fields.Boolean(related='task_id.stage_id.closed')

@api.onchange('account_id')
def onchange_account_id(self):
if not self.account_id:
return {'domain': {'task_id': []}}
self.task_id = False
project = self.env['project.project'].search(
[('analytic_account_id', '=', self.account_id.id)], limit=1)
return {
'domain': {
'task_id': [('project_id', '=', project.id),
('stage_id.fold', '=', False)]},
}
if self.task_id.project_id.analytic_account_id != self.account_id:
self.task_id = False
domain = {'task_id': []}
if self.account_id:
project = self.env['project.project'].search(
[('analytic_account_id', '=', self.account_id.id)], limit=1,
)
domain = {'task_id': [('project_id', '=', project.id),
('stage_id.closed', '=', False)]}
return {'domain': domain}

@api.onchange('task_id')
def onchange_task_id(self):
Expand All @@ -37,28 +37,42 @@ def eval_date(self, vals):
vals['date'] = fields.Date.from_string(vals['date_time'])
return vals

@api.model
def create(self, vals):
return super(AccountAnalyticLine, self).create(self.eval_date(vals))

@api.multi
def write(self, vals):
return super(AccountAnalyticLine, self).write(self.eval_date(vals))

@api.multi
def button_end_work(self):
end_date = datetime.now()
for work in self:
date = fields.Datetime.from_string(work.date_time)
work.unit_amount = (end_date - date).total_seconds() / 3600
for line in self:
date = fields.Datetime.from_string(line.date_time)
line.unit_amount = (end_date - date).total_seconds() / 3600
return True

@api.multi
def button_open_task(self):
stage = self.env['project.task.type'].search(
[('fold', '=', False)], limit=1)
self.mapped('task_id').write({'stage_id': stage.id})
for line in self.filtered('task_id'):
if line.task_id.project_id:
stage = self.env['project.task.type'].search(
[('project_ids', '=', line.task_id.project_id.id),
('closed', '=', False)], limit=1)
if stage:
line.task_id.write({'stage_id': stage.id})

@api.multi
def button_close_task(self):
stage = self.env['project.task.type'].search(
[('fold', '=', True)], limit=1)
self.mapped('task_id').write({'stage_id': stage.id})
for line in self.filtered('task_id.project_id'):
stage = self.env['project.task.type'].search(
[('project_ids', '=', line.task_id.project_id.id),
('closed', '=', True)], limit=1,
)
if not stage: # pragma: no cover
raise exceptions.UserError(
_("There isn't any stage with closed check. Please "
"mark any.")
)
line.task_id.write({'stage_id': stage.id})
22 changes: 0 additions & 22 deletions project_timesheet_time_control/security/project_security.xml

This file was deleted.

4 changes: 4 additions & 0 deletions project_timesheet_time_control/tests/__init__.py
@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0

from . import test_project_timesheet_time_control

0 comments on commit a5c6a11

Please sign in to comment.