[ADD] Manage board services in WuBook rooms

This commit is contained in:
Pablo
2019-02-13 09:19:56 +01:00
parent 3caeaad379
commit ba37dd8d13
5 changed files with 40 additions and 6 deletions

View File

@@ -3,6 +3,7 @@
from odoo import api, models, fields, _ from odoo import api, models, fields, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
from odoo.addons import decimal_precision as dp
from odoo.addons.queue_job.job import job from odoo.addons.queue_job.job import job
from odoo.addons.component.core import Component from odoo.addons.component.core import Component
from odoo.addons.component_event import skip_if from odoo.addons.component_event import skip_if
@@ -18,8 +19,12 @@ class ChannelHotelRoomType(models.Model):
string='Room Type', string='Room Type',
required=True, required=True,
ondelete='cascade') ondelete='cascade')
channel_short_code = fields.Char("Channel Short Code", readonly=True, old_name='wscode') channel_short_code = fields.Char("Channel Short Code", old_name='wscode')
ota_capacity = fields.Integer("OTA's Capacity", default=1, old_name='wcapacity') ota_capacity = fields.Integer("OTA's Capacity", default=1, old_name='wcapacity')
min_price = fields.Float('Min. Price', default=5.0, digits=dp.get_precision('Product Price'),
help="Setup the min price to prevent incidents while editing your prices.")
max_price = fields.Float('Max. Price', default=200.0, digits=dp.get_precision('Product Price'),
help="Setup the max price to prevent incidents while editing your prices.")
@api.onchange('room_ids') @api.onchange('room_ids')
def _get_capacity(self): def _get_capacity(self):

View File

@@ -15,6 +15,10 @@
<field name="channel_short_code" /> <field name="channel_short_code" />
<field name="ota_capacity" /> <field name="ota_capacity" />
</group> </group>
<group>
<field name="min_price" class="oe_inline"/>
<field name="max_price" class="oe_inline"/>
</group>
</form> </form>
</field> </field>
</record> </record>

View File

@@ -122,6 +122,8 @@ class WuBookAdapter(AbstractComponent):
# === ROOMS # === ROOMS
def create_room(self, shortcode, name, capacity, price, availability, defboard, rtype): def create_room(self, shortcode, name, capacity, price, availability, defboard, rtype):
import wdb;
wdb.set_trace()
rcode, results = self._server.new_room( rcode, results = self._server.new_room(
self._session_info[0], self._session_info[0],
self._session_info[1], self._session_info[1],
@@ -140,7 +142,8 @@ class WuBookAdapter(AbstractComponent):
}) })
return results return results
def modify_room(self, channel_room_id, name, capacity, price, availability, scode, defboard, rtype): def modify_room(self, channel_room_id, name, capacity, price, availability, scode, defboard,
names, descriptions, boards, min_price, max_price, rtype):
rcode, results = self._server.mod_room( rcode, results = self._server.mod_room(
self._session_info[0], self._session_info[0],
self._session_info[1], self._session_info[1],
@@ -151,7 +154,13 @@ class WuBookAdapter(AbstractComponent):
availability, availability,
scode, scode,
defboard, defboard,
rtype names,
descriptions,
boards,
min_price,
max_price,
int(rtype),
False,
) )
if rcode != 0: if rcode != 0:
raise ChannelConnectorError(_("Can't modify room in WuBook"), { raise ChannelConnectorError(_("Can't modify room in WuBook"), {

View File

@@ -16,9 +16,11 @@ class HotelRoomTypeAdapter(Component):
def fetch_rooms(self): def fetch_rooms(self):
return super(HotelRoomTypeAdapter, self).fetch_rooms() return super(HotelRoomTypeAdapter, self).fetch_rooms()
def modify_room(self, channel_room_id, name, capacity, price, availability, scode, defboard, rtype): def modify_room(self, channel_room_id, name, capacity, price, availability, scode, defboard,
names, descriptions, boards, min_price, max_price, rtype):
return super(HotelRoomTypeAdapter, self).modify_room( return super(HotelRoomTypeAdapter, self).modify_room(
channel_room_id, name, capacity, price, availability, scode, defboard, rtype) channel_room_id, name, capacity, price, availability, scode, defboard,
names, descriptions, boards, min_price, max_price, rtype)
def delete_room(self, channel_room_id): def delete_room(self, channel_room_id):
return super(HotelRoomTypeAdapter, self).delete_room(channel_room_id) return super(HotelRoomTypeAdapter, self).delete_room(channel_room_id)

View File

@@ -15,6 +15,14 @@ class HotelRoomTypeExporter(Component):
binding.with_context({ binding.with_context({
'connector_no_export': True, 'connector_no_export': True,
}).write({'sync_date': fields.Datetime.now()}) }).write({'sync_date': fields.Datetime.now()})
# TODO: do not write if backend_adapter.modify_room through an error
boards = {}
for board in binding.board_service_room_type_ids:
boards.update(
{board.channel_service: {
'dtype': 2 if board.price_type == 'fixed' else 1,
'value': board.amount}}
)
return self.backend_adapter.modify_room( return self.backend_adapter.modify_room(
binding.external_id, binding.external_id,
binding.name, binding.name,
@@ -23,7 +31,13 @@ class HotelRoomTypeExporter(Component):
binding.total_rooms_count, binding.total_rooms_count,
binding.channel_short_code, binding.channel_short_code,
'nb', 'nb',
binding.class_id and binding.class_id.code_class or False) {},
{},
boards,
binding.min_price,
binding.max_price,
binding.class_id and binding.class_id.code_class or False,
)
except ChannelConnectorError as err: except ChannelConnectorError as err:
self.create_issue( self.create_issue(
section='room', section='room',