Skip to content

Commit

Permalink
[FIX] pms: fix precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Mar 27, 2024
1 parent 8f6c23d commit f5f94ae
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 63 deletions.
5 changes: 4 additions & 1 deletion pms_housekeeping/data/cron_jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
<field name="doall" eval="False" />
<field name="state">code</field>
<field name="model_id" ref="model_pms_housekeeping_task" />
<field name="nextcall" eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 05:00:00')" />
<field
name="nextcall"
eval="(DateTime.now() + timedelta(days=1)).strftime('%Y-%m-%d 05:00:00')"
/>
<field name="code">model.generate_task_properties()</field>
</record>
</odoo>
14 changes: 7 additions & 7 deletions pms_housekeeping/models/pms_housekeeping_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,18 @@ def _compute_priority(self):
else:
rec.priority = False

@api.depends('room_id')
@api.depends("room_id")
def _compute_allowed_housekeeper_ids(self):
for rec in self:
domain = [('job_id.name', '=', 'Housekeeper')]
domain = [("job_id.name", "=", "Housekeeper")]
if rec.room_id:
domain = [
('job_id.name', '=', 'Housekeeper'),
'|',
('property_ids', 'in', rec.room_id.pms_property_id.ids),
('property_ids', '=', False),
("job_id.name", "=", "Housekeeper"),
"|",
("property_ids", "in", rec.room_id.pms_property_id.ids),
("property_ids", "=", False),
]
rec.allowed_housekeeper_ids = self.env['hr.employee'].search(domain).ids
rec.allowed_housekeeper_ids = self.env["hr.employee"].search(domain).ids

@api.model
def create(self, vals):
Expand Down
3 changes: 1 addition & 2 deletions pms_housekeeping/models/pms_housekeeping_task_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class PmsHouseKeepingTaskType(models.Model):
string="Properties",
)


@api.constrains("is_overnight", "days_after_clean_overnight")
def _check_days_after_clean_overnight(self):
for record in self:
Expand Down Expand Up @@ -77,7 +76,7 @@ def _check_housekeeper_ids(self):
for record in self:
if record.housekeeper_ids:
for employee in record.housekeeper_ids:
if employee.job_id.name != 'Housekeeper':
if employee.job_id.name != "Housekeeper":
raise ValidationError(
_("The job position should be Housekeeper.")
)
89 changes: 44 additions & 45 deletions pms_housekeeping/tests/test_pms_housekeeping_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,7 @@ def test_no_create_grandchild_task(self):
}
)
# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="Grandchild task shouldn´t exist."
):
with self.assertRaises(ValidationError, msg="Grandchild task shouldn´t exist."):
self.env["pms.housekeeping.task"].create(
{
"name": "Grandchild Task",
Expand Down Expand Up @@ -543,56 +541,57 @@ def test_create_task_with_housekeeper(self):
}
)

#ASSERT
# ASSERT
self.assertTrue(self.task, "Housekeeping task should be created")

def test_task_housekeeper_room_inconsistency(self):

# ARRANGE
self.pms_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
self.room2 = self.env["pms.room"].create(
{
"name": "Room 202",
"pms_property_id": self.pms_property2.id,
"room_type_id": self.room_type1.id,
}
)
self.employee = self.env["hr.employee"].create(
{
"name": "Test Employee",
"company_id": self.company1.id,
"job_id": self.env.ref("pms_housekeeping.housekeeping_job_id").id,
"property_ids": [(6, 0, [self.pms_property1.id])],
}
)
# create task type
self.task_type = self.env["pms.housekeeping.task.type"].create(
# ARRANGE
self.pms_property2 = self.env["pms.property"].create(
{
"name": "Property 2",
"company_id": self.company1.id,
"default_pricelist_id": self.pricelist1.id,
}
)
self.room2 = self.env["pms.room"].create(
{
"name": "Room 202",
"pms_property_id": self.pms_property2.id,
"room_type_id": self.room_type1.id,
}
)
self.employee = self.env["hr.employee"].create(
{
"name": "Test Employee",
"company_id": self.company1.id,
"job_id": self.env.ref("pms_housekeeping.housekeeping_job_id").id,
"property_ids": [(6, 0, [self.pms_property1.id])],
}
)
# create task type
self.task_type = self.env["pms.housekeeping.task.type"].create(
{
"name": "Task Type 1",
"is_checkout": True,
}
)

# ACT & ASSERT
with self.assertRaises(
ValidationError,
msg="The room and housekeeper should belong to the same property.",
):
self.env["pms.housekeeping.task"].create(
{
"name": "Task Type 1",
"is_checkout": True,
"name": "Task",
"room_id": self.room2.id,
"task_type_id": self.task_type.id,
"task_date": datetime.today(),
"housekeeper_ids": [(6, 0, [self.employee.id])],
}
)

# ACT & ASSERT
with self.assertRaises(
ValidationError, msg="The room and housekeeper should belong to the same property."
):
self.env["pms.housekeeping.task"].create(
{
"name": "Task",
"room_id": self.room2.id,
"task_type_id": self.task_type.id,
"task_date": datetime.today(),
"housekeeper_ids": [(6, 0, [self.employee.id])],
}
)

def test_task_housekeeper_room_consistency(self):
# ARRANGE
self.employee = self.env["hr.employee"].create(
Expand Down
3 changes: 2 additions & 1 deletion pms_housekeeping/tests/test_pms_housekeeping_task_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .common import TestPms
from odoo.exceptions import ValidationError

from .common import TestPms


class TestPmsHousekeepingTask(TestPms):
def setUp(self):
Expand Down
7 changes: 5 additions & 2 deletions pms_housekeeping/tests/test_pms_hr_employee.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from odoo.exceptions import ValidationError

from .common import TestPms


Expand Down Expand Up @@ -54,7 +55,8 @@ def test_employee_pre_assigned_room_consistent_with_property(self):

# ASSERT
self.assertTrue(
self.hr_employee.pre_assigned_room_ids, "Pre assigned room is not consistent with property"
self.hr_employee.pre_assigned_room_ids,
"Pre assigned room is not consistent with property",
)

def test_employee_pre_assigned_room_consistent_without_properties(self):
Expand All @@ -72,7 +74,8 @@ def test_employee_pre_assigned_room_consistent_without_properties(self):

# ASSERT
self.assertTrue(
self.hr_employee.pre_assigned_room_ids, "Pre assigned room is not consistent without properties"
self.hr_employee.pre_assigned_room_ids,
"Pre assigned room is not consistent without properties",
)

def test_not_pre_assigned_room_no_housekeeper_employee(self):
Expand Down
5 changes: 1 addition & 4 deletions pms_housekeeping/views/pms_housekeeping_task_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@
widget="many2many_tags"
domain="[('job_id.name', '=', 'Housekeeper')]"
/>
<field
name="pms_property_ids"
widget="many2many_tags"
/>
<field name="pms_property_ids" widget="many2many_tags" />
<field name="parent_id" />
<field name="description" />
</group>
Expand Down
2 changes: 1 addition & 1 deletion pms_housekeeping/views/pms_housekeeping_task_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
widget="many2many_tags"
domain="[('id', 'in', allowed_housekeeper_ids)]"
/>
<field name="allowed_housekeeper_ids" invisible="1"/>
<field name="allowed_housekeeper_ids" invisible="1" />
</group>
<group class="col-12">
<field name="parent_id" />
Expand Down

0 comments on commit f5f94ae

Please sign in to comment.