mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[FIX] fix quota and availability in hotel room type
This commit is contained in:
@@ -185,6 +185,7 @@ class HotelReservation(models.Model):
|
|||||||
vals.update({'to_read': True})
|
vals.update({'to_read': True})
|
||||||
|
|
||||||
reservation_id = super(HotelReservation, self).create(vals)
|
reservation_id = super(HotelReservation, self).create(vals)
|
||||||
|
import wdb; wdb.set_trace()
|
||||||
# restar quota si en viene de wubook y es mayor que cero
|
# restar quota si en viene de wubook y es mayor que cero
|
||||||
backend_id = self.env['channel.hotel.room.type'].search([
|
backend_id = self.env['channel.hotel.room.type'].search([
|
||||||
('odoo_id', '=', vals['room_type_id'])
|
('odoo_id', '=', vals['room_type_id'])
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class ChannelHotelRoomType(models.Model):
|
|||||||
default_max_avail = fields.Integer("Max. Availability", default=_default_max_avail,
|
default_max_avail = fields.Integer("Max. Availability", default=_default_max_avail,
|
||||||
help="Maximum simultaneous availability given no availability rules. "
|
help="Maximum simultaneous availability given no availability rules. "
|
||||||
"Use `-1` for using maximum simultaneous availability.")
|
"Use `-1` for using maximum simultaneous availability.")
|
||||||
default_availability = fields.Integer(default=_default_availability, readonly = True,
|
default_availability = fields.Integer(default=_default_availability, readonly=True,
|
||||||
help="Default availability for OTAs. "
|
help="Default availability for OTAs. "
|
||||||
"The availability is calculated based on the quota, "
|
"The availability is calculated based on the quota, "
|
||||||
"the maximum simultaneous availability and "
|
"the maximum simultaneous availability and "
|
||||||
@@ -52,16 +52,16 @@ class ChannelHotelRoomType(models.Model):
|
|||||||
max_price = fields.Float('Max. Price', default=200.0, digits=dp.get_precision('Product Price'),
|
max_price = fields.Float('Max. Price', default=200.0, digits=dp.get_precision('Product Price'),
|
||||||
help="Setup the max price to prevent incidents while editing your prices.")
|
help="Setup the max price to prevent incidents while editing your prices.")
|
||||||
|
|
||||||
@api.constrains('default_max_avail', 'default_quota', 'default_availability')
|
@api.constrains('default_max_avail', 'default_quota')
|
||||||
def _check_availability(self):
|
def _check_availability(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.quota > record.room_type_id.total_rooms_count:
|
if record.default_quota > record.total_rooms_count:
|
||||||
raise ValidationError(_("The quota assigned to the channel manager can't be greater "
|
raise ValidationError(_("The quota assigned to the channel manager can't be greater "
|
||||||
"than the total rooms count!"))
|
"than the total rooms count!"))
|
||||||
if (record.max_avail > record.quota) and (record.quota >= 0):
|
# if (record.default_max_avail > record.default_quota) and (record.default_quota >= 0):
|
||||||
raise ValidationError(_("The maximum simultaneous availability can't be greater "
|
# raise ValidationError(_("The maximum simultaneous availability can't be greater "
|
||||||
"than a given quota."))
|
# "than a given quota."))
|
||||||
if record.max_avail > record.room_type_id.total_rooms_count:
|
if record.default_max_avail > record.total_rooms_count:
|
||||||
raise ValidationError(_("The maximum simultaneous availability can't be greater "
|
raise ValidationError(_("The maximum simultaneous availability can't be greater "
|
||||||
"than the total rooms count!"))
|
"than the total rooms count!"))
|
||||||
|
|
||||||
@@ -178,6 +178,7 @@ class HotelRoomType(models.Model):
|
|||||||
'default_odoo_id': self.id,
|
'default_odoo_id': self.id,
|
||||||
'default_name': self.name,
|
'default_name': self.name,
|
||||||
'default_ota_capacity': self.capacity,
|
'default_ota_capacity': self.capacity,
|
||||||
|
'default_capacity': self.capacity,
|
||||||
'default_list_price': self.list_price,
|
'default_list_price': self.list_price,
|
||||||
'default_total_rooms_count': self.total_rooms_count}
|
'default_total_rooms_count': self.total_rooms_count}
|
||||||
return action
|
return action
|
||||||
|
|||||||
@@ -165,7 +165,8 @@ class ChannelHotelRoomTypeAvailability(models.Model):
|
|||||||
to_eval.append(room_type_bind.default_availability)
|
to_eval.append(room_type_bind.default_availability)
|
||||||
else:
|
else:
|
||||||
# default availability for OTAs if not record given
|
# default availability for OTAs if not record given
|
||||||
# This should happens only when refreshing availability from hotel.reservation
|
# This should never happens because the channel.hotel.room.type.availability
|
||||||
|
# should be created and the quota update (if needed) __before__ refreshing_availability()
|
||||||
to_eval.append(room_type_bind.default_availability)
|
to_eval.append(room_type_bind.default_availability)
|
||||||
|
|
||||||
avail = max(min(to_eval), 0)
|
avail = max(min(to_eval), 0)
|
||||||
@@ -185,7 +186,8 @@ class ChannelHotelRoomTypeAvailability(models.Model):
|
|||||||
if room_type_avail_id.channel_avail != avail:
|
if room_type_avail_id.channel_avail != avail:
|
||||||
room_type_avail_id.write({'channel_avail': avail})
|
room_type_avail_id.write({'channel_avail': avail})
|
||||||
else:
|
else:
|
||||||
# This should happens only when refreshing availability from hotel.reservation
|
# This should never happens because the channel.hotel.room.type.availability
|
||||||
|
# should be created and the quota update (if needed) __before__ refreshing_availability()
|
||||||
channel_room_type_avail_obj.create({
|
channel_room_type_avail_obj.create({
|
||||||
'odoo_id': room_type_bind.odoo_id.id,
|
'odoo_id': room_type_bind.odoo_id.id,
|
||||||
'backend_id': backend_id,
|
'backend_id': backend_id,
|
||||||
|
|||||||
@@ -36,10 +36,10 @@
|
|||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="total_rooms_count" />
|
<field name="total_rooms_count" />
|
||||||
<field name="default_availability" />
|
<field name="default_availability" force_save="1" />
|
||||||
</group>
|
</group>
|
||||||
<label colspan="2" class="fa fa-info-circle"
|
<label colspan="2" class="fa fa-info-circle"
|
||||||
string="Use `-1` for managing no Quota or Maximum simultaneous availability.">
|
string=" Use `-1` for managing no Quota or Maximum simultaneous availability.">
|
||||||
</label>
|
</label>
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
|
|||||||
Reference in New Issue
Block a user