Skip to content

Commit

Permalink
[IMP] hr_course: Add improvements to 14
Browse files Browse the repository at this point in the history
  • Loading branch information
aromera authored and olgamarcocb committed Jan 18, 2022
1 parent 7d24786 commit dbd90e0
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 179 deletions.
18 changes: 10 additions & 8 deletions hr_course/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=========
HR Course
Hr Course
=========

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -14,13 +14,13 @@ HR Course
: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/14.0/hr_course
:target: https://github.com/OCA/hr/tree/13.0/hr_course
:alt: OCA/hr
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/hr-14-0/hr-14-0-hr_course
:target: https://translation.odoo-community.org/projects/hr-13-0/hr-13-0-hr_course
: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/14.0
:target: https://runbot.odoo-community.org/runbot/116/13.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand All @@ -38,18 +38,20 @@ Usage

To create a Course go to Employees -> Courses.

To create a Training Schedule go to Employees -> Courses Schedule.

Fill the information and click assign attendees to continue. Assign them and
then start the course.
then start the course session.

One it has finished you must enter the results and finish the course.
One it has finished you must enter the results and finish the course session.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/hr/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 <https://github.com/OCA/hr/issues/new?body=module:%20hr_course%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/hr/issues/new?body=module:%20hr_course%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -80,6 +82,6 @@ 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 <https://github.com/OCA/hr/tree/14.0/hr_course>`_ project on GitHub.
This module is part of the `OCA/hr <https://github.com/OCA/hr/tree/13.0/hr_course>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_course/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "HR Course",
"summary": """
This module allows your to manage employee's training courses""",
"version": "14.0.1.0.0",
"version": "14.0.2.0.0",
"license": "AGPL-3",
"author": "Creu Blanca,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/hr",
Expand Down
2 changes: 1 addition & 1 deletion hr_course/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -476,4 +476,4 @@ msgstr ""
#~ msgstr "hr.course.attendee"

#~ msgid "hr.course.result"
#~ msgstr "hr.course.result"
#~ msgstr "hr.course.result"
2 changes: 1 addition & 1 deletion hr_course/i18n/hr_course.pot
Original file line number Diff line number Diff line change
Expand Up @@ -454,4 +454,4 @@ msgstr ""
msgid ""
"You should set a course back to draft only if you cancelled it by mistake or"
" if some of its information is incorrect. Do you want to continue?"
msgstr ""
msgstr ""
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def migrate(env, version):
""",
)
openupgrade.load_data(
env.cr, "hr_course", "migrations/13.0.2.0.0/noupdate_changes.xml"
env.cr, "hr_course", "migrations/14.0.2.0.0/noupdate_changes.xml"
)
1 change: 1 addition & 0 deletions hr_course/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import hr_employee
from . import hr_course
from . import hr_course_schedule
151 changes: 1 addition & 150 deletions hr_course/models/hr_course.py
Original file line number Diff line number Diff line change
@@ -1,156 +1,7 @@
# Copyright 2019 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


class HrCourseSchedule(models.Model):
_name = "hr.course.schedule"
_description = "Course Schedule"
_inherit = "mail.thread"

name = fields.Char(string="Name", required=True, tracking=True)
course_id = fields.Many2one("hr.course", string="Course", required=True)

start_date = fields.Date(
string="Start date",
readonly=True,
states={"draft": [("readonly", False)]},
tracking=True,
)
end_date = fields.Date(
string="End date",
readonly=True,
states={"draft": [("readonly", False)]},
tracking=True,
)
currency_id = fields.Many2one(
"res.currency",
string="Currency",
default=lambda self: self.env.user.company_id.currency_id,
)
cost = fields.Monetary(string="Course Cost", required=True, tracking=True)
authorized_by = fields.Many2one(
string="Authorized by",
comodel_name="hr.employee",
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
tracking=True,
)
state = fields.Selection(
[
("draft", "Draft"),
("waiting_attendees", "Waiting attendees"),
("in_progress", "In progress"),
("in_validation", "In validation"),
("completed", "Completed"),
("cancelled", "Cancelled"),
],
required=True,
readonly=True,
default="draft",
tracking=True,
)

comment = fields.Text("Comment")
training_company_id = fields.Many2one("res.partner", string="Training company")
instructor_ids = fields.Many2many("res.partner", string="Instructor")
place = fields.Char("Place")

attendant_ids = fields.Many2many(
"hr.employee",
readonly=True,
states={"waiting_attendees": [("readonly", False)]},
)
course_attendee_ids = fields.One2many(
"hr.course.attendee",
inverse_name="course_schedule_id",
readonly=True,
states={"in_validation": [("readonly", False)]},
)

@api.constrains("start_date", "end_date")
def _check_start_end_dates(self):
self.ensure_one()
if self.start_date and self.end_date and (self.start_date > self.end_date):
raise ValidationError(
_("The start date cannot be later than the end date.")
)

def all_passed(self):
for attendee in self.course_attendee_ids:
attendee.result = "passed"

def _draft2waiting_values(self):
return {"state": "waiting_attendees"}

def _attendee_values(self, attendee):
return {"employee_id": attendee.id, "course_schedule_id": self.id}

def _waiting2inprogress_values(self):
attendants = []
employee_attendants = self.course_attendee_ids.mapped("employee_id")
for attendee in self.attendant_ids.filtered(
lambda r: r not in employee_attendants
):
attendants.append((0, 0, self._attendee_values(attendee)))
deleted_attendees = ""
for course_attendee in self.course_attendee_ids.filtered(
lambda r: r.employee_id not in self.attendant_ids
):
attendants += course_attendee._remove_from_course()
deleted_attendees += "- %s <br></br>" % course_attendee.employee_id.name
if deleted_attendees != "":
message = (
_("Employees removed from this course: <br></br>%s") % deleted_attendees
)
self.message_post(body=message)
return {"state": "in_progress", "course_attendee_ids": attendants}

def _inprogress2validation_values(self):
return {"state": "in_validation"}

def _validation2complete_values(self):
return {"state": "completed"}

def _back2draft_values(self):
return {"state": "draft"}

def _cancel_course_values(self):
return {"state": "cancelled"}

def draft2waiting(self):
for record in self:
record.write(record._draft2waiting_values())

def waiting2inprogress(self):
for record in self:
record.write(record._waiting2inprogress_values())

def inprogress2validation(self):
for record in self:
record.write(record._inprogress2validation_values())

def validation2complete(self):
for record in self:
if self.course_attendee_ids.filtered(
lambda r: r.result == "pending" and r.active
):
raise ValidationError(
_("You cannot complete the course with pending results")
)
else:
record.write(record._validation2complete_values())

def back2draft(self):
for record in self:
record.write(record._back2draft_values())

def cancel_course(self):
for record in self:
record.write(record._cancel_course_values())
from odoo import api, fields, models


class HRCourseAttendee(models.Model):
Expand Down
Loading

0 comments on commit dbd90e0

Please sign in to comment.