mirror of
https://bitbucket.org/presik/trytonpsk-hotel.git
synced 2023-12-14 07:52:52 +01:00
242 lines
8.3 KiB
Python
242 lines
8.3 KiB
Python
# This file is part of Presik. The COPYRIGHT file at the top level of
|
|
# this repository contains the full copyright notices and license terms.
|
|
from trytond.pyson import Eval
|
|
from trytond.model import Workflow, ModelView, ModelSQL, fields, Unique
|
|
from trytond.wizard import Wizard, StateView, Button, StateReport
|
|
from trytond.report import Report
|
|
from trytond.transaction import Transaction
|
|
from datetime import datetime
|
|
from trytond.pool import Pool
|
|
|
|
STATES = {'invisible': (Eval('type') != 'service')}
|
|
|
|
|
|
class HousekeepingCleaningType(ModelSQL, ModelView):
|
|
"Housekeeping Cleaning Type"
|
|
__name__ = "hotel.housekeeping.cleaning_type"
|
|
name = fields.Char('Name', required=True, select=True)
|
|
description = fields.Text('Description')
|
|
|
|
|
|
class Housekeeping(Workflow, ModelSQL, ModelView):
|
|
'HouseKeeping'
|
|
__name__ = 'hotel.housekeeping'
|
|
employee = fields.Many2One('company.employee', 'Employee')
|
|
room = fields.Many2One('hotel.room', 'Room', required=True)
|
|
state = fields.Selection([
|
|
('inspected', 'Inspected'),
|
|
('dirty', 'Dirty'),
|
|
('clean', 'Clean'),
|
|
('maintenance', 'Maintenance'),
|
|
], 'Status', required=True, readonly=True)
|
|
state_string = state.translated('state')
|
|
availability = fields.Selection([
|
|
('blocked', 'Blocked'),
|
|
('available', 'Available'),
|
|
('occupied', 'Occupied'),
|
|
], 'Availability', required=True)
|
|
cleaning_type = fields.Many2One('hotel.housekeeping.cleaning_type',
|
|
'Cleaning Type', required=False)
|
|
availability_string = state.translated('availability')
|
|
check_list = fields.Text('Check List')
|
|
tasks = fields.One2Many('hotel.housekeeping.task', 'housekeeping',
|
|
'House Tasks')
|
|
start_date_assigned = fields.Date('Start Date Assigned')
|
|
end_date_assigned = fields.Date('End Date Assigned')
|
|
notes = fields.Text('Notes')
|
|
check_in_time = fields.Function(fields.Time('Check In Time'), 'get_check_in_time')
|
|
check_out_time = fields.Function(fields.Time('Check In Time'), 'get_check_out_time')
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(Housekeeping, cls).__setup__()
|
|
t = cls.__table__()
|
|
cls._sql_constraints += [
|
|
('room_uniq', Unique(t, t.room), 'The room must be unique.'),
|
|
]
|
|
cls._transitions |= set((
|
|
('clean', 'dirty'),
|
|
('clean', 'inspected'),
|
|
('clean', 'maintenance'),
|
|
('dirty', 'clean'),
|
|
('dirty', 'maintenance'),
|
|
('dirty', 'inspected'),
|
|
('maintenance', 'inspected'),
|
|
('maintenance', 'dirty'),
|
|
('inspected', 'dirty'),
|
|
('inspected', 'maintenance'),
|
|
('inspected', 'clean'),
|
|
))
|
|
cls._buttons.update({
|
|
'clean': {
|
|
'invisible': Eval('state').in_(['maintenance', 'clean']),
|
|
},
|
|
'dirty': {
|
|
'invisible': Eval('state').in_(['dirty']),
|
|
},
|
|
'inspected': {
|
|
'invisible': Eval('state').in_(['inspected']),
|
|
},
|
|
'maintenance': {
|
|
'invisible': Eval('state').in_(['maintenance']),
|
|
},
|
|
})
|
|
|
|
@staticmethod
|
|
def default_state():
|
|
return 'clean'
|
|
|
|
@staticmethod
|
|
def default_avaibility():
|
|
return 'available'
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('clean')
|
|
def clean(cls, records):
|
|
for rec in records:
|
|
rec.cleaning_type = None
|
|
rec.save()
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('dirty')
|
|
def dirty(cls, records):
|
|
Config = Pool().get('hotel.configuration')
|
|
config = Config.get_configuration()
|
|
for rec in records:
|
|
rec.cleaning_type = config.cleaning_occupied.id
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('maintenance')
|
|
def maintenance(cls, records):
|
|
pass
|
|
|
|
@classmethod
|
|
@ModelView.button
|
|
@Workflow.transition('inspected')
|
|
def inspected(cls, records):
|
|
pass
|
|
|
|
def get_check_in_time(self, name):
|
|
pool = Pool()
|
|
Date = pool.get('ir.date')
|
|
Configuration = pool.get('hotel.configuration')
|
|
BookingFolio = pool.get('hotel.folio')
|
|
config = Configuration.get_configuration()
|
|
lines = BookingFolio.search_read([
|
|
('room', '=', self.room.id),
|
|
('arrival_date', '=', Date.today()),
|
|
], fields_names=['id'])
|
|
if lines:
|
|
return config.check_in_time.strftime('%H:%M %p')
|
|
|
|
def get_check_out_time(self, name):
|
|
pool = Pool()
|
|
Date = pool.get('ir.date')
|
|
Configuration = pool.get('hotel.configuration')
|
|
Operation = pool.get('hotel.operation')
|
|
config = Configuration.get_configuration()
|
|
operations = Operation.search_read([
|
|
('room', '=', self.room.id),
|
|
('end_date', '=', Date.today()),
|
|
], fields_names=['id'])
|
|
if operations:
|
|
return config.check_out_time.strftime('%H:%M %p')
|
|
|
|
# def get_occupancies(self, name):
|
|
# pool = Pool()
|
|
# OccupancyLine = pool.get('hotel.occupancy.line')
|
|
# occupancies = set()
|
|
# lines = OccupancyLine.search([
|
|
# ('room.id', '=', self.room.id),
|
|
# ('occupancy.state', '=', 'confirmed'),
|
|
# ])
|
|
# for line in lines:
|
|
# occupancies.add(line.id)
|
|
# return list(occupancies)
|
|
|
|
|
|
class HotelTask(ModelSQL, ModelView):
|
|
"Hotel Task"
|
|
__name__ = "hotel.task"
|
|
name = fields.Char('Name Task', required=True, select=True)
|
|
frecuency = fields.Integer('Frecuency', select=True, help='In days')
|
|
quantity = fields.Integer('Quantity', select=True)
|
|
|
|
|
|
class HotelHousekeepingTask(ModelView, ModelSQL):
|
|
'Hotel Housekeeping Task'
|
|
__name__ = 'hotel.housekeeping.task'
|
|
housekeeping = fields.Many2One('hotel.housekeeping', 'Hotel Housekeeping',
|
|
ondelete='CASCADE', select=True, required=True)
|
|
task = fields.Many2One('hotel.task', 'Task', select=True, required=True)
|
|
frecuency = fields.Integer('Frecuency', select=True, help='In days')
|
|
quantity = fields.Integer('Quantity', select=True)
|
|
|
|
@fields.depends('task', 'frecuency')
|
|
def on_change_task(self, name=None):
|
|
if self.task:
|
|
self.frecuency = self.task.frecuency
|
|
|
|
|
|
class HousekeepingServiceStart(ModelView):
|
|
'Print Housekeeping service Start'
|
|
__name__ = 'hotel.print_housekeeping_service.start'
|
|
date = fields.Date('Date', required=True)
|
|
employee = fields.Many2One('company.employee', 'Employee')
|
|
company = fields.Many2One('company.company', 'Company', required=True)
|
|
|
|
@staticmethod
|
|
def default_date():
|
|
Date_ = Pool().get('ir.date')
|
|
return Date_.today()
|
|
|
|
@staticmethod
|
|
def default_company():
|
|
return Transaction().context.get('company')
|
|
|
|
|
|
class HousekeepingService(Wizard):
|
|
'Housekeeping Service'
|
|
__name__ = 'hotel.print_housekeeping_service'
|
|
start = StateView('hotel.print_housekeeping_service.start',
|
|
'hotel.print_housekeeping_service_start_view_form', [
|
|
Button('Cancel', 'end', 'tryton-cancel'),
|
|
Button('Open', 'print_', 'tryton-print', default=True),
|
|
])
|
|
print_ = StateReport('hotel.print_housekeeping_service.report')
|
|
|
|
def do_print_(self, action):
|
|
company = self.start.company
|
|
data = {
|
|
'date': self.start.date,
|
|
'employee': self.start.employee.id if self.start.employee else None,
|
|
'company': company.id,
|
|
}
|
|
return action, data
|
|
|
|
def transition_print_(self):
|
|
return 'end'
|
|
|
|
|
|
class HousekeepingServiceReport(Report):
|
|
__name__ = 'hotel.print_housekeeping_service.report'
|
|
|
|
@classmethod
|
|
def get_context(cls, records, header, data):
|
|
report_context = super().get_context(records, header, data)
|
|
pool = Pool()
|
|
Company = pool.get('company.company')
|
|
Housekeeping = pool.get('hotel.housekeeping')
|
|
|
|
dom = []
|
|
if data['employee']:
|
|
dom.append(('employee.id', '=', data['employee']))
|
|
|
|
housekeepings = Housekeeping.search(dom)
|
|
report_context['records'] = housekeepings
|
|
report_context['company'] = Company(data['company']).party.name
|
|
report_context['date'] = datetime.now()
|
|
return report_context
|