diff --git a/hr_course/models/hr_course.py b/hr_course/models/hr_course.py
index 7856f2df0e7..d18b5a2e2d9 100644
--- a/hr_course/models/hr_course.py
+++ b/hr_course/models/hr_course.py
@@ -26,6 +26,11 @@ class HRCourseAttendee(models.Model):
default="pending",
)
active = fields.Boolean(default=True, readonly=True)
+ company_id = fields.Many2one(
+ comodel_name="res.company",
+ string="Company",
+ related="course_schedule_id.company_id",
+ )
def _remove_from_course(self):
return [(1, self.id, {"active": False})]
@@ -38,7 +43,10 @@ class HrCourse(models.Model):
name = fields.Char(required=True, tracking=True)
category_id = fields.Many2one(
- "hr.course.category", string="Category", required=True
+ "hr.course.category",
+ domain="[('company_ids', '=', company_id)]",
+ string="Category",
+ required=True,
)
permanence = fields.Boolean(string="Has Permanence", default=False, tracking=True)
@@ -53,6 +61,13 @@ class HrCourse(models.Model):
"hr.course.schedule", inverse_name="course_id"
)
+ company_id = fields.Many2one(
+ comodel_name="res.company",
+ string="Company",
+ default=lambda self: self.env.company,
+ required=True,
+ )
+
@api.onchange("permanence")
def _onchange_permanence(self):
self.permanence_time = False
@@ -63,5 +78,13 @@ class HRCourseCategory(models.Model):
_description = "Course Category"
name = fields.Char(string="Course category", required=True)
+ company_ids = fields.Many2many(
+ comodel_name="res.company",
+ string="Companies",
+ default=lambda self: self.env.company,
+ required=True,
+ )
- _sql_constraints = [("name_uniq", "unique (name)", "Category already exists !")]
+ _sql_constraints = [
+ ("name_company_uniq", "unique (name, company_ids)", "Category already exists !")
+ ]
diff --git a/hr_course/models/hr_course_schedule.py b/hr_course/models/hr_course_schedule.py
index 5c0aa25864b..8cd48dbbfd8 100644
--- a/hr_course/models/hr_course_schedule.py
+++ b/hr_course/models/hr_course_schedule.py
@@ -11,6 +11,11 @@ class HrCourseSchedule(models.Model):
name = fields.Char(required=True, tracking=True)
course_id = fields.Many2one("hr.course", string="Course", required=True)
+ company_id = fields.Many2one(
+ comodel_name="res.company",
+ string="Company",
+ related="course_id.company_id",
+ )
start_date = fields.Date(
readonly=True,
@@ -59,6 +64,7 @@ class HrCourseSchedule(models.Model):
"hr.employee",
readonly=True,
states={"waiting_attendees": [("readonly", False)]},
+ domain="[('company_id', '=', company_id)]",
)
course_attendee_ids = fields.One2many(
"hr.course.attendee",
diff --git a/hr_course/models/hr_employee.py b/hr_course/models/hr_employee.py
index 9b0526cb541..3b9b4f102a5 100644
--- a/hr_course/models/hr_employee.py
+++ b/hr_course/models/hr_employee.py
@@ -12,6 +12,7 @@ class HrEmployee(models.Model):
"hr.course.attendee",
"employee_id",
string="Courses",
+ domain="[('company_id', 'in', company_id)]",
readonly=True,
)
diff --git a/hr_course/security/course_security.xml b/hr_course/security/course_security.xml
index c454be80819..7ee8d2058a4 100644
--- a/hr_course/security/course_security.xml
+++ b/hr_course/security/course_security.xml
@@ -32,4 +32,24 @@