Skip to content

Commit

Permalink
Rename module to hr_timesheet_activity_begin_end
Browse files Browse the repository at this point in the history
  • Loading branch information
guewen authored and schhatbar-initos committed Apr 1, 2021
1 parent e44ddd8 commit d9472aa
Show file tree
Hide file tree
Showing 12 changed files with 521 additions and 0 deletions.
50 changes: 50 additions & 0 deletions hr_timesheet_activity_begin_end/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3

Timesheet Activities - Begin/End Hours
======================================

Adds starting and ending hours fields on the timesheet activities.

Installation
============

Nothing more than the installation of the module is required.

Configuration
=============

No configuration.

Usage
=====

The new fields are displayed on the timesheet activities.

Known issues / Roadmap
======================

No known issue

Credits
=======

Contributors
------------

* Guewen Baconnier <guewen.baconnier@camptocamp.com>

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
3 changes: 3 additions & 0 deletions hr_timesheet_activity_begin_end/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
36 changes: 36 additions & 0 deletions hr_timesheet_activity_begin_end/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
#
#
# Authors: Guewen Baconnier
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#

{'name': 'Timesheet Activities - Begin/End Hours',
'version': '8.0.1.0.0',
'author': 'Camptocamp,Odoo Community Association (OCA)',
'license': 'AGPL-3',
'category': 'Human Resources',
'depends': ['hr_timesheet_sheet',
],
'website': 'http://www.camptocamp.com',
'data': ['views/hr_analytic_timesheet.xml',
'views/hr_timesheet_sheet.xml',
],
'test': [],
'installable': True,
'auto_install': False,
}
72 changes: 72 additions & 0 deletions hr_timesheet_activity_begin_end/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_timesheet_activity_begin_end
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-04-27 07:47+0000\n"
"PO-Revision-Date: 2015-04-27 07:47+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: hr_timesheet_activity_begin_end
#: field:hr.analytic.timesheet,aal_account_name:0
msgid "Analytic Account Name"
msgstr "Nom du compte analytique"

#. module: hr_timesheet_activity_begin_end
#: model:ir.model,name:hr_timesheet_activity_begin_end.model_account_analytic_line
msgid "Analytic Line"
msgstr "Ligne analytique"

#. module: hr_timesheet_activity_begin_end
#: field:hr.analytic.timesheet,aal_time_start:0
#: field:hr.analytic.timesheet,aal_time_stop:0
msgid "Analytic Line Begin Hour"
msgstr "Heure de début de la ligne analytique"

#. module: hr_timesheet_activity_begin_end
#: field:hr.analytic.timesheet,aal_date:0
msgid "Analytic Line Date"
msgstr "Date de la ligne analytique"

#. module: hr_timesheet_activity_begin_end
#: field:account.analytic.line,time_start:0
msgid "Begin Hour"
msgstr "Heure de début"

#. module: hr_timesheet_activity_begin_end
#: field:account.analytic.line,time_stop:0
msgid "End Hour"
msgstr "Heure de fin"

#. module: hr_timesheet_activity_begin_end
#: code:addons/hr_timesheet_activity_begin_end/models/account_analytic_line.py:86
#, python-format
msgid "Lines can't overlap:\n"
""
msgstr "Les lignes ne peuvent pas se chevaucher :\n"

#. module: hr_timesheet_activity_begin_end
#: code:addons/hr_timesheet_activity_begin_end/models/account_analytic_line.py:54
#, python-format
msgid "The beginning hour (%s) must precede the ending hour (%s)."
msgstr "L'heure de début (%s) doit précéder l'heure de fin (%s)."

#. module: hr_timesheet_activity_begin_end
#: code:addons/hr_timesheet_activity_begin_end/models/account_analytic_line.py:63
#, python-format
msgid "The duration (%s) must be equal to the difference between the hours (%s)."
msgstr "La durée (%s) doit être égale à la différence entre les heures (%s)."

