Skip to content

Commit

Permalink
Merge PR #1259 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by etobella
  • Loading branch information
OCA-git-bot committed Jun 29, 2023
2 parents 92e78a5 + ba30d53 commit 0228154
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 3 deletions.
6 changes: 5 additions & 1 deletion hr_employee_calendar_planning/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
"license": "AGPL-3",
"installable": True,
"depends": ["hr"],
"data": ["security/ir.model.access.csv", "views/hr_employee_views.xml"],
"data": [
"security/ir.model.access.csv",
"views/hr_employee_views.xml",
"views/resource_calendar_views.xml",
],
"post_init_hook": "post_init_hook",
"maintainers": ["victoralmau", "pedrobaeza"],
}
17 changes: 17 additions & 0 deletions hr_employee_calendar_planning/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,23 @@ def copy(self, default=None):
new.filtered("calendar_ids").regenerate_calendar()
return new

def _sync_user(self, user):
res = super()._sync_user(user=user)
# set calendar_ids from Create employee button from user
if not self.calendar_ids:
res.update(
{
"calendar_ids": [
(
0,
0,
{"calendar_id": user.company_id.resource_calendar_id.id},
),
]
}
)
return res

@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
Expand Down
8 changes: 7 additions & 1 deletion hr_employee_calendar_planning/models/resource_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ class ResourceCalendar(models.Model):

active = fields.Boolean(default=True)
auto_generate = fields.Boolean()
employee_calendar_ids = fields.One2many("hr.employee.calendar", "calendar_id")

@api.constrains("active")
def _check_active(self):
for item in self:
total_items = self.env["hr.employee.calendar"].search_count(
[("calendar_id", "=", item.id)]
[
("calendar_id", "=", item.id),
"|",
("date_end", "=", False),
("date_end", "<=", fields.Date.today()),
]
)
if total_items:
raise ValidationError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import exceptions, fields
from odoo.tests import common
from odoo.tests import common, new_test_user

from ..hooks import post_init_hook

Expand All @@ -12,6 +12,15 @@ class TestHrEmployeeCalendarPlanning(common.SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
)
)
resource_calendar = cls.env["resource.calendar"]
cls.calendar1 = resource_calendar.create(
{"name": "Test calendar 1", "attendance_ids": []}
Expand Down Expand Up @@ -373,3 +382,11 @@ def test_employee_copy(self):
self.assertNotEqual(
self.employee.resource_calendar_id, employee2.resource_calendar_id
)

def test_user_action_create_employee(self):
user = new_test_user(self.env, login="test-user")
user.action_create_employee()
self.assertIn(
user.company_id.resource_calendar_id,
user.employee_id.mapped("calendar_ids.calendar_id"),
)
23 changes: 23 additions & 0 deletions hr_employee_calendar_planning/views/resource_calendar_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Creu Blanca
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="resource_calendar_form" model="ir.ui.view">
<field name="model">resource.calendar</field>
<field name="inherit_id" ref="resource.resource_calendar_form" />
<field name="arch" type="xml">
<notebook position="inside">
<page name="employee_calendar" string="Employee Calendars">
<field name="employee_calendar_ids">
<tree editable="top" create="0">
<field name="company_id" invisible="1" />
<field name="date_start" />
<field name="date_end" />
<field name="employee_id" />
</tree>
</field>
</page>
</notebook>
</field>
</record>
</odoo>

0 comments on commit 0228154

Please sign in to comment.