Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP]hr_course:multi company support #1430

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions hr_course/models/hr_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})]
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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 !")
]
6 changes: 6 additions & 0 deletions hr_course/models/hr_course_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions hr_course/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class HrEmployee(models.Model):
"hr.course.attendee",
"employee_id",
string="Courses",
domain="[('company_id', 'in', company_id)]",
readonly=True,
)

Expand Down
20 changes: 20 additions & 0 deletions hr_course/security/course_security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,24 @@
<field name="groups" eval="[(4, ref('hr.group_hr_manager'))]" />
<field name="global" eval="False" />
</record>
<record model="ir.rule" id="hr_employee_course_company_rule">
<field name="name">hr.employee.course.company.rule</field>
<field name="model_id" ref="model_hr_course" />
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<record model="ir.rule" id="hr_employee_course_schedule_company_rule">
<field name="name">hr.employee.course.schedule.company.rule</field>
<field name="model_id" ref="model_hr_course_schedule" />
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<record model="ir.rule" id="hr_employee_course_attendee_company_rule">
<field name="name">hr.employee.course.attendee.company.rule</field>
<field name="model_id" ref="model_hr_course_attendee" />
<field name="domain_force">[('company_id', 'in', company_ids)]</field>
</record>
<record model="ir.rule" id="hr_employee_course_category_company_rule">
<field name="name">hr.employee.course.category.company.rule</field>
<field name="model_id" ref="model_hr_course_category" />
<field name="domain_force">[('company_ids', 'in', company_ids)]</field>
</record>
</odoo>
11 changes: 11 additions & 0 deletions hr_course/views/hr_course_category_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<form string="Course Categories">
<group>
<field name="name" />
<field
name="company_ids"
groups="base.group_multi_company"
widget="many2many_tags"
/>
</group>
</form>
</field>
Expand All @@ -17,6 +22,7 @@
<field name="arch" type="xml">
<search string="Course Categories">
<field name="name" string="Category" />
<field name="company_ids" groups="base.group_multi_company" />
</search>
</field>
</record>
Expand All @@ -27,6 +33,11 @@
<field name="arch" type="xml">
<tree>
<field name="name" />
<field
name="company_ids"
groups="base.group_multi_company"
widget="many2many_tags"
/>
</tree>
</field>
</record>
Expand Down
5 changes: 5 additions & 0 deletions hr_course/views/hr_course_schedule_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@
<group>
<group>
<field name="course_id" />
<field
name="company_id"
groups="base.group_multi_company"
/>
<field
name="cost"
widget="monetary"
Expand All @@ -111,6 +115,7 @@
string="Attendees"
attrs="{'invisible': [('state','not in',['draft', 'waiting_attendees','cancelled'])]}"
>
<field name="company_id" invisible="1" />
<field name="attendant_ids" />
</page>
<page
Expand Down
7 changes: 7 additions & 0 deletions hr_course/views/hr_course_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
</div>
<group>
<group>
<field name="company_id" invisible="1" />
<field name="category_id" />
<field
name="company_id"
groups="base.group_multi_company"
/>
<field name="permanence" />
<field
name="permanence_time"
Expand Down Expand Up @@ -64,7 +69,9 @@
<field name="arch" type="xml">
<tree>
<field name="name" />
<field name="company_id" invisible="1" />
<field name="category_id" />
<field name="company_id" groups="base.group_multi_company" />
<field name="content" />
<field name="objective" />
</tree>
Expand Down
Loading