diff --git a/hotel/models/hotel_folio.py b/hotel/models/hotel_folio.py
index 46da5abb3..656aab0bb 100644
--- a/hotel/models/hotel_folio.py
+++ b/hotel/models/hotel_folio.py
@@ -97,7 +97,7 @@ class HotelFolio(models.Model):
readonly=True, copy=False,
index=True, track_visibility='onchange',
default='draft')
-
+
# Partner fields for being used directly in the Folio views---------
email = fields.Char('E-mail', related='partner_id.email')
@@ -165,7 +165,7 @@ class HotelFolio(models.Model):
has_checkout_to_send = fields.Boolean(
compute='_compute_has_checkout_to_send')
- #Generic Fields-----------------------------------------------------
+ #Generic Fields-----------------------------------------------------
internal_comment = fields.Text(string='Internal Folio Notes')
cancelled_reason = fields.Text('Cause of cancelled')
closure_reason_id = fields.Many2one('room.closure.reason')
@@ -349,7 +349,7 @@ class HotelFolio(models.Model):
).next_by_code('hotel.folio') or _('New')
else:
vals['name'] = self.env['ir.sequence'].next_by_code('hotel.folio') or _('New')
-
+
# Makes sure partner_invoice_id' and 'pricelist_id' are defined
lfields = ('partner_invoice_id', 'partner_shipping_id', 'pricelist_id')
@@ -402,7 +402,7 @@ class HotelFolio(models.Model):
self.pricelist_id.is_staff,
self.reservation_type)}
self.update(values)
-
+
@api.model
def calcule_reservation_type(self, is_staff, current_type):
@@ -753,13 +753,13 @@ class HotelFolio(models.Model):
info_grouped = []
for rline in self.room_lines:
if (import_all or rline.to_send) and \
- not rline.parent_reservation and rline.state == state:
- dates = rline.get_real_checkin_checkout()
+ not rline.parent_reservation and rline.state == state:
+ dates = (rline.real_checkin, rline.real_checkout)
vals = {
'num': len(
self.room_lines.filtered(
- lambda r: r.get_real_checkin_checkout()[0] == dates[0] and \
- r.get_real_checkin_checkout()[1] == dates[1] and \
+ lambda r: r.real_checkin == dates[0] and \
+ r.real_checkout == dates[1] and \
r.room_type_id.id == rline.room_type_id.id and \
(r.to_send or import_all) and not r.parent_reservation and \
r.state == rline.state)
diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py
index 222b2030f..2a43ded84 100644
--- a/hotel/models/hotel_reservation.py
+++ b/hotel/models/hotel_reservation.py
@@ -151,6 +151,10 @@ class HotelReservation(models.Model):
checkout = fields.Date('Check Out', required=True,
default=_get_default_checkout,
track_visibility='onchange')
+ real_checkin = fields.Date('Real Check In', required=True,
+ track_visibility='onchange')
+ real_checkout = fields.Date('Real Check Out', required=True,
+ track_visibility='onchange')
arrival_hour = fields.Char('Arrival Hour',
default=_get_default_arrival_hour,
help="Default Arrival Hour (HH:MM)")
@@ -309,7 +313,11 @@ class HotelReservation(models.Model):
vals.update(self.prepare_reservation_lines(
vals['checkin'],
days_diff,
- vals=vals)) #REVISAR el unlink
+ vals=vals)) # REVISAR el unlink
+ if 'checkin' in vals and 'checkout' in vals \
+ and 'real_checkin' not in vals and 'real_checkout' not in vals:
+ vals['real_checkin'] = vals['checkin']
+ vals['real_checkout'] = vals['checkout']
record = super(HotelReservation, self).create(vals)
#~ if (record.state == 'draft' and record.folio_id.state == 'sale') or \
#~ record.preconfirm:
@@ -325,6 +333,13 @@ class HotelReservation(models.Model):
for record in self:
checkin = vals['checkin'] if 'checkin' in vals else record.checkin
checkout = vals['checkout'] if 'checkout' in vals else record.checkout
+
+ if not record.splitted and not vals.get('splitted', False):
+ if 'checkin' in vals:
+ vals['real_checkin'] = vals['checkin']
+ if 'checkout' in vals:
+ vals['real_checkout'] = vals['checkout']
+
days_diff = (
fields.Date.from_string(checkout) - \
fields.Date.from_string(checkin)
@@ -485,6 +500,8 @@ class HotelReservation(models.Model):
'splitted': self.splitted,
'room_type_id': self.room_type_id.id,
'room_id': self.room_id.id,
+ 'real_checkin': self.real_checkin,
+ 'real_checkout': self.real_checkout,
}
@api.constrains('adults')
@@ -952,39 +969,13 @@ class HotelReservation(models.Model):
RESERVATION SPLITTED -----------------------------------------------
"""
- @api.multi
- def get_real_checkin_checkout(self):
- self.ensure_one()
- if not self.splitted:
- return (self.checkin, self.checkout)
-
- master_reservation = self.parent_reservation or self
- splitted_reservs = self.env['hotel.reservation'].search([
- '|',
- ('splitted', '=', True),
- ('id', '=', master_reservation.id), # This here because can create a splitted reserv before set as splitted the parent reservation (master)
- ('folio_id', '=', self.folio_id.id),
- '|',
- ('parent_reservation', '=', master_reservation.id),
- ('id', '=', master_reservation.id)
- ])
- last_checkout = splitted_reservs[0].checkout
- first_checkin = splitted_reservs[0].checkin
- for reserv in splitted_reservs:
- if last_checkout < reserv.checkout:
- last_checkout = reserv.checkout
- if first_checkin > reserv.checkin:
- first_checkin = reserv.checkin
- return (first_checkin, last_checkout)
-
@api.multi
def split(self, nights):
for record in self:
date_start_dt = fields.Date.from_string(record.checkin)
date_end_dt = fields.Date.from_string(record.checkout)
date_diff = abs((date_end_dt - date_start_dt).days)
- new_start_date_dt = date_start_dt + \
- timedelta(days=date_diff-nights)
+ new_start_date_dt = date_start_dt + timedelta(days=date_diff-nights)
if nights >= date_diff or nights < 1:
raise ValidationError(_("Invalid Nights! Max is \
'%d'") % (date_diff-1))
@@ -1058,19 +1049,24 @@ class HotelReservation(models.Model):
@api.model
def unify_books(self, splitted_reservs):
- master_reservation = splitted_reservs[0].parent_reservation or splitted_reservs[0]
+ parent_reservation = splitted_reservs[0].parent_reservation or splitted_reservs[0]
room_type_ids = splitted_reservs.mapped('room_type_id.id')
if len(room_type_ids) > 1 or \
(len(room_type_ids) == 1
- and master_reservation.room_type_id.id != room_type_ids[0]):
+ and parent_reservation.room_type_id.id != room_type_ids[0]):
raise ValidationError(_("This reservation can't be unified: They \
all need to be in the same room"))
# Search checkout
last_checkout = splitted_reservs[0].checkout
+ first_checkin = splitted_reservs[0].checkin
+ master_reservation = splitted_reservs[0]
for reserv in splitted_reservs:
if last_checkout < reserv.checkout:
last_checkout = reserv.checkout
+ if first_checkin > reserv.checkin:
+ first_checkin = reserv.checkin
+ master_reservation = reserv
# Agrupate reservation lines
reservation_line_ids = splitted_reservs.mapped('reservation_line_ids')
@@ -1088,9 +1084,15 @@ class HotelReservation(models.Model):
osplitted_reservs = splitted_reservs - master_reservation
osplitted_reservs.sudo().unlink()
+ _logger.info("========== UNIFY")
+ _logger.info(master_reservation.real_checkin)
+ _logger.info(first_checkin)
+ _logger.info(master_reservation.real_checkout)
+ _logger.info(last_checkout)
+
master_reservation.write({
'checkout': last_checkout,
- 'splitted': master_reservation.get_real_checkin_checkout()[1] != last_checkout,
+ 'splitted': master_reservation.real_checkin != first_checkin or master_reservation.real_checkout != last_checkout,
'reservation_line_ids': rlines,
'price_total': tprice,
})
diff --git a/hotel_calendar/__manifest__.py b/hotel_calendar/__manifest__.py
index 0f123751b..b85d29a60 100644
--- a/hotel_calendar/__manifest__.py
+++ b/hotel_calendar/__manifest__.py
@@ -25,7 +25,6 @@
'views/inherited_res_users_views.xml',
'views/inherited_hotel_room_type_views.xml',
'views/inherited_hotel_room_views.xml',
- 'views/room_pricelist_cached_views.xml',
'views/hotel_reservation_views.xml',
'views/hotel_calendar_management_views.xml',
'views/hotel_calendar_views.xml',
diff --git a/hotel_calendar/data/menus.xml b/hotel_calendar/data/menus.xml
index 6ef1e3d96..69f7251b6 100644
--- a/hotel_calendar/data/menus.xml
+++ b/hotel_calendar/data/menus.xml
@@ -22,9 +22,6 @@
web_icon="hotel_calendar,static/description/icon_calendar_configurator.png"
action="action_hotel_calendar_management" groups="hotel.group_hotel_manager" />
-
-