From 38305c520605551769550e76489a37536d99e31b Mon Sep 17 00:00:00 2001 From: Andhitia Rama Date: Fri, 18 Jan 2019 22:15:11 +0700 Subject: [PATCH] [8.0.1.2.0] hr_job_family_modelling/ * Put relation between object --- hr_job_family_modelling/__openerp__.py | 4 +- hr_job_family_modelling/models/__init__.py | 2 + hr_job_family_modelling/models/hr_employee.py | 27 +++- hr_job_family_modelling/models/hr_job.py | 75 +++++++++ .../models/hr_job_family.py | 60 +++++++- .../models/hr_job_family_level.py | 142 ++++++++++++++++-- .../models/hr_job_grade.py | 5 + .../security/ir.model.access.csv | 2 + .../views/hr_employee_views.xml | 4 +- .../views/hr_job_family_level_views.xml | 69 +++++++++ .../views/hr_job_family_views.xml | 13 ++ .../views/hr_job_grade_views.xml | 2 + .../views/hr_job_views.xml | 44 ++++++ 13 files changed, 430 insertions(+), 19 deletions(-) create mode 100644 hr_job_family_modelling/models/hr_job.py create mode 100644 hr_job_family_modelling/views/hr_job_family_level_views.xml create mode 100644 hr_job_family_modelling/views/hr_job_views.xml diff --git a/hr_job_family_modelling/__openerp__.py b/hr_job_family_modelling/__openerp__.py index d4437dc0..cee7c1b3 100644 --- a/hr_job_family_modelling/__openerp__.py +++ b/hr_job_family_modelling/__openerp__.py @@ -6,7 +6,7 @@ "name": "Job Family Modelling", "summary": "Grading system that divides jobs into coherent groups " "based on shared characteristics", - "version": "8.0.1.1.0", + "version": "8.0.1.2.0", "category": "Human Resources", "website": "https://opensynergy-indonesia.com/", "author": "OpenSynergy Indonesia", @@ -22,6 +22,8 @@ "views/hr_job_grade_views.xml", "views/hr_job_family_grade_views.xml", "views/hr_job_family_views.xml", + "views/hr_job_family_level_views.xml", + "views/hr_job_views.xml", "views/hr_employee_views.xml", ], } diff --git a/hr_job_family_modelling/models/__init__.py b/hr_job_family_modelling/models/__init__.py index 9630f8fd..97ca8884 100644 --- a/hr_job_family_modelling/models/__init__.py +++ b/hr_job_family_modelling/models/__init__.py @@ -7,5 +7,7 @@ hr_job_grade, hr_job_family_grade, hr_job_family, + hr_job_family_level, hr_employee, + hr_job, ) diff --git a/hr_job_family_modelling/models/hr_employee.py b/hr_job_family_modelling/models/hr_employee.py index ed80130d..2cfb529f 100644 --- a/hr_job_family_modelling/models/hr_employee.py +++ b/hr_job_family_modelling/models/hr_employee.py @@ -2,19 +2,36 @@ # Copyright 2018 OpenSynergy Indonesia # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from openerp import models, fields, api class HrEmployee(models.Model): _inherit = "hr.employee" + @api.multi + @api.depends( + "job_id" + ) + def _compute_job_grade(self): + for employee in self: + result = False + if employee.job_id: + result = employee.job_id.job_grade_ids.ids + employee.allowed_job_grade_ids = result + job_grade_id = fields.Many2one( string="Job Grade", comodel_name="hr.job_grade", required=False, ) - job_family_grade_id = fields.Many2one( - string="Job Family Grade", - comodel_name="hr.job_family_grade", - required=False, + allowed_job_grade_ids = fields.Many2many( + string="Job Grades", + comodel_name="hr.job_grade", + compute="_compute_job_grade", + store=False, ) + # job_family_grade_id = fields.Many2one( + # string="Job Family Grade", + # comodel_name="hr.job_family_grade", + # required=False, + # ) diff --git a/hr_job_family_modelling/models/hr_job.py b/hr_job_family_modelling/models/hr_job.py new file mode 100644 index 00000000..cae2b3f5 --- /dev/null +++ b/hr_job_family_modelling/models/hr_job.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 OpenSynergy Indonesia +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models, fields, api + + +class HrJob(models.Model): + _inherit = "hr.job" + + @api.multi + @api.depends( + "job_family_level_id" + ) + def _compute_job_grade(self): + for job in self: + result = False + if job.job_family_level_id: + result = job.job_family_level_id.job_grade_ids.ids + job.allowed_job_grade_ids = result + + job_family_level_id = fields.Many2one( + string="Job Family Level", + comodel_name="hr.job_family_level", + ) + allowed_job_grade_ids = fields.Many2many( + string="Job Grades", + comodel_name="hr.job_grade", + compute="_compute_job_grade", + store=False, + ) + job_grade_ids = fields.Many2many( + string="Job Grades", + comodel_name="hr.job_grade", + relation="rel_job_2_grade", + column1="job_id", + column2="job_grade_id", + ) + + @api.multi + def onchange_job_family_level_id(self, job_family_level_id): + value = self._get_value_before_onchange_job_family_level_id() + domain = self._get_domain_before_onchange_job_family_level_id() + + if job_family_level_id: + obj_job_family_level = self.env["hr.job_family_level"] + job_family_level = obj_job_family_level.browse( + [job_family_level_id])[0] + value = self._get_value_after_onchange_job_family_level_id( + job_family_level + ) + domain = self._get_domain_after_onchange_job_family_level_id( + job_family_level + ) + return {"value": value, "domain": domain} + + @api.multi + def _get_value_before_onchange_job_family_level_id(self): + return { + "job_grade_ids": [], + } + + @api.multi + def _get_domain_before_onchange_job_family_level_id(self): + return {} + + @api.multi + def _get_value_after_onchange_job_family_level_id(self, job_family_level): + return { + "job_grade_ids": [], + } + + @api.multi + def _get_domain_after_onchange_job_family_level_id(self, job_family_level): + return {} diff --git a/hr_job_family_modelling/models/hr_job_family.py b/hr_job_family_modelling/models/hr_job_family.py index 98fd7f0f..d589aa10 100644 --- a/hr_job_family_modelling/models/hr_job_family.py +++ b/hr_job_family_modelling/models/hr_job_family.py @@ -2,13 +2,34 @@ # © 2016 OpenSynergy Indonesia # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from openerp import models, fields, api, _ +from openerp.exceptions import Warning as UserError class HrJobFamily(models.Model): _name = "hr.job_family" _description = "Job Family" + @api.multi + @api.depends( + "min_job_grade_id", + "max_job_grade_id", + "max_job_grade_id.sequence", + "min_job_grade_id.sequence", + ) + def _compute_job_grade_ids(self): + obj_jg = self.env["hr.job_grade"] + job_grade_ids = obj_jg.search([]).ids + for jf in self: + result = [] + if jf.min_job_grade_id and jf.max_job_grade_id: + min_job_grade_id = jf.min_job_grade_id.id + max_job_grade_id = jf.max_job_grade_id.id + min_index = job_grade_ids.index(min_job_grade_id) + max_index = job_grade_ids.index(max_job_grade_id) + result = job_grade_ids[min_index:max_index + 1] + jf.job_grade_ids = result + name = fields.Char( string="Job Family", required=True, @@ -18,6 +39,26 @@ class HrJobFamily(models.Model): string="Code", required=True, ) + min_job_grade_id = fields.Many2one( + string="Min. Grade", + comodel_name="hr.job_grade", + required=True, + ) + max_job_grade_id = fields.Many2one( + string="Max. Grade", + comodel_name="hr.job_grade", + required=True, + ) + job_grade_ids = fields.Many2many( + string="Job Grades", + comodel_name="hr.job_grade", + relation="rel_job_family_2_grade", + column1="job_family_id", + column2="job_grade_id", + compute="_compute_job_grade_ids", + store=True, + readonly=True, + ) active = fields.Boolean( string="Active", default=True, @@ -25,3 +66,20 @@ class HrJobFamily(models.Model): note = fields.Text( string="Note", ) + + @api.constrains( + "min_job_grade_id", + "max_job_grade_id", + ) + def _check_min_max_grade(self): + obj_jg = self.env["hr.job_grade"] + job_grade_ids = obj_jg.search([]).ids + msg = _("Wrong Max Min Grade") + for jf in self: + if jf.min_job_grade_id and jf.max_job_grade_id: + min_job_grade_id = jf.min_job_grade_id.id + max_job_grade_id = jf.max_job_grade_id.id + min_index = job_grade_ids.index(min_job_grade_id) + max_index = job_grade_ids.index(max_job_grade_id) + if min_index > max_index: + raise UserError(msg) diff --git a/hr_job_family_modelling/models/hr_job_family_level.py b/hr_job_family_modelling/models/hr_job_family_level.py index 293bb6c3..750411a1 100644 --- a/hr_job_family_modelling/models/hr_job_family_level.py +++ b/hr_job_family_modelling/models/hr_job_family_level.py @@ -2,31 +2,80 @@ # © 2016 OpenSynergy Indonesia # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import models, fields +from openerp import models, fields, api, _ +from openerp.exceptions import Warning as UserError class HrJobFamilyLevel(models.Model): - _name = "hr.job.family.level" + _name = "hr.job_family_level" _description = "Job Family Level" - name = fields.Char( - string="Job Family Level", - required=True, - translate=True, + @api.multi + @api.depends( + "job_family_id", + ) + def _compute_job_grade(self): + for jfl in self: + jfl.allowed_job_grade_ids = jfl.job_family_id.job_grade_ids.ids + + @api.multi + @api.depends( + "min_job_grade_id", + "max_job_grade_id", + "max_job_grade_id.sequence", + "min_job_grade_id.sequence", ) + def _compute_job_grade_ids(self): + obj_jg = self.env["hr.job_grade"] + job_grade_ids = obj_jg.search([]).ids + for jf in self: + result = [] + if jf.min_job_grade_id and jf.max_job_grade_id: + min_job_grade_id = jf.min_job_grade_id.id + max_job_grade_id = jf.max_job_grade_id.id + min_index = job_grade_ids.index(min_job_grade_id) + max_index = job_grade_ids.index(max_job_grade_id) + result = job_grade_ids[min_index:max_index + 1] + jf.job_grade_ids = result + code = fields.Char( string="Code", required=True, ) job_family_id = fields.Many2one( string="Job Family", - comodel_name="hr.job.family", - required=False, + comodel_name="hr.job_family", + required=True, ) job_family_grade_id = fields.Many2one( string="Job Family Grade", - comodel_name="hr.job.family.grade", - required=False, + comodel_name="hr.job_family_grade", + required=True, + ) + allowed_job_grade_ids = fields.Many2many( + string="Job Grades", + comodel_name="hr.job_grade", + compute="_compute_job_grade", + store=False, + ) + job_grade_ids = fields.Many2many( + string="Job Grades", + comodel_name="hr.job_grade", + relation="rel_job_family_level_2_grade", + column1="job_family_level_id", + column2="job_grade_id", + compute="_compute_job_grade_ids", + store=True, + ) + min_job_grade_id = fields.Many2one( + string="Min. Grade", + comodel_name="hr.job_grade", + required=True, + ) + max_job_grade_id = fields.Many2one( + string="Max. Grade", + comodel_name="hr.job_grade", + required=True, ) active = fields.Boolean( string="Active", @@ -35,3 +84,76 @@ class HrJobFamilyLevel(models.Model): note = fields.Text( string="Note", ) + + @api.multi + def name_get(self): + result = [] + for jfl in self: + grade_count = len(jfl.job_grade_ids) + if grade_count == 0: + min_grade = "-" + max_grade = "-" + else: + min_grade = jfl.job_grade_ids[0].name + max_grade = jfl.job_grade_ids[grade_count - 1].name + + name = "%s %s (%s - %s)" % ( + jfl.job_family_grade_id.name, + jfl.job_family_id.name, + min_grade, + max_grade) + result.append([jfl.id, name]) + return result + + @api.multi + def onchange_job_family_id(self, job_family_id): + value = self._get_value_before_onchange_job_family_id() + domain = self._get_domain_before_onchange_job_family_id() + + if job_family_id: + obj_job_family = self.env["hr.job_family"] + job_family = obj_job_family.browse([job_family_id])[0] + value = self._get_value_after_onchange_job_family_id( + job_family + ) + domain = self._get_domain_after_onchange_job_family_id( + job_family + ) + return {"value": value, "domain": domain} + + @api.multi + def _get_value_before_onchange_job_family_id(self): + return { + "job_grade_ids": [], + } + + @api.multi + def _get_domain_before_onchange_job_family_id(self): + return {} + + @api.multi + def _get_value_after_onchange_job_family_id(self, job_family): + return { + "job_grade_ids": [], + } + + @api.multi + def _get_domain_after_onchange_job_family_id(self, job_family): + return {} + + @api.constrains( + "min_job_grade_id", + "max_job_grade_id", + ) + def _check_min_max_grade(self): + obj_jg = self.env["hr.job_grade"] + job_grade_ids = obj_jg.search([]).ids + msg = _("Wrong Max Min Grade") + for jf in self: + if jf.min_job_grade_id and jf.max_job_grade_id: + min_job_grade_id = jf.min_job_grade_id.id + max_job_grade_id = jf.max_job_grade_id.id + min_index = job_grade_ids.index(min_job_grade_id) + max_index = job_grade_ids.index(max_job_grade_id) + if min_index > max_index: + raise UserError(msg) diff --git a/hr_job_family_modelling/models/hr_job_grade.py b/hr_job_family_modelling/models/hr_job_grade.py index dfef84f4..7e24cd06 100644 --- a/hr_job_family_modelling/models/hr_job_grade.py +++ b/hr_job_family_modelling/models/hr_job_grade.py @@ -19,6 +19,11 @@ class HrJobGrade(models.Model): comodel_name="hr.job_grade_category", required=False, ) + sequence = fields.Integer( + string="Sequence", + required=True, + default=5, + ) code = fields.Char( string="Code", required=True, diff --git a/hr_job_family_modelling/security/ir.model.access.csv b/hr_job_family_modelling/security/ir.model.access.csv index ffb9c776..09c09443 100644 --- a/hr_job_family_modelling/security/ir.model.access.csv +++ b/hr_job_family_modelling/security/ir.model.access.csv @@ -7,3 +7,5 @@ hr_job_family_grade_employee,hr.job_family_grade - employee,model_hr_job_family_ hr_job_family_grade_all,hr.job_family_grade - all,model_hr_job_family_grade,,1,0,0,0 hr_job_family_employee,hr.job_family - employee,model_hr_job_family,base.group_user,1,1,1,1 hr_job_family_all,hr.job_family - all,model_hr_job_family,,1,0,0,0 +hr_job_family_level_employee,hr.job_family_level - employee,model_hr_job_family_level,base.group_user,1,1,1,1 +hr_job_family_level_all,hr.job_family_level - all,model_hr_job_family_level,,1,0,0,0 diff --git a/hr_job_family_modelling/views/hr_employee_views.xml b/hr_job_family_modelling/views/hr_employee_views.xml index 9e5ecb0c..c2700b76 100644 --- a/hr_job_family_modelling/views/hr_employee_views.xml +++ b/hr_job_family_modelling/views/hr_employee_views.xml @@ -13,8 +13,8 @@ - - + + diff --git a/hr_job_family_modelling/views/hr_job_family_level_views.xml b/hr_job_family_modelling/views/hr_job_family_level_views.xml new file mode 100644 index 00000000..113bed31 --- /dev/null +++ b/hr_job_family_modelling/views/hr_job_family_level_views.xml @@ -0,0 +1,69 @@ + + + + + + + + + tree hr.job_family_level + hr.job_family_level + + + + + + + + + + + + + form hr.job_family_level + hr.job_family_level + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + Job Family Level + hr.job_family_level + form + tree,form + + + + +
+
diff --git a/hr_job_family_modelling/views/hr_job_family_views.xml b/hr_job_family_modelling/views/hr_job_family_views.xml index a00881dc..81937402 100644 --- a/hr_job_family_modelling/views/hr_job_family_views.xml +++ b/hr_job_family_modelling/views/hr_job_family_views.xml @@ -13,6 +13,8 @@ + + @@ -26,8 +28,19 @@ + + + + + + + + + + + diff --git a/hr_job_family_modelling/views/hr_job_grade_views.xml b/hr_job_family_modelling/views/hr_job_grade_views.xml index ac8e6dc4..0de606ee 100644 --- a/hr_job_family_modelling/views/hr_job_grade_views.xml +++ b/hr_job_family_modelling/views/hr_job_grade_views.xml @@ -11,6 +11,7 @@ hr.job_grade + @@ -26,6 +27,7 @@ + diff --git a/hr_job_family_modelling/views/hr_job_views.xml b/hr_job_family_modelling/views/hr_job_views.xml new file mode 100644 index 00000000..788bc2c3 --- /dev/null +++ b/hr_job_family_modelling/views/hr_job_views.xml @@ -0,0 +1,44 @@ + + + + + + + + + hr.job tree + hr.job + + + + + + + + + + + + hr.job form + hr.job + + + + + + + + + + + + + + + + +