#. module: hr_timesheet_activity_begin_end
#: model:ir.model,name:hr_timesheet_activity_begin_end.model_hr_analytic_timesheet
msgid "Timesheet Line"
msgstr "Ligne de feuille de temps"

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_timesheet_activity_begin_end
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-04-27 07:47+0000\n"
"PO-Revision-Date: 2015-04-27 07:47+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: hr_timesheet_activity_begin_end
#: field:hr.analytic.timesheet,aal_account_name:0
msgid "Analytic Account Name"
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: model:ir.model,name:hr_timesheet_activity_begin_end.model_account_analytic_line
msgid "Analytic Line"
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: field:hr.analytic.timesheet,aal_time_start:0
#: field:hr.analytic.timesheet,aal_time_stop:0
msgid "Analytic Line Begin Hour"
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: field:hr.analytic.timesheet,aal_date:0
msgid "Analytic Line Date"
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: field:account.analytic.line,time_start:0
msgid "Begin Hour"
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: field:account.analytic.line,time_stop:0
msgid "End Hour"
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: code:addons/hr_timesheet_activity_begin_end/models/account_analytic_line.py:86
#, python-format
msgid "Lines can't overlap:\n"
""
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: code:addons/hr_timesheet_activity_begin_end/models/account_analytic_line.py:54
#, python-format
msgid "The beginning hour (%s) must precede the ending hour (%s)."
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: code:addons/hr_timesheet_activity_begin_end/models/account_analytic_line.py:63
#, python-format
msgid "The duration (%s) must be equal to the difference between the hours (%s)."
msgstr ""

#. module: hr_timesheet_activity_begin_end
#: model:ir.model,name:hr_timesheet_activity_begin_end.model_hr_analytic_timesheet
msgid "Timesheet Line"
msgstr ""

3 changes: 3 additions & 0 deletions hr_timesheet_activity_begin_end/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import account_analytic_line
126 changes: 126 additions & 0 deletions hr_timesheet_activity_begin_end/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# -*- coding: utf-8 -*-
#
#
# Authors: Guewen Baconnier
# Copyright 2015 Camptocamp SA
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#

from __future__ import division

import math
from datetime import timedelta

from openerp import models, fields, api, exceptions, _
from openerp.tools.float_utils import float_compare


def float_time_convert(float_val):
hours = math.floor(abs(float_val))
mins = abs(float_val) - hours
mins = round(mins * 60)
if mins >= 60.0:
hours = hours + 1
mins = 0.0
return '%02d:%02d' % (hours, mins)


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

time_start = fields.Float(string='Begin Hour')
time_stop = fields.Float(string='End Hour')

@api.one
@api.constrains('time_start', 'time_stop', 'unit_amount')
def _check_time_start_stop(self):
start = timedelta(hours=self.time_start)
stop = timedelta(hours=self.time_stop)
if stop < start:
raise exceptions.ValidationError(
_('The beginning hour (%s) must '
'precede the ending hour (%s).') %
(float_time_convert(self.time_start),
float_time_convert(self.time_stop))
)
hours = (stop - start).seconds / 3600
if (hours and
float_compare(hours, self.unit_amount, precision_digits=4)):
raise exceptions.ValidationError(
_('The duration (%s) must be equal to the difference '
'between the hours (%s).') %
(float_time_convert(self.unit_amount),
float_time_convert(hours))
)
# check if lines overlap
others = self.search([
('id', '!=', self.id),
('user_id', '=', self.user_id.id),
('date', '=', self.date),
('time_start', '<', self.time_stop),
('time_stop', '>', self.time_start),
])
if others:
message = _("Lines can't overlap:\n")
message += '\n'.join(['%s - %s' %
(float_time_convert(line.time_start),
float_time_convert(line.time_stop))
for line
in (self + others).sorted(
lambda l: l.time_start
)])
raise exceptions.ValidationError(message)


class HrAnalyticTimesheet(models.Model):
_inherit = 'hr.analytic.timesheet'

_order = "id desc"
_order = ("aal_date DESC, aal_time_start DESC,"
"aal_time_stop DESC, aal_account_name ASC")

aal_date = fields.Date(
string='Analytic Line Date',
related='line_id.date',
store=True,
readonly=True,
)
aal_time_start = fields.Float(
string='Analytic Line Begin Hour',
related='line_id.time_start',
store=True,
readonly=True,
)
aal_time_stop = fields.Float(
string='Analytic Line Begin Hour',
related='line_id.time_stop',
store=True,
readonly=True,
)
aal_account_name = fields.Char(
string='Analytic Account Name',
related='account_id.name',
store=True,
readonly=True,
)

@api.onchange('time_start', 'time_stop')
def onchange_hours_start_stop(self):
start = timedelta(hours=self.time_start)
stop = timedelta(hours=self.time_stop)
if stop < start:
return
self.unit_amount = (stop - start).seconds / 3600
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions hr_timesheet_activity_begin_end/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import test_timesheet_begin_end
Loading

0 comments on commit d9472aa

Please sign in to comment.