[WIP] refactoring hotel settings

This commit is contained in:
Pablo
2019-08-28 19:35:30 +02:00
committed by Dario Lodeiros
parent beda76c168
commit f035d4ba75
26 changed files with 108 additions and 275 deletions

View File

@@ -25,7 +25,6 @@ from . import hotel_room_type_restriction_item
from . import hotel_reservation_line
from . import hotel_checkin_partner
from . import inherited_product_pricelist
from . import res_config
from . import inherited_res_partner
from . import inherited_mail_compose_message
from . import hotel_room_type_class

View File

@@ -12,6 +12,6 @@ class HotelRoomAmenitie(models.Model):
default_code = fields.Char('Internal Reference')
room_amenity_type_id = fields.Many2one('hotel.amenity.type',
'Amenity Catagory')
hotel_ids = fields.Many2many('hotel.property', 'Hotels', required=False, ondelete='restrict')
hotel_ids = fields.Many2many('hotel.property', string='Hotels', required=False, ondelete='restrict')
#TODO: Constrain coherence hotel_ids with amenity types hotel_ids

View File

@@ -13,6 +13,6 @@ class HotelRoomAmenitieType(models.Model):
room_amenity_ids = fields.One2many('hotel.amenity',
'room_amenity_type_id',
'Amenities in this category')
hotel_ids = fields.Many2many('hotel.property', 'Hotels', required=False, ondelete='restrict')
hotel_ids = fields.Many2many('hotel.property', string='Hotels', required=False, ondelete='restrict')
#TODO: Constrain coherence hotel_ids with amenities hotel_ids

View File

@@ -4,6 +4,7 @@
from odoo import models, fields
# TODO: refactoring to cancellation.rule
class HotelCancelationRule(models.Model):
_name = 'hotel.cancelation.rule'
_description = 'Cancelation Rules'

View File

