[UPD] Task 973 - binding for room types

This commit is contained in:
Pablo
2019-07-18 16:50:33 +02:00
parent 241c74f317
commit 8f6f41b5b1
3 changed files with 39 additions and 11 deletions

View File

@@ -2,7 +2,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, fields, _
from odoo.exceptions import UserError
from odoo.exceptions import ValidationError
from odoo.addons import decimal_precision as dp
from odoo.addons.queue_job.job import job
@@ -26,7 +25,6 @@ class ChannelHotelRoomType(models.Model):
def _default_availability(self):
return max(min(self.default_quota, self.default_max_avail), 0)
odoo_id = fields.Many2one(comodel_name='hotel.room.type',
string='Room Type',
required=True,
@@ -172,10 +170,14 @@ class HotelRoomType(models.Model):
@api.multi
def disconnect_channel_bind_ids(self):
channel_bind_ids = self.mapped('channel_bind_ids')
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)
# TODO: multichannel rooms is not implemented
self.channel_bind_ids.with_context({'connector_no_export': True}).unlink()
@api.multi
def write(self, vals):
if 'active' in vals and vals.get('active') is False:
self.channel_bind_ids.unlink()
return super().write(vals)
class BindingHotelRoomTypeListener(Component):

View File

@@ -5,20 +5,43 @@
<field name="model">hotel.room.type</field>
<field name="inherit_id" ref="hotel.hotel_room_type_view_form" />
<field name="arch" type="xml">
<xpath expr="//form/sheet/notebook" position="inside">
<page string="Channel Bindings" invisible="1">
<field name="channel_bind_ids" />
</page>
</xpath>
<xpath expr="//button[@name='toggle_active']" position="replace">
<!-- custom message for warning when archiving a channel room type with binding -->
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive"
confirm="Archive a room type will automatically delete the room type in the Channel.
Ensure yourself no reservations are binded to this room type from today and hereafter.
Do you want to proceed?"
attrs="{'invisible': [('channel_bind_ids', '=', [])]}">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
<!-- default message for archiving a channel room type without binding -->
<button name="toggle_active" type="object" class="oe_stat_button" icon="fa-archive"
attrs="{'invisible': [('channel_bind_ids','!=', [])]}">
<field name="active" widget="boolean_button" options='{"terminology": "archive"}'/>
</button>
</xpath>
<xpath expr="//button[@name='toggle_active']" position="before">
<field name="channel_bind_ids" invisible="1" />
<button name="open_channel_bind_ids" type="object"
class="oe_stat_button" icon="fa-toggle-off" string="Connect to Channel"
attrs="{'invisible': [('channel_bind_ids','!=', [])]}"
attrs="{'invisible': ['|', ('channel_bind_ids','!=', []), ('active','=', False) ]}"
/>
<button name="open_channel_bind_ids" type="object"
class="oe_stat_button" icon="fa-cloud-upload" string="Synchronize to Channel"
class="oe_stat_button" icon="fa-cloud-upload" string="Synchronize with 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?"
confirm="Disconnecting will unbind the room type from the Channel but it will not be deleted.
Ensure yourself no reservations are binded to this room type from today and hereafter.
Do you want to proceed?"
/>
</xpath>

View File

@@ -3,7 +3,8 @@
from odoo.addons.component.core import Component
from odoo.addons.hotel_channel_connector.components.core import ChannelConnectorError
from odoo import api, fields
from odoo import api, fields, _
from odoo.exceptions import AccessError, UserError, ValidationError
class HotelRoomTypeExporter(Component):
@@ -44,6 +45,7 @@ class HotelRoomTypeExporter(Component):
section='room',
internal_message=str(err),
channel_message=err.data['message'])
raise ValidationError(_(err.data['message']))
@api.model
def create_room(self, binding):
@@ -78,6 +80,7 @@ class HotelRoomTypeExporter(Component):
section='room',
internal_message=str(err),
channel_message=err.data['message'])
raise ValidationError(_(err.data['message']))
else:
binding.with_context({
'connector_no_export': True,