Skip to content

Commit

Permalink
[MIG][11.0] hr_employee_seniority
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaime Arroyo committed May 6, 2019
1 parent 7e0b873 commit 6863946
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 51 deletions.
68 changes: 48 additions & 20 deletions hr_employee_seniority/README.rst
Original file line number Diff line number Diff line change
@@ -1,47 +1,75 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==================
Employee Seniority
==================

=====================
Hr Employee Seniority
=====================
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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-lightgray.png?logo=github
:target: https://github.com/OCA/hr/tree/11.0/hr_employee_seniority
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-11-0/hr-11-0-hr_employee_seniority
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/116/11.0
:alt: Try me on Runbot

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

This permits to keep track of employees' length of service in number of months.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/hr/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback
`here <https://github.com/OCA/hr/issues/new?body=module:%20hr_employee_senioriy%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/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/issues/new?body=module:%20hr_employee_seniority%0Aversion:%2011.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
=======

Images
------
Authors
~~~~~~~

* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
* Michael Telahun Makonnen <mmakonnen@gmail.com>
* Camptocamp SA

Contributors
------------
~~~~~~~~~~~~

* Michael Telahun Makonnen <mmakonnen@gmail.com>
* Denis Leemann <denis.leemann@camptocamp.com>

Maintainer
----------
Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://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 https://odoo-community.org.
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/11.0/hr_employee_seniority>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 0 additions & 1 deletion hr_employee_seniority/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import models
Expand Down
5 changes: 1 addition & 4 deletions hr_employee_seniority/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# copyright 2013 Michael Telahun Makonnen <mmakonnen@gmail.com>
# copyright 2017 Denis Leemann, Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
Expand All @@ -7,7 +6,7 @@
{
'name': 'Employee Seniority',
'summary': 'Keep Track of Length of Employment',
'version': '10.0.1.0.2',
'version': '11.0.1.0.0',
'category': 'Human Resources',
'author': "Michael Telahun Makonnen <mmakonnen@gmail.com>, "
"Camptocamp SA, "
Expand All @@ -24,7 +23,5 @@
'data': [
'views/employee_views.xml',
],
'test': [
],
'installable': True,
}
1 change: 0 additions & 1 deletion hr_employee_seniority/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import hr_employee
37 changes: 18 additions & 19 deletions hr_employee_seniority/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
# copyright 2013 Michael Telahun Makonnen <mmakonnen@gmail.com>
# copyright 2017 Denis Leemann, Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import calendar
from dateutil.relativedelta import relativedelta

from odoo import api, exceptions, fields, models, _
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError


class HrEmployee(models.Model):
Expand All @@ -24,24 +24,22 @@ class HrEmployee(models.Model):
)

def _first_contract(self):
Contract = self.env['hr.contract'].sudo()
return Contract.search([('employee_id', '=', self.id)],
order='date_start asc', limit=1)
hr_contract = self.env['hr.contract'].sudo()
return hr_contract.search([('employee_id', '=', self.id)],
order='date_start asc', limit=1)

@staticmethod
def check_next_days(date_to, date_from):
if date_from.day == 1:
days_in_month = calendar.monthrange(date_to.year, date_to.month)[1]
if date_to.day == days_in_month:
return 1
elif date_from.day == date_to.day + 1:
return 1
return 0
if date_from.day != 1:
return 0
days_in_month = calendar.monthrange(date_to.year, date_to.month)[1]
return 1 if date_to.day == days_in_month or \
date_from.day == date_to.day + 1 else 0

@api.depends('contract_ids', 'initial_employment_date')
def _compute_months_service(self):
date_now = fields.Date.today()
Contract = self.env['hr.contract'].sudo()
hr_contract = self.env['hr.contract'].sudo()
for employee in self:
nb_month = 0

Expand All @@ -59,8 +57,8 @@ def _compute_months_service(self):
relativedelta(to_dt, from_dt).months + \
self.check_next_days(to_dt, from_dt)

contracts = Contract.search([('employee_id', '=', employee.id)],
order='date_start asc')
contracts = hr_contract.search([('employee_id', '=', employee.id)],
order='date_start asc')
for contract in contracts:
from_dt = fields.Date.from_string(contract.date_start)
if contract.date_end and contract.date_end < date_now:
Expand All @@ -75,11 +73,12 @@ def _compute_months_service(self):

@api.constrains('initial_employment_date', 'contract_ids')
def _check_initial_employment_date(self):
if self.initial_employment_date and len(self.contract_ids):
if self.initial_employment_date and self.contract_ids:
initial_dt = fields.Date.from_string(self.initial_employment_date)
first_contract_dt = fields.Date.from_string(
self._first_contract().date_start)
if initial_dt > first_contract_dt:
raise exceptions.UserError(_("The initial employment date "
"cannot be after the first "
"contract in the system!"))
raise ValidationError(_(
"The initial employment date "
"cannot be after the first "
"contract in the system!"))
2 changes: 2 additions & 0 deletions hr_employee_seniority/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Michael Telahun Makonnen <mmakonnen@gmail.com>
* Denis Leemann <denis.leemann@camptocamp.com>
1 change: 1 addition & 0 deletions hr_employee_seniority/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This permits to keep track of employees' length of service in number of months.
1 change: 0 additions & 1 deletion hr_employee_seniority/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from . import test_employee_seniority
15 changes: 10 additions & 5 deletions hr_employee_seniority/tests/test_employee_seniority.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
# copyright 2017 Denis Leemann, Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from dateutil.relativedelta import relativedelta

from odoo.exceptions import ValidationError
from odoo.tests import common
from odoo import fields

Expand Down Expand Up @@ -71,6 +71,11 @@ def test_inital_employment_before_first_contract_date(self):
self.employee.write({'initial_employment_date': self.two_year_ago})
self.assertAlmostEqual(self.employee.length_of_service, 24.0)

with self.assertRaises(ValidationError):
self.employee.write({
'initial_employment_date': self.six_months_ago
})

def test_multiple_contracts_with_no_interval(self):
# multiple contracts
self.contract_model.create(
Expand Down Expand Up @@ -121,8 +126,8 @@ def test_days_in_contract(self):
{
'employee_id': self.employee.id,
'name': 'Contract 1',
'date_start': (2017, 01, 01),
'date_end': (2017, 01, 03),
'date_start': '2017-01-01',
'date_end': '2017-01-03',
'wage': 5000
}
)
Expand All @@ -132,8 +137,8 @@ def test_days_in_contract(self):
{
'employee_id': self.employee.id,
'name': 'Contract 1',
'date_start': (2016, 11, 01),
'date_end': (2016, 12, 31),
'date_start': '2016-11-01',
'date_end': '2016-12-31',
'wage': 5000
}
)
Expand Down

0 comments on commit 6863946

Please sign in to comment.