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

[12.0][MIG] hr_timesheet_sheet_attendance #199

Merged
merged 5 commits into from
Jun 12, 2020
Merged
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
104 changes: 104 additions & 0 deletions hr_timesheet_sheet_attendance/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
=============================
HR Timesheet Sheet Attendance
=============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fhr--timesheet-lightgray.png?logo=github
:target: https://github.com/OCA/hr-timesheet/tree/12.0/hr_timesheet_sheet_attendance
:alt: OCA/hr-timesheet
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-timesheet-12-0/hr-timesheet-12-0-hr_timesheet_sheet_attendance
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/117/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of hr_timesheet_sheet
and help employees to manage their attendance according to timesheet period.
It provide functionality to checkin/checkout directly from timesheet-sheet.
It also help you/management in performace evaluation by displaing
total attendance time and difference of total attendance time and total working time.

**Table of contents**

.. contents::
:local:

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

This module relies on:

* The OCA module 'HR Timesheet Sheet', and can be downloaded from
Github: https://github.com/OCA/hr-timesheet/tree/12.0/hr_timesheet_sheet

Usage
=====

* Goto Timesheets > My Timesheet Sheets and create a timesheet
* Goto tab Attendances on timesheet form
- You can see there your current status checkin/checkout
- You also can create attendance by clicking on button Check In/Check Out on right side
- You can see your attendance that belongs to current timesheet on left side in same tab
* 'Total Attendance' is total working time based on your attendance
* 'Difference' is the difference betwwen total attandance time and working time (sum(attendace-time) - sum(unit amount in timessheet lines))
* Two smart buttons are present on top-right corner of timesheet form
- First one(with time icon) will take you list of your timesheets (by default filter timesheets related to current timesheet-sheet)
- Second one(labeled as Attendances) will take you to list of your attendances (by default filter ateendances related to current timesheet-sheet)
* It prevents to change in any attendance ralted to timesheet-sheet that already has submitted
* It also prevents to submit such a timesheet-sheet not having equal number of checkin and checkout

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr-timesheet/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 <https://github.com/OCA/hr-timesheet/issues/new?body=module:%20hr_timesheet_sheet_attendance%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* BizzAppDev

Contributors
~~~~~~~~~~~~

* Ruchir Shukla <ruchir@bizzappdev.com>
* Shruti Singh <shruti.singh@bizzappdev.com>
* Chirag Parmar <chirag.parmar@bizzappdev.com>
* Naglis Jonaitis <naglis@versada.eu>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

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

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.

