Skip to content

Commit

Permalink
[WIP]14.0-pms_housekeeping: housekeeping task views
Browse files Browse the repository at this point in the history
  • Loading branch information
braisab committed Feb 12, 2024
1 parent 16d1ed3 commit b57b092
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 26 deletions.
1 change: 1 addition & 0 deletions pms_housekeeping/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"views/pms_housekeeping_task_type_views.xml",
"views/pms_housekeeping_views.xml",
"views/pms_housekeeping_task_views.xml",
"views/pms_room_views.xml",
],
"installable": True,
}
6 changes: 6 additions & 0 deletions pms_housekeeping/data/pms_housekeeping_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
<field name="name">Housekeeper</field>
<field name="state">open</field>
</record>
<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">
<field name="name">Promotion</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions pms_housekeeping/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
from . import hr_employee
from . import pms_housekeeping_task_type
from . import pms_housekeeping_task
from . import pms_housekeeping_cancellation_type
from . import pms_room
8 changes: 8 additions & 0 deletions pms_housekeeping/models/pms_housekeeping_cancellation_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from odoo import fields, models, api


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

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


class PmsHouseKeepingTask(models.Model):
Expand All @@ -17,10 +18,10 @@ class PmsHouseKeepingTask(models.Model):
required=True,
ondelete="restrict",
)
task_datetime = fields.Datetime(string="Date")
task_date = fields.Date(string="Date", required=True,)
state = fields.Selection(
selection=[
("holding", "On Holding"),
("pending", "Pending"),
("to_do", "To Do"),
("in_progress", "In Progress"),
("done", "Done"),
Expand All @@ -44,5 +45,70 @@ class PmsHouseKeepingTask(models.Model):
string="Parent Task",
help="Indicates that this task is a child of another task",
comodel_name="pms.housekeeping.task",
domain="[('id', '!=', id)]",
)
parent_state = fields.Char(
string="Parent State",
compute="_compute_parent_state",
)
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,
)
is_future = fields.Boolean(
string="Is Future",
compute="_compute_is_future",
)

@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")

def action_cancel(self):
for rec in self:
rec.state = "cancel"

def action_to_do(self):
for rec in self:
rec.state = "to_do"

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

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