@@ -189,14 +189,12 @@ class HotelCheckinPartner(models.Model):
def _get_arrival_hour(self):
self.ensure_one()
tz_hotel = self.env['ir.default'].sudo().get(
'res.config.settings', 'tz_hotel')
tz_hotel = self.env.user.hotel_id.tz
today = fields.Datetime.context_timestamp(
self.with_context(tz=tz_hotel),
datetime.datetime.strptime(fields.Date.today(),
DEFAULT_SERVER_DATE_FORMAT))
default_arrival_hour = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_arrival_hour')
default_arrival_hour = self.env.user.hotel_id.arrival_hour
if self.reservation_id.checkin < today.strftime(DEFAULT_SERVER_DATE_FORMAT):
return default_arrival_hour
now = fields.Datetime.context_timestamp(
@@ -208,14 +206,12 @@ class HotelCheckinPartner(models.Model):
def _get_departure_hour(self):
self.ensure_one()
tz_hotel = self.env['ir.default'].sudo().get(
'res.config.settings', 'tz_hotel')
tz_hotel = self.env.user.hotel_id.tz
today = fields.Datetime.context_timestamp(
self.with_context(tz=tz_hotel),
datetime.datetime.strptime(fields.Date.today(),
DEFAULT_SERVER_DATE_FORMAT))
default_departure_hour = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_departure_hour')
default_departure_hour = self.env.user.hotel_id.departure_hour
if self.reservation_id.checkout < today.strftime(DEFAULT_SERVER_DATE_FORMAT):
return default_departure_hour
now = fields.Datetime.context_timestamp(

View File

@@ -462,8 +462,8 @@ class HotelFolio(models.Model):
addr = self.partner_id.address_get(['invoice'])
pricelist = self.partner_id.property_product_pricelist and \
self.partner_id.property_product_pricelist.id or \
self.env['ir.default'].sudo().get('res.config.settings', 'default_pricelist_id')
self.partner_id.property_product_pricelist.id or \
self.env.user.hotel_id.pricelist_id.id
values = {
'pricelist_id': pricelist,
'payment_term_id': self.partner_id.property_payment_term_id and self.partner_id.property_payment_term_id.id or False,

View File

@@ -2,7 +2,9 @@
# Copyright 2019 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, api, fields
import re
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class HotelProperty(models.Model):
@@ -18,4 +20,29 @@ class HotelProperty(models.Model):
string='Accepted Users')
room_type_ids = fields.One2many('hotel.room.type', 'hotel_id', 'Room Types')
room_ids = fields.One2many('hotel.room', 'hotel_id', 'Room')
room_ids = fields.One2many('hotel.room', 'hotel_id', 'Rooms')
# TODO: refactoring res.config.settings', 'default_pricelist_id' by the current hotel.property.pricelist_id
pricelist_id = fields.Many2one('product.pricelist', 'Product Pricelist',
help='The default pricelist used in this hotel.',
required=True)
# TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id
restriction_id = fields.Many2one('hotel.room.type.restriction', 'Restriction Plan',
help='The default restriction plan used in this hotel.',
required=True)
# TODO: refactoring 'res.config.settings', 'default_arrival_hour' by the current hotel.property.arrival_hour
arrival_hour = fields.Char('Arrival Hour (GMT)',
help="HH:mm Format", default="14:00")
# TODO: refactoring 'res.config.settings', 'default_departure_hour' by the current hotel.property.departure_hour
departure_hour = fields.Char('Departure Hour (GMT)',
help="HH:mm Format", default="12:00")
# TODO: refactoring 'res.config.settings', 'tz_hotel' by the current hotel.property.tz (inherited in res.partner)
def _check_hours(self):
r = re.compile('[0-2][0-9]:[0-5][0-9]')
if not r.match(self.arrival_hour):
raise ValidationError(_("Invalid arrival hour (Format: HH:mm)"))
if not r.match(self.departure_hour):
raise ValidationError(_("Invalid departure hour (Format: HH:mm)"))

View File

@@ -31,8 +31,7 @@ class HotelReservation(models.Model):
if folio and folio.room_lines:
return folio.room_lines[0].checkin
else:
tz_hotel = self.env['ir.default'].sudo().get(
'res.config.settings', 'tz_hotel')
tz_hotel = self.env.user.hotel_id.tz
today = fields.Date.context_today(self.with_context(tz=tz_hotel))
return fields.Date.from_string(today).strftime(DEFAULT_SERVER_DATE_FORMAT)
@@ -45,16 +44,14 @@ class HotelReservation(models.Model):
if folio and folio.room_lines:
return folio.room_lines[0].checkout
else:
tz_hotel = self.env['ir.default'].sudo().get(
'res.config.settings', 'tz_hotel')
tz_hotel = self.env.user.hotel_id.tz
today = fields.Date.context_today(self.with_context(tz=tz_hotel))
return (fields.Date.from_string(today) + timedelta(days=1)).strftime(
DEFAULT_SERVER_DATE_FORMAT)
def _get_default_arrival_hour(self):
folio = False
default_arrival_hour = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_arrival_hour')
default_arrival_hour = self.env.user.hotel_id.arrival_hour
if 'folio_id' in self._context:
folio = self.env['hotel.folio'].search([
('id', '=', self._context['folio_id'])
@@ -66,8 +63,7 @@ class HotelReservation(models.Model):
def _get_default_departure_hour(self):
folio = False
default_departure_hour = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_departure_hour')
default_departure_hour = self.env.user.hotel_id.departure_hour
if 'folio_id' in self._context:
folio = self.env['hotel.folio'].search([
('id', '=', self._context['folio_id'])
@@ -226,7 +222,7 @@ class HotelReservation(models.Model):
partner_id = fields.Many2one(related='folio_id.partner_id')
tour_operator_id = fields.Many2one(related='folio_id.tour_operator_id')
partner_invoice_id = fields.Many2one(related='folio_id.partner_invoice_id')
partner_invoice_id = fields.Many2one(related='folio_id.partner_invoice_id')
partner_invoice_vat = fields.Char(related="partner_invoice_id.vat")
partner_invoice_name = fields.Char(related="partner_invoice_id.name")
partner_invoice_street = fields.Char(related="partner_invoice_id.street")
@@ -673,8 +669,8 @@ class HotelReservation(models.Model):
def onchange_partner_id(self):
addr = self.partner_id.address_get(['invoice'])
pricelist = self.partner_id.property_product_pricelist and \
self.partner_id.property_product_pricelist.id or \
self.env['ir.default'].sudo().get('res.config.settings', 'default_pricelist_id')
self.partner_id.property_product_pricelist.id or \
self.env.user.hotel_id.pricelist_id.id
values = {
'pricelist_id': pricelist,
'partner_invoice_id': addr['invoice'],
@@ -896,8 +892,7 @@ class HotelReservation(models.Model):
self.ensure_one()
pricelist = self.pricelist_id
if pricelist and pricelist.cancelation_rule_id:
tz_hotel = self.env['ir.default'].sudo().get(
'res.config.settings', 'tz_hotel')
tz_hotel = self.env.user.hotel_id.tz
today = fields.Date.context_today(self.with_context(
tz=tz_hotel))
days_diff = (fields.Date.from_string(self.real_checkin) -

View File

@@ -14,20 +14,18 @@ class HotelRoomTypeRestriction(models.Model):
item_ids = fields.One2many('hotel.room.type.restriction.item',
'restriction_id', string='Restriction Items',
copy=True)
active = fields.Boolean('Active',
help='If unchecked, it will allow you to hide the \
restriction plan without removing it.',
default=True)
hotel_id = fields.Many2one('hotel.property', default=_get_default_hotel,
required=True, ondelete='cascade')
active = fields.Boolean('Active', default=True,
help='If unchecked, it will allow you to hide the '
'restriction plan without removing it.')
hotel_ids = fields.One2many('hotel.property',
'restriction_id', string='Restriction Plan',
default=_get_default_hotel, required=True)
@api.multi
@api.depends('name')
def name_get(self):
restriction_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_restriction_id')
if restriction_id:
restriction_id = int(restriction_id)
# TODO: refactoring res.config.settings', 'default_restriction_id by the current hotel.property.restriction_id
restriction_id = self.env.user.hotel_id.restriction_id.id
names = []
for record in self:
if record.id == restriction_id:

View File

@@ -21,8 +21,10 @@ class HotelRoomTypeRestrictionItem(models.Model):
closed = fields.Boolean('Closed')
closed_departure = fields.Boolean('Closed Departure')
closed_arrival = fields.Boolean('Closed Arrival')
hotel_id = fields.Many2one('hotel.property', store=True, readonly=True,
related='restriction_id.hotel_id')
hotel_ids = fields.One2many('hotel.property',
'restriction_id', string='Restriction Plan',
store=True, readonly=True,
related='restriction_id.hotel_ids')
_sql_constraints = [('room_type_registry_unique',
'unique(restriction_id, room_type_id, date)',
@@ -37,7 +39,7 @@ class HotelRoomTypeRestrictionItem(models.Model):
raise ValidationError(_("Min. Stay can't be less than zero"))
elif record.min_stay_arrival < 0:
raise ValidationError(
("Min. Stay Arrival can't be less than zero"))
_("Min. Stay Arrival can't be less than zero"))
elif record.max_stay < 0:
raise ValidationError(_("Max. Stay can't be less than zero"))
elif record.max_stay_arrival < 0:

View File

@@ -14,21 +14,7 @@ class ProductPricelist(models.Model):
cancelation_rule_id = fields.Many2one(
'hotel.cancelation.rule',
string="Cancelation Policy")
hotel_ids = fields.Many2many('hotel.property', string='Hotels', required=False,
ondelete='restrict')
@api.multi
@api.depends('name')
def name_get(self):
pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_pricelist_id')
if pricelist_id:
pricelist_id = int(pricelist_id)
org_names = super(ProductPricelist, self).name_get()
names = []
for name in org_names:
if name[0] == pricelist_id:
names.append((name[0], '%s (Default)' % name[1]))
else:
names.append((name[0], name[1]))
return names

View File

@@ -1,86 +0,0 @@
# Copyright 2017-2018 Alexandre Díaz
# Copyright 2017 Dario Lodeiros
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import re
import pytz
from openerp import models, fields, api, _
from openerp.exceptions import ValidationError
@api.model
def _tz_get(self):
# put POSIX 'Etc/*' entries at the end to avoid confusing users
# see bug 1086728
return [(tz, tz) for tz in sorted(pytz.all_timezones,
key=lambda tz: tz
if not tz.startswith('Etc/') else '_')]
class HotelConfiguration(models.TransientModel):
_inherit = 'res.config.settings'
default_pricelist_id = fields.Many2one('product.pricelist',
'Product Pricelist')
default_restriction_id = fields.Many2one('hotel.room.type.restriction',
'Restrictions')
default_arrival_hour = fields.Char('Default Arrival Hour (GMT)',
help="HH:mm Format", default="14:00")
default_departure_hour = fields.Char('Default Departure Hour (GMT)',
help="HH:mm Format", default="12:00")
tz_hotel = fields.Selection(_tz_get, string='Timezone',
default=lambda self: self._context.get('tz'),
help="The hotel's timezone, used to manage \
date and time values in reservations \
It is important to set a value for this \
field.")
@api.multi
def set_values(self):
super(HotelConfiguration, self).set_values()
self.env['ir.default'].sudo().set(
'res.config.settings', 'default_pricelist_id',
self.default_pricelist_id.id)
self.env['ir.default'].sudo().set(
'res.config.settings', 'default_restriction_id',
self.default_restriction_id.id)
self.env['ir.default'].sudo().set(
'res.config.settings', 'tz_hotel', self.tz_hotel)
self.env['ir.default'].sudo().set(
'res.config.settings', 'default_arrival_hour',
self.default_arrival_hour)
self.env['ir.default'].sudo().set(
'res.config.settings', 'default_departure_hour',
self.default_departure_hour)
@api.model
def get_values(self):
res = super(HotelConfiguration, self).get_values()
# ONLY FOR v11. DO NOT FORWARD-PORT
default_pricelist_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_pricelist_id')
default_restriction_id = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_restriction_id')
tz_hotel = self.env['ir.default'].sudo().get(
'res.config.settings', 'tz_hotel')
default_arrival_hour = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_arrival_hour')
default_departure_hour = self.env['ir.default'].sudo().get(
'res.config.settings', 'default_departure_hour')
res.update(
default_pricelist_id=default_pricelist_id,
default_restriction_id=default_restriction_id,
tz_hotel=tz_hotel,
default_arrival_hour=default_arrival_hour,
default_departure_hour=default_departure_hour,
)
return res
@api.constrains('default_arrival_hour', 'default_departure_hour')
def _check_hours(self):
r = re.compile('[0-2][0-9]:[0-5][0-9]')
if not r.match(self.default_arrival_hour):
raise ValidationError(_("Invalid arrival hour (Format: HH:mm)"))
if not r.match(self.default_departure_hour):
raise ValidationError(_("Invalid departure hour (Format: HH:mm)"))