This module is part of the `OCA/hr-timesheet <https://github.com/OCA/hr-timesheet/tree/12.0/hr_timesheet_sheet_attendance>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions hr_timesheet_sheet_attendance/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

from . import models
18 changes: 18 additions & 0 deletions hr_timesheet_sheet_attendance/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
'name': 'HR Timesheet Sheet Attendance',
'version': '12.0.1.0.0',
'category': 'Human Resources',
'sequence': 80,
'license': 'AGPL-3',
"author": "BizzAppDev, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr-timesheet/",
'depends': [
'hr_attendance',
'hr_timesheet_sheet'
],
'data': [
'views/hr_timesheet_sheet_view.xml',
'views/hr_attendance_view.xml',
],
'installable': True,
}
101 changes: 101 additions & 0 deletions hr_timesheet_sheet_attendance/i18n/hr_timesheet_sheet_attendance.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * hr_timesheet_sheet_attendance
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \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_sheet_attendance
#: model:ir.model,name:hr_timesheet_sheet_attendance.model_hr_attendance
msgid "Attendance"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.model.fields,field_description:hr_timesheet_sheet_attendance.field_hr_timesheet_sheet_attendance_count
msgid "Attendance Count"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.actions.act_window,name:hr_timesheet_sheet_attendance.action_hr_timeseet_sheet_attendance
#: model:ir.model.fields,field_description:hr_timesheet_sheet_attendance.field_hr_timesheet_sheet_attendances_ids
#: model:ir.ui.view,arch_db:hr_timesheet_sheet_attendance.hr_timesheet_sheet_inherit_form_simplified
msgid "Attendances"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.ui.view,arch_db:hr_timesheet_sheet_attendance.hr_timesheet_sheet_inherit_form_simplified
msgid "Check In"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.ui.view,arch_db:hr_timesheet_sheet_attendance.hr_timesheet_sheet_inherit_form_simplified
msgid "Check Out"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.model.fields,field_description:hr_timesheet_sheet_attendance.field_hr_timesheet_sheet_attendance_state
msgid "Current Status"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.model.fields,field_description:hr_timesheet_sheet_attendance.field_hr_timesheet_sheet_total_difference
msgid "Difference"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.model.fields,field_description:hr_timesheet_sheet_attendance.field_hr_attendance_sheet_id
msgid "Sheet"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: code:addons/hr_timesheet_sheet_attendance/models/hr_timesheet_sheet.py:82
#, python-format
msgid "The timesheet cannot be validated as it does not contain an equal number of sign ins and sign outs."
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.ui.view,arch_db:hr_timesheet_sheet_attendance.hr_timesheet_sheet_inherit_form_simplified
msgid "Timesheet"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.actions.act_window,name:hr_timesheet_sheet_attendance.action_hr_timeseet_sheet_analytic_line
msgid "Timesheet Activities"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.model,name:hr_timesheet_sheet_attendance.model_hr_timesheet_sheet
msgid "Timesheet Sheet"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: model:ir.model.fields,field_description:hr_timesheet_sheet_attendance.field_hr_timesheet_sheet_total_attendance
msgid "Total Attendance"
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: code:addons/hr_timesheet_sheet_attendance/models/hr_attendance.py:106
#, python-format
msgid "You can not enter an attendance date outside the current timesheet dates."
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: code:addons/hr_timesheet_sheet_attendance/models/hr_attendance.py:89
#, python-format
msgid "You can not enter an attendance in a submitted timesheet. Ask your manager to reset it before adding attendance."
msgstr ""

#. module: hr_timesheet_sheet_attendance
#: code:addons/hr_timesheet_sheet_attendance/models/hr_attendance.py:68
#, python-format
msgid "You cannot modify an entry in a confirmed timesheet"
msgstr ""

2 changes: 2 additions & 0 deletions hr_timesheet_sheet_attendance/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import hr_timesheet_sheet
from . import hr_attendance
102 changes: 102 additions & 0 deletions hr_timesheet_sheet_attendance/models/hr_attendance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
from odoo import api, fields, models, _
from odoo.exceptions import UserError

import pytz


class HrAttendance(models.Model):
_inherit = 'hr.attendance'

def _get_attendance_employee_tz(self, date=None):
"""Convert date according to timezone of user
:param date: datetime.datetime.
:return: datetime.date with applied timezone or False"""

tz = False
if self.employee_id.user_id:
tz = self.employee_id.user_id.partner_id.tz
if not date:
return False
time_zone = pytz.timezone(tz or 'UTC')
attendance_tz_dt = pytz.UTC.localize(date)
attendance_tz_dt = attendance_tz_dt.astimezone(time_zone)
return attendance_tz_dt.date()

def _get_timesheet_sheet(self):
"""Find and return current timesheet-sheet
:return: recordset of hr_timesheet.sheet or False"""

sheet_obj = self.env['hr_timesheet.sheet']
check_in = False
if self.check_in:
check_in = self._get_attendance_employee_tz(date=self.check_in)

domain = [('employee_id', '=', self.employee_id.id)]
if check_in:
domain += [
('date_start', '<=', check_in),
('date_end', '>=', check_in)
]

sheet_ids = sheet_obj.search(domain, limit=1)
return sheet_ids[:1] or False

@api.depends('employee_id', 'check_in', 'check_out')
def _compute_sheet_id(self):
"""Find and set current timesheet-sheet in
current attendance record"""
for attendance in self:
attendance.sheet_id = attendance._get_timesheet_sheet()

sheet_id = fields.Many2one(
comodel_name='hr_timesheet.sheet',
compute="_compute_sheet_id",
string='Sheet',
store=True)

def _check_timesheet_state(self):
"""Check and raise error if current sheet not in draftstate"""
if self._context.get('allow_modify_confirmed_sheet', False):
return
if self.sheet_id and self.sheet_id.state != 'draft':
raise UserError(_(
"You cannot modify an entry in a confirmed timesheet"
))

@api.multi
def unlink(self):
# Restrict to delete attendance from confirmed timesheet-sheet
for attendance in self:
attendance._check_timesheet_state()

return super(HrAttendance, self).unlink()

@api.constrains('check_in', 'check_out')
def _check_timesheet(self):
"""- Restrict to create attendance in confirmed timesheet-sheet
- Restrict to add attendance date outside the current
timesheet dates"""
timesheet = self.sheet_id
if not timesheet:
return
if timesheet and timesheet.state != 'draft':
raise UserError(_(
"You can not enter an attendance in a submitted timesheet. " +
"Ask your manager to reset it before adding attendance."
))
else:
checkin_tz_date = self._get_attendance_employee_tz(
date=self.check_in
)
checkout_tz_date = self._get_attendance_employee_tz(
date=self.check_out
)
if ((timesheet.date_start > checkin_tz_date or
timesheet.date_end < checkin_tz_date) or
checkout_tz_date and (timesheet.date_start >
checkout_tz_date or
timesheet.date_end <
checkout_tz_date)):
raise UserError(_(
"You can not enter an attendance date " +
"outside the current timesheet dates."))
Loading