def action_pending(self):
for rec in self:
rec.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):
for rec in self:
if rec.task_date:
rec.is_today = rec.task_date == fields.Date.today()
else:
rec.is_today = False
@api.depends("task_date")
def _compute_is_future(self):
for rec in self:
if rec.task_date:
rec.is_future = rec.task_date > fields.Date.today()
else:
rec.is_future = False
11 changes: 4 additions & 7 deletions pms_housekeeping/models/pms_housekeeping_task_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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",)
days_after_clean_empty = fields.Integer(string="Days After Clean", )
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(
comodel_name="hr.employee",
relation="pms_housekeeping_task_type_hr_employee_rel",
Expand All @@ -22,13 +22,10 @@ class PmsHouseKeepingTaskType(models.Model):
string="Housekeepers",
domain="[('job_id.name', '=', 'Housekeeper')]",
)
parent_id = fields.Many2many(
parent_id = fields.Many2one(
string="Parent Task Type",
help="Indicates that this task type is a child of another task type",
comodel_name="pms.housekeeping.task.type",
relation="pms_housekeeping_task_type_rel",
column1="parent_task_type_id",
column2="child_task_type_id",
ondelete="restrict",
domain="[('id', '!=', id)]",
)
is_inspection = fields.Boolean(string="Inspection")
17 changes: 17 additions & 0 deletions pms_housekeeping/models/pms_room.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import fields, models, api


class PmsRoom(models.Model):
_inherit = "pms.room"

housekeeping_state = fields.Selection(
selection=[
("dirty", "Dirty"),
("to_inspect", "To Inspect"),
("clean", "Clean"),
],
string="Housekeeping State",
required=True,
default="dirty",
)

1 change: 1 addition & 0 deletions pms_housekeeping/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
user_access_pms_housekeeping_task_type,user_access_pms_housekeeping_task_type,model_pms_housekeeping_task_type,pms.group_pms_user,1,1,1,1
user_access_pms_housekeeping_task,user_access_pms_housekeeping_task_,model_pms_housekeeping_task,pms.group_pms_user,1,1,1,1
user_access_pms_housekeeping_cancellation_type,user_access_pms_housekeeping_cancellation_type,model_pms_housekeeping_cancellation_type,pms.group_pms_user,1,1,1,1
35 changes: 22 additions & 13 deletions pms_housekeeping/views/pms_housekeeping_task_type_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@
<tree string="Housekeeping Task Type">
<field name="name"/>
<field name="is_automated"/>
<field name="is_inspection"/>
<field name="housekeepers" widget="many2many_tags" />
<field name="parent_id" widget="many2many_tags" />
<field name="parent_id" />
<field name="description" />
<field name="priority" attrs="{'invisible': [('is_automated', '==', False)]}"/>
<field name="is_overnight" attrs="{'invisible': [('is_automated', '==', False)]}"/>
Expand All @@ -28,18 +29,26 @@
<field name="arch" type="xml">
<form string="Housekeeping Task Type">
<group>
<field name="name"/>
<field name="is_automated"/>
<field name="housekeepers" widget="many2many_tags" />
<field name="parent_id" widget="many2many_tags" />
<field name="description" />
<field name="priority" attrs="{'invisible': [('is_automated', '==', False)]}"/>
<field name="is_overnight" attrs="{'invisible': [('is_automated', '==', False)]}"/>
<field name="is_empty" attrs="{'invisible': [('is_automated', '==', False)]}"/>
<field name="is_checkin" attrs="{'invisible': [('is_automated', '==', False)]}"/>
<field name="is_checkout" attrs="{'invisible': [('is_automated', '==', False)]}"/>
<field name="days_after_clean_overnight" attrs="{'invisible': [('is_automated', '==', False), ('is_overnight', '==', False)]}"/>
<field name="days_after_clean_empty" attrs="{'invisible': [('is_automated', '==', False), ('is_empty', '==', False)]}"/>

<group>
<field name="name"/>
<field name="is_automated"/>
<field name="is_inspection"/>
<field name="housekeepers" widget="many2many_tags" />
<field name="parent_id" />
<field name="description" />
</group>

<group attrs="{'invisible': [('is_automated', '==', False)]}">
<field name="priority" />
<field name="is_overnight" />
<field name="is_empty" />
<field name="is_checkin" />
<field name="is_checkout" />
<field name="days_after_clean_overnight" attrs="{'invisible': [('is_overnight', '==', False)]}"/>
<field name="days_after_clean_empty" attrs="{'invisible': [('is_empty', '==', False)]}"/>
</group>

</group>
</form>
</field>
Expand Down
47 changes: 44 additions & 3 deletions pms_housekeeping/views/pms_housekeeping_task_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,63 @@
<field name="arch" type="xml">
<form string="Housekeeping Task">
<header>
<field name="state" widget="statusbar" />
<button
name="action_pending"
string="Mark as Pending"
class="oe_highlight"
type="object"
attrs="{'invisible': [('state', '!=', 'cancel'), ('is_today', '=', True)]}"
/>
<button
name="action_to_do"
string="Mark as To Do"
class="oe_highlight"
type="object"
attrs="{'invisible':[('state' ,'=', 'to_do'), ('is_today', '=', False), ('is_future', '=', True)]}"
/>
<button
name="action_in_progress"
string="Mark as In Progress"
class="oe_highlight"
type="object"
attrs="{'invisible':[('state','in', ('done', 'in_progress', 'cancel', 'pending'))]}"
/>
<button
name="action_done"
string="Mark as Done"
class="oe_highlight"
type="object"
attrs="{'invisible':[('state' ,'in', ('done', 'to_do', 'cancel', 'pending'))]}"
/>
<button
name="action_cancel"
string="Cancel Task"
type="object"
attrs="{'invisible':[('state','in', ('done', 'in_progress', 'cancel'))]}"
/>
<field name="state" widget="statusbar"/>
</header>
<group class="col-6">
<field name="name" />
<field name="room_id" />
<field name="task_type_id" />
<field name="parent_state" />
<field name="is_today" />
<field name="is_future" />

</group>
<group class="col-6">
<field name="task_datetime" />
<field name="task_date" />
<field name="priority" />
<field name="employee_ids" widget="many2many_tags"/>
</group>
<group class="col-12">
<field name="parent_id" widget="many2many_tags"/>
<field name="parent_id"/>
<field name="cleaning_comments" />
</group>
<group class="col-12">
<field name="cancellation_type_id" attrs="{'invisible': [('state', '!=', 'cancel')]}"/>
</group>
</form>
</field>
</record>
Expand Down
13 changes: 13 additions & 0 deletions pms_housekeeping/views/pms_room_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="pms_housekeeping_room" model="ir.ui.view">
<field name="model">pms.room</field>
<field name="inherit_id" ref="pms.pms_room_view_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='short_name']" position="after">
<field name="housekeeping_state" />
</xpath>
</field>
</record>

</odoo>

0 comments on commit b57b092

Please sign in to comment.