From 570651317121af67536d9859cd1b53d416df1444 Mon Sep 17 00:00:00 2001 From: Jaime Arroyo Date: Wed, 24 Jul 2019 09:42:48 +0200 Subject: [PATCH] [11.0][MIG] hr_contract_default_trial_length --- hr_contract_default_trial_length/README.rst | 72 ++++++++++++++----- hr_contract_default_trial_length/__init__.py | 1 - .../__manifest__.py | 19 +++-- .../models/__init__.py | 1 - .../models/hr_contract.py | 12 ++-- .../models/hr_contract_type.py | 1 - .../readme/CONFIGURE.rst | 2 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + .../readme/INSTALL.rst | 7 ++ .../readme/ROADMAP.rst | 1 + .../readme/USAGE.rst | 1 + .../tests/__init__.py | 1 + .../tests/test_trial_length.py | 30 ++++++++ .../views/hr_contract_type.xml | 12 +++- 15 files changed, 123 insertions(+), 41 deletions(-) create mode 100644 hr_contract_default_trial_length/readme/CONFIGURE.rst create mode 100644 hr_contract_default_trial_length/readme/CONTRIBUTORS.rst create mode 100644 hr_contract_default_trial_length/readme/DESCRIPTION.rst create mode 100644 hr_contract_default_trial_length/readme/INSTALL.rst create mode 100644 hr_contract_default_trial_length/readme/ROADMAP.rst create mode 100644 hr_contract_default_trial_length/readme/USAGE.rst create mode 100644 hr_contract_default_trial_length/tests/__init__.py create mode 100644 hr_contract_default_trial_length/tests/test_trial_length.py diff --git a/hr_contract_default_trial_length/README.rst b/hr_contract_default_trial_length/README.rst index de7c442103eb..50fbdbdbfcbf 100644 --- a/hr_contract_default_trial_length/README.rst +++ b/hr_contract_default_trial_length/README.rst @@ -1,18 +1,43 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :alt: License: AGPL-3 - ============================= Default Contract Trail Length ============================= +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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_contract_default_trial_length + :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_contract_default_trial_length + :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 addon allows you to define default trail length for contracts +**Table of contents** + +.. contents:: + :local: + Installation ============ To install this module, you need to: -* clone the branch 10.0 of the repository https://github.com/OCA/hr +* clone the branch 11.0 of the repository https://github.com/OCA/hr * add the path to this repository in your configuration (addons-path) * update the module list * search for "Default Contract Trail Length" in your addons @@ -26,43 +51,52 @@ shown above. Usage ===== -* Set your trail length on your contract types + +* Set your trail length on your contract types Known issues / Roadmap ====================== * Contract trial length can also depend on contract duration -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/116/10.0 - 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 smashing it by providing a detailed and welcomed feedback -`here `_. +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 ======= +Authors +~~~~~~~ + +* Salton Massally + Contributors ------------- +~~~~~~~~~~~~ * Salton Massally (iDT Labs) * Julien Laloux +* Jaime Arroyo -Maintainer ----------- +Maintainers +~~~~~~~~~~~ -.. image:: http://odoo-community.org/logo.png +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png :alt: Odoo Community Association - :target: http://odoo-community.org + :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. -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 `_ project on GitHub. -To contribute to this module, please visit http://odoo-community.org. +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_contract_default_trial_length/__init__.py b/hr_contract_default_trial_length/__init__.py index b30bf671b323..8885117b3861 100644 --- a/hr_contract_default_trial_length/__init__.py +++ b/hr_contract_default_trial_length/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2015 Salton Massally # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/hr_contract_default_trial_length/__manifest__.py b/hr_contract_default_trial_length/__manifest__.py index baad89935cee..74db0f806b19 100644 --- a/hr_contract_default_trial_length/__manifest__.py +++ b/hr_contract_default_trial_length/__manifest__.py @@ -1,20 +1,19 @@ -# -*- coding: utf-8 -*- # Copyright 2015 Salton Massally # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - "name": "Default Contract Trail Length", - "version": "10.0.1.0.0", + 'name': 'Default Contract Trail Length', + 'version': '11.0.1.0.0', 'license': 'AGPL-3', - 'author': "Salton Massally , " - "Odoo Community Association (OCA)", - "website": "http://idtlabs.sl", - "category": "Human Resources", - "summary": "Define default trail length for contracts", - "depends": [ + 'author': 'Salton Massally ,' + 'Odoo Community Association (OCA)', + 'website': 'http://idtlabs.sl', + 'category': 'Human Resources', + 'summary': 'Define default trail length for contracts', + 'depends': [ 'hr_contract' ], - "data": [ + 'data': [ 'views/hr_contract_type.xml', ], 'installable': True, diff --git a/hr_contract_default_trial_length/models/__init__.py b/hr_contract_default_trial_length/models/__init__.py index 74318db8ab30..46fe4e6d62f0 100644 --- a/hr_contract_default_trial_length/models/__init__.py +++ b/hr_contract_default_trial_length/models/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2015 Salton Massally # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/hr_contract_default_trial_length/models/hr_contract.py b/hr_contract_default_trial_length/models/hr_contract.py index cb7a5e5524ea..23afcc3cd48a 100644 --- a/hr_contract_default_trial_length/models/hr_contract.py +++ b/hr_contract_default_trial_length/models/hr_contract.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2015 Salton Massally # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -9,13 +8,14 @@ class HrContract(models.Model): _inherit = 'hr.contract' - @api.onchange('trial_date_start', 'type_id') + @api.onchange('type_id') @api.multi def onchange_trial_date_start(self): self.ensure_one() - if self.trial_date_start and len(self.type_id): - res = self.type_id.trial_length - if res: + self.trial_date_end = False + if self.date_start and self.type_id: + days = self.type_id.trial_length + if days: end_dt = fields.Date.from_string( - self.trial_date_start) + relativedelta(days=res) + self.date_start) + relativedelta(days=days) self.trial_date_end = fields.Date.to_string(end_dt) diff --git a/hr_contract_default_trial_length/models/hr_contract_type.py b/hr_contract_default_trial_length/models/hr_contract_type.py index 1c8f170ed18a..2c22013132d7 100644 --- a/hr_contract_default_trial_length/models/hr_contract_type.py +++ b/hr_contract_default_trial_length/models/hr_contract_type.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2015 Salton Massally # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/hr_contract_default_trial_length/readme/CONFIGURE.rst b/hr_contract_default_trial_length/readme/CONFIGURE.rst new file mode 100644 index 000000000000..221558f207f5 --- /dev/null +++ b/hr_contract_default_trial_length/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ +This module does not require any special configuration apart from enabling it as +shown above. diff --git a/hr_contract_default_trial_length/readme/CONTRIBUTORS.rst b/hr_contract_default_trial_length/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..1d59acff3340 --- /dev/null +++ b/hr_contract_default_trial_length/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Salton Massally (iDT Labs) +* Julien Laloux +* Jaime Arroyo diff --git a/hr_contract_default_trial_length/readme/DESCRIPTION.rst b/hr_contract_default_trial_length/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..83c88c345f82 --- /dev/null +++ b/hr_contract_default_trial_length/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This addon allows you to define default trail length for contracts diff --git a/hr_contract_default_trial_length/readme/INSTALL.rst b/hr_contract_default_trial_length/readme/INSTALL.rst new file mode 100644 index 000000000000..39ee1a19f8ad --- /dev/null +++ b/hr_contract_default_trial_length/readme/INSTALL.rst @@ -0,0 +1,7 @@ +To install this module, you need to: + +* clone the branch 11.0 of the repository https://github.com/OCA/hr +* add the path to this repository in your configuration (addons-path) +* update the module list +* search for "Default Contract Trail Length" in your addons +* install the module diff --git a/hr_contract_default_trial_length/readme/ROADMAP.rst b/hr_contract_default_trial_length/readme/ROADMAP.rst new file mode 100644 index 000000000000..d058f7cfe76a --- /dev/null +++ b/hr_contract_default_trial_length/readme/ROADMAP.rst @@ -0,0 +1 @@ +* Contract trial length can also depend on contract duration diff --git a/hr_contract_default_trial_length/readme/USAGE.rst b/hr_contract_default_trial_length/readme/USAGE.rst new file mode 100644 index 000000000000..c726d848d2a1 --- /dev/null +++ b/hr_contract_default_trial_length/readme/USAGE.rst @@ -0,0 +1 @@ +* Set your trail length on your contract types diff --git a/hr_contract_default_trial_length/tests/__init__.py b/hr_contract_default_trial_length/tests/__init__.py new file mode 100644 index 000000000000..c816640788b7 --- /dev/null +++ b/hr_contract_default_trial_length/tests/__init__.py @@ -0,0 +1 @@ +from . import test_trial_length diff --git a/hr_contract_default_trial_length/tests/test_trial_length.py b/hr_contract_default_trial_length/tests/test_trial_length.py new file mode 100644 index 000000000000..072b864bcff4 --- /dev/null +++ b/hr_contract_default_trial_length/tests/test_trial_length.py @@ -0,0 +1,30 @@ +# Copyright 2018 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + + +from odoo.tests.common import TransactionCase + + +class TestTrialLength(TransactionCase): + + def setUp(self): + super().setUp() + self.type1 = self.env['hr.contract.type'].create({ + 'name': 'Type 1', + 'trial_length': 20, + }) + self.type2 = self.env['hr.contract.type'].create({ + 'name': 'Type 2', + 'trial_length': 10, + }) + self.contract = self.env['hr.contract'].create({ + 'name': 'Contract', + 'type_id': self.type1.id, + 'date_start': '2019-10-10', + 'wage': 50000, + }) + + def test_onchange_trial_date_start(self): + self.contract.write({'type_id': self.type2.id}) + self.contract.onchange_trial_date_start() + self.assertEqual(self.contract.trial_date_end, '2019-10-20') diff --git a/hr_contract_default_trial_length/views/hr_contract_type.xml b/hr_contract_default_trial_length/views/hr_contract_type.xml index c490aac4dedd..0685e505773d 100644 --- a/hr_contract_default_trial_length/views/hr_contract_type.xml +++ b/hr_contract_default_trial_length/views/hr_contract_type.xml @@ -5,9 +5,15 @@ hr.contract.type - - - + + + +