[ADD] buttons for channel management + minor cleanup

This commit is contained in:
Pablo
2019-02-25 22:26:10 +01:00
parent 03d5c42795
commit f36c7c3d27
5 changed files with 54 additions and 16 deletions

View File

@@ -101,7 +101,7 @@ class HotelRoomTypeRestriction(models.Model):
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
msg += _(" The restriction plan [%s] should be delete from the channel manager.") % channel_bind_ids.get_external_id
raise UserError(msg)
class BindingHotelRoomTypeListener(Component):

View File

@@ -1,7 +1,8 @@
# Copyright 2018 Alexandre Díaz <dev@redneboa.es>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, models, fields
from odoo import api, models, fields, _
from odoo.exceptions import UserError
from odoo.addons.queue_job.job import job
from odoo.addons.component.core import Component
from odoo.addons.component_event import skip_if
@@ -79,6 +80,31 @@ class ProductPricelist(models.Model):
names.append((name[0], name[1]))
return names
@api.multi
def open_channel_bind_ids(self):
channel_bind_ids = self.mapped('channel_bind_ids')
action = self.env.ref('hotel_channel_connector.channel_product_pricelist_action').read()[0]
action['views'] = [(self.env.ref('hotel_channel_connector.channel_product_pricelist_view_form').id, 'form')]
action['target'] = 'new'
if len(channel_bind_ids) == 1:
action['res_id'] = channel_bind_ids.ids[0]
elif len(channel_bind_ids) > 1:
# WARNING: more than one binding is currently not expected
action['domain'] = [('id', 'in', channel_bind_ids.ids)]
else:
action['context'] = {
'default_odoo_id': self.id,
'default_name': self.name,
}
return action
@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 pricelist [%s] should be delete from the channel manager.") % channel_bind_ids.get_external_id
raise UserError(msg)
class BindingProductPricelistListener(Component):
_name = 'binding.product.pricelist.listener'
_inherit = 'base.connector.listener'

View File

@@ -28,4 +28,13 @@
</field>
</record>
<record id="channel_product_pricelist_action" model="ir.actions.act_window">
<field name="name">Hotel Channel Connector Bindings</field>
<field name="res_model">channel.product.pricelist</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
<field name="domain">[]</field>
</record>
</odoo>

View File

@@ -18,7 +18,7 @@
<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 automatically delete the restriction plan in the Channel. Do you want to proceed?"
/>
</xpath>
</field>

View File

@@ -5,19 +5,22 @@
<field name="model">product.pricelist</field>
<field name="inherit_id" ref="product.product_pricelist_view" />
<field name="arch" type="xml">
<xpath expr="//sheet" position="inside">
<notebook>
<page name="connector" string="Channel Connector">
<group string="Hotel Channel Bindings">
<field name="channel_bind_ids" nolabel="1">
<tree>
<field name="backend_id"/>
</tree>
</field>
</group>
</page>
</notebook>
</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','!=', [])]}"
/>
<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 pricelist in the Channel. Do you want to proceed?"
/>
</xpath>
</field>
</record>