[IMP]14.0-pms_housekeeping: new hr_employee inherit and housekeeping_task_type model

This commit is contained in:
braisab
2024-02-07 18:01:33 +01:00
committed by Darío Lodeiros
parent 3e14695c56
commit 9c5fbd03d8
21 changed files with 144 additions and 1246 deletions

View File

@@ -1,7 +1,5 @@
# Copyright 2021 Jose Luis Algara
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import pms_housekeeping_task
from . import pms_housekeeping
from . import pms_reservation
from . import pms_room
from . import hr_employee
from . import pms_housekeeping_task_type

View File

@@ -0,0 +1,14 @@
# 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
class HrEmployee(models.Model):
_inherit = "hr.employee"
pre_assigned_room_ids = fields.Many2many(
comodel_name="pms.room",
string="Pre Assigned Rooms",
help="Rooms pre assigned to this employee",
)

View File

@@ -1,42 +0,0 @@
# 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
class HouseKeeping(models.Model):
_name = "pms.housekeeping"
_description = "HouseKeeping"
# HouseKeeping 'log'
# Fields declaration
task_date = fields.Date(
string="Clean date", default=lambda self: fields.Datetime.now(), required=True
)
task_start = fields.Datetime(string="Task start at")
task_end = fields.Datetime(string="Task end at")
room_id = fields.Many2one("pms.room", string="Room")
employee_id = fields.Many2one("hr.employee", string="Employee")
task_id = fields.Many2one("pms.housekeeping.task", string="Task", required=True)
notes = fields.Text("Internal Notes")
lostfound = fields.Text("Lost and Found")
state = fields.Selection(
string="Task State",
selection=[
("draft", "Draft"),
("to_do", "To Do"),
("in_progress", "In Progress"),
("done", "Done"),
],
default="draft",
)
color = fields.Integer("Color Index")
# Default Methods ang Gets
def name_get(self):
result = []
for task in self:
name = task.task_id.name
result.append((task.id, name))
return result

View File

@@ -1,42 +0,0 @@
# 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
class HouseKeepingTask(models.Model):
_name = "pms.housekeeping.task"
_description = "HouseKeeping Tasks"
# HouseKeeping 'Task types'
# Fields declaration
active = fields.Boolean("Active", default=True)
name = fields.Char("Task Name", translate=True, required=True)
pms_property_ids = fields.Many2many(
string="Properties",
help="Properties with access to the element;"
" if not set, all properties can access",
required=False,
comodel_name="pms.property",
relation="pms_housekeepink_task_pms_property_rel",
column1="pms_housekeepink_task_id",
column2="pms_property_id",
ondelete="restrict",
check_pms_properties=True,
)
clean_type = fields.Selection(
string="Clean type",
selection=[
("occupied", "Occupied"),
("exit", "Exit"),
("picked_up", "Picked up"),
("staff", "Staff"),
("clean", "Clean"),
("inspected", "Inspected"),
("dont_disturb", "Don't disturb"),
],
)
def_employee_id = fields.Many2one(
"hr.employee", string="Employee assigned by default"
)

View File

@@ -0,0 +1,40 @@
from odoo import fields, models
class PmsHouseKeepingTaskType(models.Model):
_name = "pms.housekeeping.task.type"
name = fields.Char(string="Name", required=True)
description = fields.Text(string="Description")
is_automated = fields.Boolean(string="Is Automated")
clean_event = fields.Selection(
selection=[
("overnight", "Overnight"),
("checkin", "Checkin"),
("checkout", "Checkout"),
("empty", "Empty"),
("priority", "Priority"),
],
string="Clean When",
required=True,
default="overnight",
)
days_after_clean_event = fields.Integer(string="Days After Clean Event")
housekeepers = fields.Many2many(
comodel_name="hr.employee",
relation="pms_housekeeping_task_type_hr_employee_rel",
column1="task_type_id",
column2="employee_id",
string="Housekeepers",
domain="[('job_id.name', '=', 'Housekeeper')]",
)
parent_id = fields.Many2many(
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)]",
)

