mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[UPD] manage default quota in channel room type
This commit is contained in:
@@ -16,13 +16,16 @@ class ChannelHotelRoomType(models.Model):
|
|||||||
_inherits = {'hotel.room.type': 'odoo_id'}
|
_inherits = {'hotel.room.type': 'odoo_id'}
|
||||||
_description = 'Channel Hotel Room'
|
_description = 'Channel Hotel Room'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _default_max_avail(self):
|
||||||
|
return self.env['hotel.room.type'].browse(
|
||||||
|
self._context.get('default_odoo_id')
|
||||||
|
).total_rooms_count or -1
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _default_availability(self):
|
def _default_availability(self):
|
||||||
room_type_id = self._context.get('room_type_id')
|
return max(min(self.default_quota, self.default_max_avail), 0)
|
||||||
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',
|
odoo_id = fields.Many2one(comodel_name='hotel.room.type',
|
||||||
string='Room Type',
|
string='Room Type',
|
||||||
@@ -32,18 +35,48 @@ class ChannelHotelRoomType(models.Model):
|
|||||||
ota_capacity = fields.Integer("OTA's Capacity", default=1, old_name='wcapacity',
|
ota_capacity = fields.Integer("OTA's Capacity", default=1, old_name='wcapacity',
|
||||||
help="The capacity of the room for OTAs.")
|
help="The capacity of the room for OTAs.")
|
||||||
|
|
||||||
default_quota = fields.Integer("Default Quota", default=-1,
|
default_quota = fields.Integer("Default Quota",
|
||||||
help="Quota assigned to the channel given no availability rules.")
|
help="Quota assigned to the channel given no availability rules. "
|
||||||
default_max_avail = fields.Integer("Max. Availability", default=-1,
|
"Use `-1` for managing no quota.")
|
||||||
help="Maximum simultaneous availability given no quota.")
|
default_max_avail = fields.Integer("Max. Availability", default=_default_max_avail,
|
||||||
default_availability = fields.Integer(readonly=True, default=_default_availability,
|
help="Maximum simultaneous availability given no availability rules. "
|
||||||
help="Default availability for OTAs.")
|
"Use `-1` for using maximum simultaneous availability.")
|
||||||
|
default_availability = fields.Integer(default=_default_availability, readonly = True,
|
||||||
|
help="Default availability for OTAs. "
|
||||||
|
"The availability is calculated based on the quota, "
|
||||||
|
"the maximum simultaneous availability and "
|
||||||
|
"the total room count for the given room type.")
|
||||||
|
|
||||||
min_price = fields.Float('Min. Price', default=5.0, digits=dp.get_precision('Product Price'),
|
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.")
|
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'),
|
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')
|
||||||
|
def _check_availability(self):
|
||||||
|
for record in self:
|
||||||
|
if record.quota > record.room_type_id.total_rooms_count:
|
||||||
|
raise ValidationError(_("The quota assigned to the channel manager can't be greater "
|
||||||
|
"than the total rooms count!"))
|
||||||
|
if (record.max_avail > record.quota) and (record.quota >= 0):
|
||||||
|
raise ValidationError(_("The maximum simultaneous availability can't be greater "
|
||||||
|
"than a given quota."))
|
||||||
|
if record.max_avail > record.room_type_id.total_rooms_count:
|
||||||
|
raise ValidationError(_("The maximum simultaneous availability can't be greater "
|
||||||
|
"than the total rooms count!"))
|
||||||
|
|
||||||
|
@api.onchange('default_quota', 'default_max_avail')
|
||||||
|
def _onchange_availability(self):
|
||||||
|
for rec in self:
|
||||||
|
to_eval = []
|
||||||
|
to_eval.append(rec.total_rooms_count)
|
||||||
|
if rec.default_quota >= 0:
|
||||||
|
to_eval.append(rec.default_quota)
|
||||||
|
if rec.default_max_avail >= 0:
|
||||||
|
to_eval.append(rec.default_max_avail)
|
||||||
|
|
||||||
|
rec.default_availability = min(to_eval)
|
||||||
|
|
||||||
@api.onchange('room_ids')
|
@api.onchange('room_ids')
|
||||||
def _get_capacity(self):
|
def _get_capacity(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@@ -141,16 +174,19 @@ class HotelRoomType(models.Model):
|
|||||||
# WARNING: more than one binding is currently not expected
|
# WARNING: more than one binding is currently not expected
|
||||||
action['domain'] = [('id', 'in', channel_bind_ids.ids)]
|
action['domain'] = [('id', 'in', channel_bind_ids.ids)]
|
||||||
else:
|
else:
|
||||||
action['context'] = {'default_odoo_id': self.id,
|
action['context'] = {
|
||||||
'default_name': self.name,
|
'default_odoo_id': self.id,
|
||||||
'default_ota_capacity': self.capacity,
|
'default_name': self.name,
|
||||||
'default_list_price': self.list_price}
|
'default_ota_capacity': self.capacity,
|
||||||
|
'default_list_price': self.list_price,
|
||||||
|
'default_total_rooms_count': self.total_rooms_count}
|
||||||
return action
|
return action
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def sync_from_channel(self):
|
def disconnect_channel_bind_ids(self):
|
||||||
channel_bind_ids = self.mapped('channel_bind_ids')
|
channel_bind_ids = self.mapped('channel_bind_ids')
|
||||||
msg = _("Synchronize room types from the channel manager is not yet implementet.")
|
msg = _("This function is not yet implemented.")
|
||||||
|
msg += _(" The room type [%s] should be delete from the channel manager.") % channel_bind_ids.get_external_id
|
||||||
raise UserError(msg)
|
raise UserError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,36 @@
|
|||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="external_id" />
|
|
||||||
<field name="channel_short_code" />
|
|
||||||
<field name="ota_capacity" />
|
|
||||||
<field name="default_availability" />
|
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="min_price" class="oe_inline"/>
|
<group>
|
||||||
<field name="max_price" class="oe_inline"/>
|
<field name="external_id" />
|
||||||
|
<field name="channel_short_code" />
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<field name="capacity" />
|
||||||
|
<field name="ota_capacity" />
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<group>
|
||||||
|
<field name="list_price" class="oe_inline"/>
|
||||||
|
<field name="min_price" class="oe_inline"/>
|
||||||
|
<field name="max_price" class="oe_inline"/>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<group>
|
||||||
|
<field name="default_quota"/>
|
||||||
|
<field name="default_max_avail"/>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<field name="total_rooms_count" />
|
||||||
|
<field name="default_availability" />
|
||||||
|
</group>
|
||||||
|
<label colspan="2" class="fa fa-info-circle"> Use `-1` for managing no Quota or Maximum simultaneous availability.</label>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
<field name="sync_date" readonly="1"/>
|
<field name="sync_date" readonly="1"/>
|
||||||
</group>
|
</group>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -6,11 +6,20 @@
|
|||||||
<field name="inherit_id" ref="hotel.hotel_room_type_view_form" />
|
<field name="inherit_id" ref="hotel.hotel_room_type_view_form" />
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//button[@name='toggle_active']" position="before">
|
<xpath expr="//button[@name='toggle_active']" position="before">
|
||||||
|
<field name="channel_bind_ids" invisible="1" />
|
||||||
<button name="open_channel_bind_ids" type="object"
|
<button name="open_channel_bind_ids" type="object"
|
||||||
class="oe_stat_button" icon="fa-cloud-upload" string="Export to Channel"/>
|
class="oe_stat_button" icon="fa-toggle-off" string="Connect to Channel"
|
||||||
<button name="sync_from_channel" type="object"
|
attrs="{'invisible': [('channel_bind_ids','!=', [])]}"
|
||||||
class="oe_stat_button" icon="fa-cloud-download" string="Import from Channel"
|
/>
|
||||||
confirm="Synchronizing a room type automatically updates its values in Odoo. Do you want to proceed?"/>
|
<button name="open_channel_bind_ids" type="object"
|
||||||
|
class="oe_stat_button" icon="fa-cloud-upload" string="Synchronize to Channel"
|
||||||
|
attrs="{'invisible': [('channel_bind_ids','=', [])]}"
|
||||||
|
/>
|
||||||
|
<button name="disconnect_channel_bind_ids" type="object"
|
||||||
|
class="oe_stat_button" icon="fa-toggle-on" string="Disconnect from Channel"
|
||||||
|
attrs="{'invisible': [('channel_bind_ids','=', [])]}"
|
||||||
|
confirm="Disconnecting will automatically delete the room type in the Channel. Do you want to proceed?"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
|
|
||||||
<xpath expr="//field[@name='room_ids']" position="before">
|
<xpath expr="//field[@name='room_ids']" position="before">
|
||||||
|
|||||||
Reference in New Issue
Block a user