mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] Calendar Performance
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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,31 +969,6 @@ 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:
|
||||
@@ -1088,16 +1080,19 @@ class HotelReservation(models.Model):
|
||||
}))
|
||||
tprice += rline.price
|
||||
|
||||
# Real Dates
|
||||
rdate_begin, rdate_end = master_reservation.get_real_checkin_checkout()
|
||||
|
||||
# Unify
|
||||
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': rdate_begin != first_checkin or rdate_end != last_checkout,
|
||||
'splitted': master_reservation.real_checkin != first_checkin or master_reservation.real_checkout != last_checkout,
|
||||
'reservation_line_ids': rlines,
|
||||
'price_total': tprice,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user