From f36c7c3d278c5586c9b6a057f70721425a79358e Mon Sep 17 00:00:00 2001 From: Pablo Date: Mon, 25 Feb 2019 22:26:10 +0100 Subject: [PATCH] [ADD] buttons for channel management + minor cleanup --- .../hotel_room_type_restriction/common.py | 2 +- .../models/product_pricelist/common.py | 28 +++++++++++++++++- .../views/channel_product_pricelist_views.xml | 9 ++++++ ...ited_hotel_room_type_restriction_views.xml | 2 +- .../inherited_product_pricelist_views.xml | 29 ++++++++++--------- 5 files changed, 54 insertions(+), 16 deletions(-) diff --git a/hotel_channel_connector/models/hotel_room_type_restriction/common.py b/hotel_channel_connector/models/hotel_room_type_restriction/common.py index 94e57842d..4cd669c67 100644 --- a/hotel_channel_connector/models/hotel_room_type_restriction/common.py +++ b/hotel_channel_connector/models/hotel_room_type_restriction/common.py @@ -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): diff --git a/hotel_channel_connector/models/product_pricelist/common.py b/hotel_channel_connector/models/product_pricelist/common.py index 920fea2d6..0a2603c4b 100644 --- a/hotel_channel_connector/models/product_pricelist/common.py +++ b/hotel_channel_connector/models/product_pricelist/common.py @@ -1,7 +1,8 @@ # Copyright 2018 Alexandre Díaz # 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' diff --git a/hotel_channel_connector/views/channel_product_pricelist_views.xml b/hotel_channel_connector/views/channel_product_pricelist_views.xml index efe45799d..dbd91ec27 100644 --- a/hotel_channel_connector/views/channel_product_pricelist_views.xml +++ b/hotel_channel_connector/views/channel_product_pricelist_views.xml @@ -28,4 +28,13 @@ + + Hotel Channel Connector Bindings + channel.product.pricelist + form + tree,form + form + [] + + diff --git a/hotel_channel_connector/views/inherited_hotel_room_type_restriction_views.xml b/hotel_channel_connector/views/inherited_hotel_room_type_restriction_views.xml index 34aa9369d..fcc2e4585 100644 --- a/hotel_channel_connector/views/inherited_hotel_room_type_restriction_views.xml +++ b/hotel_channel_connector/views/inherited_hotel_room_type_restriction_views.xml @@ -18,7 +18,7 @@