Files
pms/hotel_door_codes/models/inherit_hotel_reservation.py
Darío Lodeiros 15f222bcbf [MIG] Views
2020-07-09 09:37:03 +02:00

80 lines
3.4 KiB
Python

# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2018-2019 Alda Hotels <informatica@aldahotels.com>
# Jose Luis Algara <osotranquilo@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp import models, fields, api, _
from datetime import datetime, timedelta
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
class Inherit_hotel_reservation(models.Model):
_inherit = 'hotel.reservation'
# Default methods
def _compute_door_codes(self):
for res in self:
entrada = datetime.strptime(
res.checkin[:10], DEFAULT_SERVER_DATE_FORMAT)
if datetime.weekday(entrada) == 0:
entrada = entrada + timedelta(days=1)
salida = datetime.strptime(
res.checkout[:10], DEFAULT_SERVER_DATE_FORMAT)
if datetime.weekday(salida) == 0:
salida = salida - timedelta(days=1)
codes = (_('Entry Code: ') +
'<strong><span style="font-size: 1.4em;">' +
res.doorcode4(datetime.strftime(entrada, "%Y-%m-%d")) +
'</span></strong>')
while entrada <= salida:
if datetime.weekday(entrada) == 0:
codes += ("<br>" +
_('It will change on Monday ') +
datetime.strftime(entrada, "%d-%m-%Y") +
_(' to: ') +
'<strong><span style="font-size: 1.4em;">' +
res.doorcode4(datetime.strftime(
entrada, "%Y-%m-%d")) +
'</span></strong>')
entrada = entrada + timedelta(days=1)
res.door_codes = codes
# Fields declaration
door_codes = fields.Html(
'Door Codes',
compute='_compute_door_codes')
box_number = fields.Integer('Box Number')
box_code = fields.Char('Box code')
def doorcode4(self, fecha):
# Calculate de Door Code... need a date in String format "%Y-%m-%d"
compan = self.env.user.hotel_id
if not compan.precode:
compan.precode = " "
if not compan.postcode:
compan.postcode = " "
d = datetime.strptime(fecha, DEFAULT_SERVER_DATE_FORMAT)
dia_semana = datetime.weekday(d) # Dias a restar y ponerlo en lunes
d = d - timedelta(days=dia_semana)
dtxt = d.strftime('%s.%%06d') % d.microsecond
dtxt = compan.precode + dtxt[4:8] + compan.postcode
return dtxt