[ADD] compute binding fields in hotel.reservation model

This commit is contained in:
Dario Lodeiros
2019-04-28 14:19:59 +02:00
parent eb7d7900a9
commit 69c9ece17d
2 changed files with 37 additions and 21 deletions

View File

@@ -21,20 +21,17 @@ class ChannelHotelReservation(models.Model):
ondelete='cascade')
ota_id = fields.Many2one('channel.ota.info',
string='Channel OTA ID',
readonly=True,
old_name='wchannel_id')
readonly=True)
ota_reservation_id = fields.Char("Channel OTA Reservation Code",
readonly=True,
old_name='wchannel_reservation_code')
channel_raw_data = fields.Text(readonly=True, old_name='wbook_json')
readonly=True)
channel_raw_data = fields.Text(readonly=True)
channel_status = fields.Selection([
('0', 'No Channel'),
], string='Channel Status', default='0', readonly=True, old_name='wstatus')
channel_status_reason = fields.Char("Channel Status Reason", readonly=True,
old_name='wstatus_reason')
], string='Channel Status', default='0', readonly=True)
channel_status_reason = fields.Char("Channel Status Reason", readonly=True)
channel_modified = fields.Boolean("Channel Modified", readonly=True,
default=False, old_name='wmodified')
default=False)
channel_total_amount = fields.Monetary(string='Channel Total Amount',
readonly=True, digits=dp.get_precision('Product Price'))
@@ -143,11 +140,19 @@ class HotelReservation(models.Model):
comodel_name='channel.hotel.reservation',
inverse_name='odoo_id',
string='Hotel Channel Connector Bindings')
ota_id = fields.Many2one('channel.ota.info',
string='Channel OTA ID',
readonly=True,
compute='_compute_external_data')
ota_reservation_id = fields.Char("Channel OTA Reservation Code",
compute='_compute_external_data')
external_id = fields.Char(string='ID on Channel',
compute='_compute_external_data')
# TODO: Dario v2
# origin_sale = fields.Char('Origin', compute=_get_origin_sale,
# store=True)
is_from_ota = fields.Boolean('Is From OTA',
compute='_is_from_ota',
compute='_compute_external_data',
store=True)
able_to_modify_channel = fields.Boolean(compute=_set_access_for_channel_fields,
string='Is user able to modify channel fields?')
@@ -155,11 +160,22 @@ class HotelReservation(models.Model):
unconfirmed_channel_price = fields.Boolean(related='folio_id.unconfirmed_channel_price')
@api.depends('channel_bind_ids.external_id', 'channel_bind_ids.ota_id')
def _is_from_ota(self):
@api.depends('channel_bind_ids.external_id', 'channel_bind_ids.ota_id',
'channel_bind_ids.ota_reservation_id')
def _compute_external_data(self):
for record in self:
record.is_from_ota = bool(any(bind.ota_reservation_id
for bind in record.channel_bind_ids))
vals = {
'ota_reservation_id': record.channel_bind_ids[0].
ota_reservation_id if
record.channel_bind_ids else False,
'ota_id': record.channel_bind_ids[0].ota_id.id if
record.channel_bind_ids else False,
'external_id': record.channel_bind_ids[0].external_id if
record.channel_bind_ids else False,
'is_from_ota': bool(any(bind.ota_reservation_id
for bind in record.channel_bind_ids))
}
record.update(vals)
@api.onchange('checkin', 'checkout')
def onchange_dates(self):

View File

@@ -6,7 +6,8 @@
<field name="inherit_id" ref="hotel.hotel_reservation_view_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='channel_type']" position="after">
<!-- field name="channel_reservation_id" attrs='{"readonly": [("able_to_modify_channel","=",False)], "invisible":[("channel_type","!=", "web")]}' string="OTA"/-->
<field name="ota_reservation_id" attrs='{"readonly": [("able_to_modify_channel","=",False)], "invisible":[("channel_type","!=", "web")]}' string="OTA code"/>
<field name="ota_id" readonly="True" attrs='{"invisible":[("channel_type","!=", "web")]}' string="OTA"/>
</xpath>
<xpath expr="//field[@name='shared_folio']" position="before">
<group colspan="6" col="6">
@@ -15,10 +16,6 @@
</xpath>
<xpath expr="//field[@name='partner_internal_comment']" position="after">
<field name="able_to_modify_channel" invisible="True"/>
<!-- <field name="customer_notes" readonly="1"
attrs="{'invisible': [('channel_reservation_id','=',False)]}"
nolabel="1" colspan="2"
/> -->
</xpath>
<xpath expr="//page[@name='days']" position="after">
<page name="connector" string="Channel Connector" groups="connector.group_connector_manager">
@@ -60,7 +57,8 @@
<field name="inherit_id" ref="hotel.hotel_reservation_view_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='checkout']" position="after">
<!-- field name="origin_sale"/-->
<field name="ota_id"/>
<field name="ota_reservation_id"/>
</xpath>
<xpath expr="//field[@name='checkout']" position="after">
<field name="is_from_ota" invisible="1"/>
@@ -80,7 +78,9 @@
<field name="inherit_id" ref="hotel.hotel_reservation_view_search" />
<field name="arch" type="xml">
<xpath expr="//field[@name='folio_id']" position="after">
<!-- field name="wchannel_reservation_code"/-->
<field name="ota_reservation_id" />
<field name="ota_id" />
<field name="external_id" />
</xpath>
<xpath expr="//group" position="inside">
<!-- filter name="origin" string="Origin" domain="[]"