[ADD] create vplans in wubook

This commit is contained in:
Pablo
2019-03-06 07:55:20 +01:00
parent 12a49678a3
commit 9702a281b4
6 changed files with 91 additions and 5 deletions

View File

@@ -56,6 +56,9 @@ class HotelChannelInterfaceAdapter(AbstractComponent):
def create_vplan(self, name, pid, dtype, value):
raise NotImplementedError
def modify_vplan(self, pid, dtype, value):
raise NotImplementedError
def delete_plan(self, channel_plan_id):
raise NotImplementedError

View File

@@ -6,6 +6,8 @@ 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
import logging
_logger = logging.getLogger(__name__)
class ChannelProductPricelist(models.Model):
@@ -37,6 +39,15 @@ class ChannelProductPricelist(models.Model):
exporter = work.component(usage='product.pricelist.exporter')
exporter.create_vplan(self)
@job(default_channel='root.channel')
@api.multi
def modify_vplan(self):
self.ensure_one()
if self.external_id:
with self.backend_id.work_on(self._name) as work:
exporter = work.component(usage='product.pricelist.exporter')
exporter.modify_vplan(self)
@job(default_channel='root.channel')
@api.multi
def update_plan_name(self):
@@ -149,6 +160,9 @@ class BindingProductPricelistListener(Component):
if 'name' in fields:
for binding in record.channel_bind_ids:
binding.update_plan_name()
if 'item_ids' in fields and record.is_virtual_plan:
for binding in record.channel_bind_ids:
binding.modify_vplan()
class ChannelBindingProductPricelistListener(Component):

View File

@@ -22,3 +22,7 @@ class ProductPricelistExporter(Component):
@api.model
def create_vplan(self, binding):
raise NotImplementedError
@api.model
def modify_vplan(self, binding):
raise NotImplementedError

View File

@@ -337,6 +337,21 @@ class WuBookAdapter(AbstractComponent):
})
return results
def modify_vplan(self, pid, dtype, value):
rcode, results = self._server.mod_vplans(
self._session_info[0],
self._session_info[1],
[{'pid': pid,
'variation': value,
'variation_type': dtype
}]
)
if rcode != 0:
raise ChannelConnectorError(_("Can't modify virtual pricing plan in wubook"), {
'message': results,
})
return results
def delete_plan(self, channel_plan_id):
rcode, results = self._server.del_plan(
self._session_info[0],

View File

@@ -18,6 +18,9 @@ class ProductPricelistAdapter(Component):
def create_vplan(self, name, pid, dtype, value):
return super(ProductPricelistAdapter, self).create_vplan(name, pid, dtype, value)
def modify_vplan(self, pid, dtype, value):
return super(ProductPricelistAdapter, self).modify_vplan(pid, dtype, value)
def delete_plan(self, external_id):
return super(ProductPricelistAdapter, self).delete_plan(external_id)

View File

@@ -40,12 +40,27 @@ class ProductPricelistExporter(Component):
@api.model
def create_vplan(self, binding):
try:
import wdb; wdb.set_trace()
item_ids = binding.odoo_id.item_ids
base_pricelist = item_ids.base_pricelist_id
value = item_ids.price_discount or item_ids.price_surcharge
dtype = 0
# NOTE: price_discount is greater than zero for a discount
# and lesser than zero for increasing the price a percentage
if item_ids.price_discount > 0:
dtype = -1
elif item_ids.price_discount < 0:
dtype = 1
# NOTE: price_surcharge is greater than zero for increasing the price
# and lesser than zero for a fixed discount
if item_ids.price_surcharge > 0:
dtype = 2
elif item_ids.price_discount < 0:
dtype = -2
external_id = self.backend_adapter.create_vplan(
binding.name,
binding.pid,
binding.dtype,
binding.value,
base_pricelist.channel_bind_ids.external_id,
dtype,
value,
)
except ChannelConnectorError as err:
self.create_issue(
@@ -54,4 +69,36 @@ class ProductPricelistExporter(Component):
channel_message=err.data['message'])
else:
binding.external_id = external_id
self.binder.bind(external_id, binding)
self.binder.bind(external_id, binding)
@api.model
def modify_vplan(self, binding):
try:
item_ids = binding.odoo_id.item_ids
base_pricelist = item_ids.base_pricelist_id
value = item_ids.price_discount or item_ids.price_surcharge
dtype = 0
# NOTE: price_discount is greater than zero for a discount
# and lesser than zero for increasing the price a percentage
if item_ids.price_discount > 0:
dtype = -1
elif item_ids.price_discount < 0:
dtype = 1
# NOTE: price_surcharge is greater than zero for increasing the price
# and lesser than zero for a fixed discount
if item_ids.price_surcharge > 0:
dtype = 2
elif item_ids.price_discount < 0:
dtype = -2
binding.with_context({
'connector_no_export': True,
}).write({'sync_date': fields.Datetime.now()})
return self.backend_adapter.modify_vplan(
base_pricelist.channel_bind_ids.external_id,
dtype,
value)
except ChannelConnectorError as err:
self.create_issue(
section='pricelist',
internal_message=str(err),
channel_message=err.data['message'])