View File

@@ -1,13 +0,0 @@
# Copyright 2021 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
class PmsRoom(models.Model):
_inherit = "pms.reservation"
dont_disturb = fields.Boolean(
string="Dont disturb",
default=False,
)

View File

@@ -1,140 +0,0 @@
# Copyright 2021 Jose Luis Algara (Alda Hotels <https://www.aldahotels.es>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import logging
from datetime import datetime, timedelta
from odoo import fields, models
_logger = logging.getLogger(__name__)
def kanban_card_color(state):
colors = {
"occupied": 2,
"exit": 3,
"picked_up": 7,
"staff": 11,
"clean": 4,
"inspected": 10,
"dont_disturb": 9,
}
return colors[state]
class PmsRoom(models.Model):
_inherit = "pms.room"
housekeeping_ids = fields.One2many(
string="Housekeeping tasks",
comodel_name="pms.housekeeping",
inverse_name="room_id",
domain=[("task_date", "=", datetime.now().date())],
)
clean_status = fields.Selection(
string="Clean type",
selection=[
("occupied", "Occupied"),
("exit", "Exit"),
("picked_up", "Picked up"),
("staff", "Staff"),
("clean", "Clean"),
("inspected", "Inspected"),
("dont_disturb", "Don't disturb"),
],
compute="_compute_clean_status",
# store=True,
)
clean_employee_id = fields.Many2one(
"hr.employee",
string="Default employee",
help="Cleaning employee assigned by default",
)
employee_picture = fields.Binary(
string="Employee picture", related="clean_employee_id.image_1920"
)
# @api.depends('clean_status_now')
def _compute_clean_status(self):
for room in self:
room.clean_status = room.get_clean_status()
return
# Business methods
def get_clean_status(self, date_clean=False, margin_days=5):
status = "NONE"
if not date_clean:
date_clean = fields.Date.today()
reservations = self.env["pms.reservation.line"].search(
[
("room_id", "=", self.id),
("date", "<=", date_clean + timedelta(days=margin_days)),
("date", ">=", date_clean - timedelta(days=margin_days)),
]
)
today_res = reservations.filtered(
lambda reservation: reservation.date == date_clean
)
yesterday_res = reservations.filtered(
lambda reservation: reservation.date == date_clean - (timedelta(days=1))
)
lasts_res = reservations.filtered(
lambda reservation: reservation.date < date_clean
)
if today_res.reservation_id.reservation_type == "out":
status = "dont_disturb"
return status
if len(today_res) == 0:
if len(yesterday_res) != 0:
status = "exit"
elif len(lasts_res) != 0:
status = "clean"
else:
# TODO hace cuantos dias se limpio o repaso.??
status = "picked_up"
return status
else:
if yesterday_res.reservation_id != today_res.reservation_id:
status = "exit"
else:
if today_res.reservation_id.reservation_type == "staff":
status = "staff"
elif today_res.reservation_id.dont_disturb:
status = "dont_disturb"
else:
status = "occupied"
# TODO hace cuantos dias que la ocupa.??
return status
def add_today_tasks(self):
for room in self:
tasks = self.env["pms.housekeeping.task"].search(
[("clean_type", "=", room.clean_status)]
)
for task in tasks:
new_task = self.env["pms.housekeeping"]
employee = (
task.def_employee_id.id
if len(task.def_employee_id) > 0
else room.clean_employee_id.id
)
new_task.create(
{
"room_id": room.id,
"employee_id": employee,
"task_id": task.id,
"state": "draft",
"color": kanban_card_color(room.clean_status),
}
)
return
def add_all_today_tasks(self):
rooms = self.env["pms.room"].search([])
_logger.warning("Init Add All today Task")
for room in rooms:
room.add_today_tasks()
return