Skip to content

Commit

Permalink
[IMP]14.0-pms_housekeeping: housekeeping task
Browse files Browse the repository at this point in the history
  • Loading branch information
braisab committed Feb 13, 2024
1 parent b57b092 commit 662a287
Show file tree
Hide file tree
Showing 12 changed files with 365 additions and 198 deletions.
2 changes: 1 addition & 1 deletion pms_housekeeping/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Housekeeping
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:de773807356222adab5ee772d075d86a64a8a09828b1e137748c9562380fe750
!! source digest: sha256:4807e347dd2088e7cfafc8201f1105b6162c3f0793e9b87f570b6ba38c1756e7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
5 changes: 4 additions & 1 deletion pms_housekeeping/data/pms_housekeeping_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
<field name="name">Housekeeper</field>
<field name="state">open</field>
</record>
<record id="cancellation_type_dont_disturb" model="pms.housekeeping.cancellation.type">
<record
id="cancellation_type_dont_disturb"
model="pms.housekeeping.cancellation.type"
>
<field name="name">Don´t disturb</field>
</record>
<record id="cancellation_type_promotion" model="pms.housekeeping.cancellation.type">
Expand Down
9 changes: 8 additions & 1 deletion pms_housekeeping/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2020 Jose Luis Algara (Alda Hotels <https://www.aldahotels.es>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models
from odoo import api, fields, models


class HrEmployee(models.Model):
Expand All @@ -12,3 +12,10 @@ class HrEmployee(models.Model):
string="Pre Assigned Rooms",
help="Rooms pre assigned to this employee",
)

job_name = fields.Char(string="Job Name", compute="_compute_job_name")

@api.depends("job_id")
def _compute_job_name(self):
for record in self:
record.job_name = record.job_id.name
4 changes: 2 additions & 2 deletions pms_housekeeping/models/pms_housekeeping_cancellation_type.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from odoo import fields, models, api
from odoo import fields, models


class PmsHousekeepingCancellationType(models.Model):
_name = 'pms.housekeeping.cancellation.type'
_name = "pms.housekeeping.cancellation.type"

name = fields.Char(string="Name", required=True)
description = fields.Text(string="Description")
169 changes: 146 additions & 23 deletions pms_housekeeping/models/pms_housekeeping_task.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import fields, models, api
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError


