diff --git a/hr_employee_seniority/README.rst b/hr_employee_seniority/README.rst index c57d76c7913f..12ec342222d5 100644 --- a/hr_employee_seniority/README.rst +++ b/hr_employee_seniority/README.rst @@ -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 -`_. 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 `_. +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. Credits ======= -Images ------- +Authors +~~~~~~~ -* Odoo Community Association: `Icon `_. +* Michael Telahun Makonnen +* Camptocamp SA Contributors ------------- +~~~~~~~~~~~~ * Michael Telahun Makonnen * Denis Leemann -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 `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_employee_seniority/__init__.py b/hr_employee_seniority/__init__.py index 299943e473b9..cfc40a3eacfe 100644 --- a/hr_employee_seniority/__init__.py +++ b/hr_employee_seniority/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import models diff --git a/hr_employee_seniority/__manifest__.py b/hr_employee_seniority/__manifest__.py index 002a31816d41..b7fe6430ffc8 100644 --- a/hr_employee_seniority/__manifest__.py +++ b/hr_employee_seniority/__manifest__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # copyright 2013 Michael Telahun Makonnen # copyright 2017 Denis Leemann, Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -7,12 +6,12 @@ { '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 , " "Camptocamp SA, " "Odoo Community Association (OCA)", - 'website': 'http://miketelahun.wordpress.com', + 'website': 'https://github.com/OCA/hr', 'license': 'AGPL-3', 'depends': [ 'hr', @@ -24,7 +23,5 @@ 'data': [ 'views/employee_views.xml', ], - 'test': [ - ], 'installable': True, } diff --git a/hr_employee_seniority/models/__init__.py b/hr_employee_seniority/models/__init__.py index c8919c724362..92ea155c7d14 100644 --- a/hr_employee_seniority/models/__init__.py +++ b/hr_employee_seniority/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import hr_employee diff --git a/hr_employee_seniority/models/hr_employee.py b/hr_employee_seniority/models/hr_employee.py index f96ad96ca15d..98be008167dd 100644 --- a/hr_employee_seniority/models/hr_employee.py +++ b/hr_employee_seniority/models/hr_employee.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # copyright 2013 Michael Telahun Makonnen # copyright 2017 Denis Leemann, Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). @@ -6,7 +5,8 @@ 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): @@ -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 @@ -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: @@ -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!")) diff --git a/hr_employee_seniority/readme/CONTRIBUTORS.rst b/hr_employee_seniority/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..f515a56fe771 --- /dev/null +++ b/hr_employee_seniority/readme/CONTRIBUTORS.rst @@ -0,0 +1,2 @@ +* Michael Telahun Makonnen +* Denis Leemann diff --git a/hr_employee_seniority/readme/DESCRIPTION.rst b/hr_employee_seniority/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..b5c738b1e52a --- /dev/null +++ b/hr_employee_seniority/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This permits to keep track of employees' length of service in number of months. diff --git a/hr_employee_seniority/tests/__init__.py b/hr_employee_seniority/tests/__init__.py index d6119adf0672..bb754dbf1cd8 100644 --- a/hr_employee_seniority/tests/__init__.py +++ b/hr_employee_seniority/tests/__init__.py @@ -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 diff --git a/hr_employee_seniority/tests/test_employee_seniority.py b/hr_employee_seniority/tests/test_employee_seniority.py index 38dae8d64952..d33626bb3e3e 100644 --- a/hr_employee_seniority/tests/test_employee_seniority.py +++ b/hr_employee_seniority/tests/test_employee_seniority.py @@ -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 @@ -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( @@ -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 } ) @@ -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 } )