diff --git a/hotel_channel_connector/components/backend_adapter.py b/hotel_channel_connector/components/backend_adapter.py index e15242191..7db9f48bc 100644 --- a/hotel_channel_connector/components/backend_adapter.py +++ b/hotel_channel_connector/components/backend_adapter.py @@ -53,6 +53,9 @@ class HotelChannelInterfaceAdapter(AbstractComponent): def create_plan(self, name, daily=1): raise NotImplementedError + def create_vplan(self, name, pid, dtype, value): + raise NotImplementedError + def delete_plan(self, channel_plan_id): raise NotImplementedError diff --git a/hotel_channel_connector/models/product_pricelist/common.py b/hotel_channel_connector/models/product_pricelist/common.py index a1ea574c5..41f01ca13 100644 --- a/hotel_channel_connector/models/product_pricelist/common.py +++ b/hotel_channel_connector/models/product_pricelist/common.py @@ -28,6 +28,15 @@ class ChannelProductPricelist(models.Model): exporter = work.component(usage='product.pricelist.exporter') exporter.create_plan(self) + @job(default_channel='root.channel') + @api.multi + def create_vplan(self): + self.ensure_one() + if not self.external_id: + with self.backend_id.work_on(self._name) as work: + exporter = work.component(usage='product.pricelist.exporter') + exporter.create_vplan(self) + @job(default_channel='root.channel') @api.multi def update_plan_name(self): @@ -62,7 +71,7 @@ class ProductPricelist(models.Model): inverse_name='odoo_id', string='Hotel Channel Connector Bindings') - is_virtual_plan = fields.Boolean("Is a Virtual Pricing Plan", compute='_compute_virtual_plan', readonly="True", + is_virtual_plan = fields.Boolean("Is a Virtual Pricing Plan", compute='_compute_virtual_plan', help="A virtual plan is based on another Pricelist " "with a fixed or percentage variation.") @@ -149,7 +158,10 @@ class ChannelBindingProductPricelistListener(Component): @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_create(self, record, fields=None): - record.create_plan() + if record.is_virtual_plan: + record.create_vplan() + else: + record.create_plan() @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_unlink(self, record, fields=None): diff --git a/hotel_channel_connector/models/product_pricelist/exporter.py b/hotel_channel_connector/models/product_pricelist/exporter.py index a60bc54ee..7c1a10c79 100644 --- a/hotel_channel_connector/models/product_pricelist/exporter.py +++ b/hotel_channel_connector/models/product_pricelist/exporter.py @@ -18,3 +18,7 @@ class ProductPricelistExporter(Component): @api.model def create_plan(self, binding): raise NotImplementedError + + @api.model + def create_vplan(self, binding): + raise NotImplementedError diff --git a/hotel_channel_connector/views/channel_product_pricelist_views.xml b/hotel_channel_connector/views/channel_product_pricelist_views.xml index 61810b308..8010b95a5 100644 --- a/hotel_channel_connector/views/channel_product_pricelist_views.xml +++ b/hotel_channel_connector/views/channel_product_pricelist_views.xml @@ -13,7 +13,7 @@ - + diff --git a/hotel_channel_connector_wubook/components/backend_adapter.py b/hotel_channel_connector_wubook/components/backend_adapter.py index 9b9c615a2..4a61abc6f 100644 --- a/hotel_channel_connector_wubook/components/backend_adapter.py +++ b/hotel_channel_connector_wubook/components/backend_adapter.py @@ -322,6 +322,21 @@ class WuBookAdapter(AbstractComponent): }) return results + def create_vplan(self, name, pid, dtype, value): + rcode, results = self._server.add_vplan( + self._session_info[0], + self._session_info[1], + name, + pid, + dtype, + value, + ) + if rcode != 0: + raise ChannelConnectorError(_("Can't add virtual pricing plan to wubook"), { + 'message': results, + }) + return results + def delete_plan(self, channel_plan_id): rcode, results = self._server.del_plan( self._session_info[0], diff --git a/hotel_channel_connector_wubook/models/product_pricelist/common.py b/hotel_channel_connector_wubook/models/product_pricelist/common.py index a979e0e87..fdb23e1b4 100644 --- a/hotel_channel_connector_wubook/models/product_pricelist/common.py +++ b/hotel_channel_connector_wubook/models/product_pricelist/common.py @@ -15,6 +15,9 @@ class ProductPricelistAdapter(Component): def create_plan(self, name): return super(ProductPricelistAdapter, self).create_plan(name) + def create_vplan(self, name, pid, dtype, value): + return super(ProductPricelistAdapter, self).create_vplan(name, pid, dtype, value) + def delete_plan(self, external_id): return super(ProductPricelistAdapter, self).delete_plan(external_id) diff --git a/hotel_channel_connector_wubook/models/product_pricelist/exporter.py b/hotel_channel_connector_wubook/models/product_pricelist/exporter.py index 055e1f147..bf30ad252 100644 --- a/hotel_channel_connector_wubook/models/product_pricelist/exporter.py +++ b/hotel_channel_connector_wubook/models/product_pricelist/exporter.py @@ -36,3 +36,22 @@ class ProductPricelistExporter(Component): else: binding.external_id = external_id self.binder.bind(external_id, binding) + + @api.model + def create_vplan(self, binding): + try: + import wdb; wdb.set_trace() + external_id = self.backend_adapter.create_vplan( + binding.name, + binding.pid, + binding.dtype, + binding.value, + ) + except ChannelConnectorError as err: + self.create_issue( + section='pricelist', + internal_message=str(err), + channel_message=err.data['message']) + else: + binding.external_id = external_id + self.binder.bind(external_id, binding) \ No newline at end of file