Expand All @@ -18,7 +18,10 @@ class PmsHouseKeepingTask(models.Model):
required=True,
ondelete="restrict",
)
task_date = fields.Date(string="Date", required=True,)
task_date = fields.Date(
string="Date",
required=True,
)
state = fields.Selection(
selection=[
("pending", "Pending"),
Expand All @@ -29,9 +32,15 @@ class PmsHouseKeepingTask(models.Model):
],
string="State",
required=True,
default="to_do",
default="pending",
)
priority = fields.Integer(
string="Priority",
default=0,
computed="_compute_priority",
store=True,
readonly=False,
)
priority = fields.Integer(string="Priority", default=0)
cleaning_comments = fields.Text(string="Cleaning Comments")
employee_ids = fields.Many2many(
comodel_name="hr.employee",
Expand All @@ -40,6 +49,9 @@ class PmsHouseKeepingTask(models.Model):
column2="employee_id",
string="Employees",
domain="[('job_id.name', '=', 'Housekeeper')]",
compute="_compute_employee_ids",
store=True,
readonly=False,
)
parent_id = fields.Many2one(
string="Parent Task",
Expand All @@ -51,27 +63,45 @@ class PmsHouseKeepingTask(models.Model):
string="Parent State",
compute="_compute_parent_state",
)
child_ids = fields.One2many(
string="Child Tasks",
help="Indicates that this task has child tasks",
comodel_name="pms.housekeeping.task",
inverse_name="parent_id",
)
cancellation_type_id = fields.Many2one(
comodel_name="pms.housekeeping.cancellation.type",
string="Cancellation Type",
ondelete="restrict",
)
is_today = fields.Boolean(
string="Is Today",
compute="_compute_is_today",
store=True,
readonly=False,
pending_allowed = fields.Boolean(
string="Is pending allowed",
compute="_compute_pending_allowed",
)
to_do_allowed = fields.Boolean(
string="Is To Do Allowed",
compute="_compute_to_do_allowed",
)
cancel_allowed = fields.Boolean(
string="Is Cancel Allowed",
compute="_compute_cancel_allowed",
)
is_future = fields.Boolean(
string="Is Future",
compute="_compute_is_future",
in_progress_allowed = fields.Boolean(
string="Is In Progress Allowed",
compute="_compute_in_progress_allowed",
)
done_allowed = fields.Boolean(
string="Is Done Allowed",
compute="_compute_done_allowed",
)

@api.constrains("task_date")
def _check_task_date(self):
for rec in self:
if rec.task_date < fields.Date.today():
raise ValidationError("Task Date must be greater than or equal to today")
raise ValidationError(
_("Task Date must be greater than or equal to today")
)

def action_cancel(self):
for rec in self:
Expand All @@ -80,35 +110,128 @@ def action_cancel(self):
def action_to_do(self):
for rec in self:
rec.state = "to_do"
rec.cancellation_type_id = False

def action_done(self):
for rec in self:
rec.state = "done"
rec.cancellation_type_id = False

def action_in_progress(self):
for rec in self:
rec.state = "in_progress"
rec.cancellation_type_id = False

def action_pending(self):
for rec in self:
rec.state = "pending"
rec.cancellation_type_id = False

@api.onchange("state")
def _onchange_state(self):
for rec in self:
if rec.state == "cancel":
rec.child_ids.state = "cancel"
elif rec.state != "done":
rec.child_ids.state = "pending"

@api.depends("parent_id.state")
def _compute_parent_state(self):
for rec in self:
rec.parent_state = rec.parent_id.state if rec.parent_id else False

@api.depends("task_date")
def _compute_is_today(self):
@api.depends("task_date", "state")
def _compute_pending_allowed(self):
for rec in self:
if rec.task_date:
rec.is_today = rec.task_date == fields.Date.today()
if (
rec.task_date
and rec.state == "cancel"
and (
rec.task_date > fields.Date.today()
or (
(rec.parent_state and rec.parent_state != "done")
or not rec.parent_state
)
)
):
rec.pending_allowed = True
else:
rec.is_today = False
@api.depends("task_date")
def _compute_is_future(self):
rec.pending_allowed = False

@api.depends("task_date", "state")
def _compute_to_do_allowed(self):
for rec in self:
if rec.task_date:
rec.is_future = rec.task_date > fields.Date.today()
if (
rec.task_date
and rec.task_date == fields.Date.today()
and rec.state in ("cancel", "pending", "done", "in_progress")
and (
(rec.parent_state and rec.parent_state == "done")
or not rec.parent_state
)
):
rec.to_do_allowed = True
else:
rec.is_future = False
rec.to_do_allowed = False

@api.depends("state")
def _compute_cancel_allowed(self):
for rec in self:
if rec.state in ("to_do", "pending"):
rec.cancel_allowed = True
else:
rec.cancel_allowed = False

@api.depends("state")
def _compute_in_progress_allowed(self):
for rec in self:
if rec.state == "to_do":
rec.in_progress_allowed = True
else:
rec.in_progress_allowed = False

@api.depends("state")
def _compute_done_allowed(self):
for rec in self:
if rec.state == "in_progress":
rec.done_allowed = True
else:
rec.done_allowed = False

@api.depends("room_id", "task_type_id")
def _compute_employee_ids(self):
for rec in self:
employee_ids = False
if rec.room_id or rec.task_type_id:
employee_ids = self.env["hr.employee"].search(
[("pre_assigned_room_ids", "in", [rec.room_id.id])]
)
if not employee_ids:
employee_ids = (
self.env["pms.housekeeping.task.type"]
.search([("id", "=", rec.task_type_id.id)])
.housekeeper_ids
)
rec.employee_ids = employee_ids

@api.depends("task_type_id")
def _compute_priority(self):
for rec in self:
if rec.task_type_id:
rec.priority = rec.task_type_id.priority
else:
rec.priority = False

@api.model
def create(self, vals):
task_type_id = vals.get("task_type_id")
pms_housekeeping_task_type = self.env["pms.housekeeping.task.type"].browse(
task_type_id
)
room_id = vals.get("room_id")
pms_room = self.env["pms.room"].browse(room_id)
pms_room.housekeeping_state = (
"to_inspect" if pms_housekeeping_task_type.is_inspection else "dirty"
)

return super(PmsHouseKeepingTask, self).create(vals)
10 changes: 7 additions & 3 deletions pms_housekeeping/models/pms_housekeeping_task_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ class PmsHouseKeepingTaskType(models.Model):
is_checkin = fields.Boolean(string="Checkin")
is_checkout = fields.Boolean(string="Checkout")
priority = fields.Integer(string="Priority", default=0)
days_after_clean_overnight = fields.Integer(string="Days After Clean Overnight",)
days_after_clean_empty = fields.Integer(string="Days After Clean Empty", )
housekeepers = fields.Many2many(
days_after_clean_overnight = fields.Integer(
string="Days After Clean Overnight",
)
days_after_clean_empty = fields.Integer(
string="Days After Clean Empty",
)
housekeeper_ids = fields.Many2many(
comodel_name="hr.employee",
relation="pms_housekeeping_task_type_hr_employee_rel",
column1="task_type_id",
Expand Down
3 changes: 1 addition & 2 deletions pms_housekeeping/models/pms_room.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from odoo import fields, models, api
from odoo import fields, models


class PmsRoom(models.Model):
Expand All @@ -14,4 +14,3 @@ class PmsRoom(models.Model):
required=True,
default="dirty",
)

2 changes: 1 addition & 1 deletion pms_housekeeping/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Housekeeping</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:de773807356222adab5ee772d075d86a64a8a09828b1e137748c9562380fe750
!! source digest: sha256:4807e347dd2088e7cfafc8201f1105b6162c3f0793e9b87f570b6ba38c1756e7
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/pms/tree/14.0/pms_housekeeping"><img alt="OCA/pms" src="https://img.shields.io/badge/github-OCA%2Fpms-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/pms-14-0/pms-14-0-pms_housekeeping"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/pms&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds housekeeping feature to property management system (PMS).</p>
Expand Down
7 changes: 6 additions & 1 deletion pms_housekeeping/views/hr_employee_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
<field name="inherit_id" ref="hr.view_employee_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='work_location']" position="after">
<field name="pre_assigned_room_ids" widget="many2many_tags" />
<field
name="pre_assigned_room_ids"
widget="many2many_tags"
attrs="{'invisible': [('job_name', '!=', 'Housekeeper')]}"
/>
<field name="job_name" invisible="1" />
</xpath>
</field>
</record>
Expand Down
Loading

0 comments on commit 662a287

Please sign in to comment.