[WIP] WIP

This commit is contained in:
Pablo
2019-02-25 14:59:52 +01:00
parent c6bc33bb32
commit f47efd0ee3
4 changed files with 39 additions and 7 deletions

View File

@@ -97,10 +97,12 @@ class ChannelHotelReservation(models.Model):
channel_room_type_avail_obj = self.env['channel.hotel.room.type.availability']
for k_i, v_i in enumerate(older_vals):
# FIX: 3rd parameters is backend_id, use room_id=v_i['room_id'] instead
channel_room_type_avail_obj.refresh_availability(
v_i['checkin'],
v_i['checkout'],
v_i['room_id'])
# FIX: 3rd parameters is backend_id, use room_id=new_vals[k_i]['room_id'] instead
channel_room_type_avail_obj.refresh_availability(
new_vals[k_i]['checkin'],
new_vals[k_i]['checkout'],
@@ -124,6 +126,7 @@ class ChannelHotelReservation(models.Model):
if self._context.get('connector_no_export', True):
channel_room_type_avail_obj = self.env['channel.hotel.room.type.availability']
for record in vals:
# FIX: 3rd parameters is backend_id, use room_id=record['room_id'] instead
channel_room_type_avail_obj.refresh_availability(
record['checkin'],
record['checkout'],
@@ -180,7 +183,20 @@ class HotelReservation(models.Model):
user = self.env['res.users'].browse(self.env.uid)
if user.has_group('hotel.group_hotel_call'):
vals.update({'to_read': True})
return super(HotelReservation, self).create(vals)
reservation_id = super(HotelReservation, self).create(vals)
# restar quota si en viene de wubook y es mayor que cero
backend_id = self.env['channel.hotel.room.type'].search([
('odoo_id', '=', vals['room_type_id'])
]).backend_id
# WARNING: more than one backend_id is currently not expected
self.env['channel.hotel.room.type.availability'].refresh_availability(
vals['real_checkin'],
vals['real_checkout'],
backend_id.id,
room_id=vals['room_type_id'])
return reservation_id
@api.multi
def generate_copy_values(self, checkin=False, checkout=False):

View File

@@ -16,6 +16,14 @@ class ChannelHotelRoomType(models.Model):
_inherits = {'hotel.room.type': 'odoo_id'}
_description = 'Channel Hotel Room'
@api.model
def _default_availability(self):
room_type_id = self._context.get('room_type_id')
if room_type_id:
room_type_id = self.env['hotel.room_type'].browse(room_type_id)
return room_type_id.default_quota if room_type_id else -1
return -1
odoo_id = fields.Many2one(comodel_name='hotel.room.type',
string='Room Type',
required=True,
@@ -23,8 +31,14 @@ class ChannelHotelRoomType(models.Model):
channel_short_code = fields.Char("Channel Short Code", old_name='wscode')
ota_capacity = fields.Integer("OTA's Capacity", default=1, old_name='wcapacity',
help="The capacity of the room for OTAs.")
default_availability = fields.Integer(default=0,
default_quota = fields.Integer("Default Quota", default=-1,
help="Quota assigned to the channel given no availability rules.")
default_max_avail = fields.Integer("Max. Availability", default=-1,
help="Maximum simultaneous availability given no quota.")
default_availability = fields.Integer(readonly=True, default=_default_availability,
help="Default availability for OTAs.")
min_price = fields.Float('Min. Price', default=5.0, digits=dp.get_precision('Product Price'),
help="Setup the min price to prevent incidents while editing your prices.")
max_price = fields.Float('Max. Price', default=200.0, digits=dp.get_precision('Product Price'),
@@ -94,7 +108,6 @@ class HotelRoomType(models.Model):
inverse_name='odoo_id',
string='Hotel Channel Connector Bindings')
default_quota = fields.Integer("Default Quota", compute="_compute_capacity")
capacity = fields.Integer("Capacity", compute="_compute_capacity")
@api.multi

View File

@@ -135,7 +135,6 @@ class ChannelHotelRoomTypeAvailability(models.Model):
domain = [('backend_id', '=', backend_id)]
if room_id:
domain.append(('room_ids', 'in', [room_id]))
# WARNING: more than one binding is currently not expected
room_type_bind = channel_room_type_obj.search(domain, limit=1)
if room_type_bind and room_type_bind.external_id:
_logger.info("==[ODOO->CHANNEL]==== REFRESH AVAILABILITY ==")
@@ -166,7 +165,6 @@ class ChannelHotelRoomTypeAvailability(models.Model):
else:
# default availability for OTAs if not record given
# This should happens only when refreshing availability from hotel.reservation
import wdb; wdb.set_trace()
to_eval.append(room_type_bind.default_availability)
avail = max(min(to_eval), 0)
@@ -187,11 +185,12 @@ class ChannelHotelRoomTypeAvailability(models.Model):
room_type_avail_id.write({'channel_avail': avail})
else:
# This should happens only when refreshing availability from hotel.reservation
import wdb; wdb.set_trace()
channel_room_type_avail_obj.create({
'room_type_id': room_type_bind.odoo_id.id,
'odoo_id': room_type_bind.odoo_id.id,
'backend_id': backend_id,
'date': ndate_str,
'channel_avail': avail,
'channel_pushed': False,
})
@job(default_channel='root.channel')
@@ -276,7 +275,9 @@ class ChannelBindingHotelRoomTypeAvailabilityListener(Component):
_logger.info(fields)
if any(fields_checked):
# self.env['channel.backend'].cron_push_changes()
record.channel_pushed = False
record.push_availability(record.backend_id)
@skip_if(lambda self, record, **kwargs: self.no_connector_export(record))
def on_fix_channel_availability(self, record, fields=None):

View File

@@ -12,6 +12,7 @@
</group>
<group>
<field name="quota" />
<field name="channel_avail" />
<field name="booked" />
</group>
<group>
@@ -28,6 +29,7 @@
<tree string="Hotel Channel Room Availability">
<field name="backend_id" />
<field name="quota" />
<field name="channel_avail" />
</tree>
</field>
</record>