diff --git a/hr_job_category/__manifest__.py b/hr_job_category/__manifest__.py index dc9a518453b..edd9125cbe6 100644 --- a/hr_job_category/__manifest__.py +++ b/hr_job_category/__manifest__.py @@ -2,21 +2,17 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'HR Job Employee Categories', - 'version': '12.0.1.0.0', - 'category': 'Generic Modules/Human Resources', - 'summary': 'Adds tags to employee trough contract and job position', - 'author': "Michael Telahun Makonnen , " - "Savoir-faire Linux, " - "Fekete Mihai (FBSR), " - "Odoo Community Association (OCA)", - 'website': 'https://github.com/OCA/hr', - 'license': 'AGPL-3', - 'depends': [ - 'hr_contract', - ], - 'data': [ - 'views/hr_view.xml', - ], - 'installable': True, + "name": "HR Job Employee Categories", + "version": "12.0.1.0.0", + "category": "Generic Modules/Human Resources", + "summary": "Adds tags to employee trough contract and job position", + "author": "Michael Telahun Makonnen , " + "Savoir-faire Linux, " + "Fekete Mihai (FBSR), " + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/hr", + "license": "AGPL-3", + "depends": ["hr_contract",], + "data": ["views/hr_view.xml",], + "installable": True, } diff --git a/hr_job_category/models/hr.py b/hr_job_category/models/hr.py index 9e3d0285b53..ec149179755 100644 --- a/hr_job_category/models/hr.py +++ b/hr_job_category/models/hr.py @@ -1,64 +1,66 @@ # Copyright 2013 Michael Telahun Makonnen # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api import logging +from odoo import api, fields, models + _logger = logging.getLogger(__name__) class HRJob(models.Model): - _inherit = 'hr.job' + _inherit = "hr.job" category_ids = fields.Many2many( - 'hr.employee.category', - 'job_category_rel', - 'job_id', - 'category_id', - string='Associated Tags' + "hr.employee.category", + "job_category_rel", + "job_id", + "category_id", + string="Associated Tags", ) class HRContract(models.Model): - _inherit = 'hr.contract' + _inherit = "hr.contract" @api.multi def _remove_tags(self, employee_id=None, job_id=None): # TODO write tags only once if not employee_id or not job_id: return - employee = self.env['hr.employee'].browse(employee_id) + employee = self.env["hr.employee"].browse(employee_id) empl_tags = employee.category_ids - job = self.env['hr.job'].browse(job_id) - _logger.debug('Removing employee tags if tag exists on contract ' - 'job: %s', empl_tags) + job = self.env["hr.job"].browse(job_id) + _logger.debug( + "Removing employee tags if tag exists on contract " "job: %s", empl_tags + ) for tag in job.category_ids: if tag in empl_tags: - employee.write({'category_ids': [(3, tag.id)]}) + employee.write({"category_ids": [(3, tag.id)]}) @api.multi def _tag_employees(self, employee_id=None, job_id=None): if not employee_id or not job_id: return - employee = self.env['hr.employee'].browse(employee_id) + employee = self.env["hr.employee"].browse(employee_id) empl_tags = employee.category_ids - job = self.env['hr.job'].browse(job_id) + job = self.env["hr.job"].browse(job_id) for tag in job.category_ids: if tag not in empl_tags: - _logger.debug("Adding employee tag if job tag doesn't " - "exists: %s", tag.name) - employee.write({'category_ids': [(4, tag.id)]}) + _logger.debug( + "Adding employee tag if job tag doesn't " "exists: %s", tag.name + ) + employee.write({"category_ids": [(4, tag.id)]}) @api.model def create(self, vals): res = super().create(vals) - self._tag_employees(vals.get('employee_id', False), - vals.get('job_id', False)) + self._tag_employees(vals.get("employee_id", False), vals.get("job_id", False)) return res @api.multi def write(self, vals): - prev_data = self.read(['job_id']) + prev_data = self.read(["job_id"]) res = super().write(vals) @@ -67,10 +69,11 @@ def write(self, vals): # for contract in self: for data in prev_data: - if (data.get('id') == contract.id and data['job_id'] and - data['job_id'][0] != contract.job_id.id): - self._remove_tags(contract.employee_id.id, - data['job_id'][0]) - self._tag_employees(contract.employee_id.id, - contract.job_id.id) + if ( + data.get("id") == contract.id + and data["job_id"] + and data["job_id"][0] != contract.job_id.id + ): + self._remove_tags(contract.employee_id.id, data["job_id"][0]) + self._tag_employees(contract.employee_id.id, contract.job_id.id) return res diff --git a/hr_job_category/readme/CONTRIBUTORS.rst b/hr_job_category/readme/CONTRIBUTORS.rst index 71ff60e08b0..e35de9243ce 100644 --- a/hr_job_category/readme/CONTRIBUTORS.rst +++ b/hr_job_category/readme/CONTRIBUTORS.rst @@ -1,4 +1,4 @@ * Michael Telahun Makonnen * Savoir-faire Linux * Fekete Mihai -* Nikul Chaudhary \ No newline at end of file +* Nikul Chaudhary diff --git a/hr_job_category/readme/DESCRIPTION.rst b/hr_job_category/readme/DESCRIPTION.rst index e5cddb071ba..883af419076 100644 --- a/hr_job_category/readme/DESCRIPTION.rst +++ b/hr_job_category/readme/DESCRIPTION.rst @@ -3,4 +3,4 @@ to support tagging employees based on their job positions. For example, all Supervisors could be attached to the Supervisors category. Define which categories a job belongs to in the configuration for the job. When an employee is assigned a particular job the categories attached to that -job will be attached to the employee record as well. \ No newline at end of file +job will be attached to the employee record as well. diff --git a/hr_job_category/readme/INSTALL.rst b/hr_job_category/readme/INSTALL.rst index e3253deed81..de0bc623691 100644 --- a/hr_job_category/readme/INSTALL.rst +++ b/hr_job_category/readme/INSTALL.rst @@ -4,4 +4,4 @@ To install this module, you need to: * add the path to this repository in your configuration (addons-path) * update the module list * search for "HR Job Employee Categories" in your addons -* install the module \ No newline at end of file +* install the module diff --git a/hr_job_category/readme/USAGE.rst b/hr_job_category/readme/USAGE.rst index 108d6a55429..bdd3d7f054c 100644 --- a/hr_job_category/readme/USAGE.rst +++ b/hr_job_category/readme/USAGE.rst @@ -3,4 +3,4 @@ Once a contract is defined for an employee, the tags assigned to the job position selected are copied to the employee. Note: If the job position is changed on the same contract, the tags from -old job position will be removed from employee. \ No newline at end of file +old job position will be removed from employee. diff --git a/hr_job_category/tests/test_hr_job_categories.py b/hr_job_category/tests/test_hr_job_categories.py index efcb58814c6..b2b8e107d53 100644 --- a/hr_job_category/tests/test_hr_job_categories.py +++ b/hr_job_category/tests/test_hr_job_categories.py @@ -7,35 +7,32 @@ class TestHrJobCategories(common.TransactionCase): def setUp(self): super(TestHrJobCategories, self).setUp() - self.employee_model = self.env['hr.employee'] - self.employee_categ_model = self.env['hr.employee.category'] - self.user_model = self.env['res.users'] - self.job_model = self.env['hr.job'] - self.contract_model = self.env['hr.contract'] + self.employee_model = self.env["hr.employee"] + self.employee_categ_model = self.env["hr.employee.category"] + self.user_model = self.env["res.users"] + self.job_model = self.env["hr.job"] + self.contract_model = self.env["hr.contract"] # Create a employee - self.employee_id = self.employee_model.create({'name': 'Employee 1'}) + self.employee_id = self.employee_model.create({"name": "Employee 1"}) # Create two employee categories - self.categ_id = self.employee_categ_model.create( - {'name': 'Category 1'}) - self.categ_2_id = self.employee_categ_model.create( - {'name': 'Category 2'}) + self.categ_id = self.employee_categ_model.create({"name": "Category 1"}) + self.categ_2_id = self.employee_categ_model.create({"name": "Category 2"}) # Create two jobs self.job_id = self.job_model.create( - {'name': 'Job 1', - 'category_ids': [(6, 0, [self.categ_id.id])]}) + {"name": "Job 1", "category_ids": [(6, 0, [self.categ_id.id])]} + ) self.job_2_id = self.job_model.create( - {'name': 'Job 2', - 'category_ids': [(6, 0, [self.categ_2_id.id])]}) + {"name": "Job 2", "category_ids": [(6, 0, [self.categ_2_id.id])]} + ) # Create one contract self.contract_id = self.contract_model.create( - {'name': 'Contract 1', - 'employee_id': self.employee_id.id, - 'wage': 50000}) + {"name": "Contract 1", "employee_id": self.employee_id.id, "wage": 50000} + ) def test_write_computes_with_normal_args(self): """ @@ -45,14 +42,14 @@ def test_write_computes_with_normal_args(self): Check if the job categories are written to the employee. """ # Check if job categories are written to the employee - self.contract_id.write({'job_id': self.job_id.id}) + self.contract_id.write({"job_id": self.job_id.id}) job_categ = [categ.id for categ in self.job_id.category_ids] empl_categ = [categ.id for categ in self.employee_id.category_ids] self.assertTrue(all(x in empl_categ for x in job_categ)) # Check if job2 categories are written to the employee - self.contract_id.write({'job_id': self.job_2_id.id}) + self.contract_id.write({"job_id": self.job_2_id.id}) job_categ = [categ.id for categ in self.job_2_id.category_ids] empl_categ = [categ.id for categ in self.employee_id.category_ids] diff --git a/hr_job_category/views/hr_view.xml b/hr_job_category/views/hr_view.xml index 34fb11b6afb..53713c7e5ed 100644 --- a/hr_job_category/views/hr_view.xml +++ b/hr_job_category/views/hr_view.xml @@ -1,16 +1,23 @@ - + - hr.job.category hr.job - + - -