From 44767febe35ece3fdf0e73288d9e1cd990e6d801 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 28 Mar 2019 11:56:27 +0100 Subject: [PATCH 1/8] [FIX] align days of the week in two lines --- hotel/wizard/massive_changes.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hotel/wizard/massive_changes.xml b/hotel/wizard/massive_changes.xml index 7071b9320..88b3483a5 100644 --- a/hotel/wizard/massive_changes.xml +++ b/hotel/wizard/massive_changes.xml @@ -16,13 +16,13 @@ - - - - - - - + + + + + + + From b97802aeb0bb233eb95f0e575fd6a495fdd36740 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 28 Mar 2019 16:11:06 +0100 Subject: [PATCH 2/8] [FIX] use field date in restriction.item --- hotel/wizard/massive_changes.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/hotel/wizard/massive_changes.py b/hotel/wizard/massive_changes.py index 8facef563..8e6065e44 100644 --- a/hotel/wizard/massive_changes.py +++ b/hotel/wizard/massive_changes.py @@ -26,8 +26,7 @@ class MassiveChangesWizard(models.TransientModel): ('0', 'Global'), ('1', 'Room Type'), ], string='Applied On', default='0') - # room_type_ids = fields.Many2many('hotel.virtual.room', - # string="Virtual Rooms") + room_type_ids = fields.Many2many('hotel.room.type', string="Room Types") # Restriction fields @@ -157,11 +156,10 @@ class MassiveChangesWizard(models.TransientModel): def _save_restrictions(self, ndate, room_types, record): hotel_room_type_re_it_obj = self.env['hotel.room.type.restriction.item'] domain = [ - ('date_start', '>=', ndate.strftime(DEFAULT_SERVER_DATE_FORMAT)), - ('date_end', '<=', ndate.strftime(DEFAULT_SERVER_DATE_FORMAT)), + ('date', '>=', ndate.strftime(DEFAULT_SERVER_DATE_FORMAT)), + ('date', '<=', ndate.strftime(DEFAULT_SERVER_DATE_FORMAT)), ('restriction_id', '=', record.restriction_id.id), ] - for room_type in room_types: vals = self._get_restrictions_values(record) if not any(vals): @@ -173,8 +171,7 @@ class MassiveChangesWizard(models.TransientModel): rrest_item_ids.write(vals) else: vals.update({ - 'date_start': ndate.strftime(DEFAULT_SERVER_DATE_FORMAT), - 'date_end': ndate.strftime(DEFAULT_SERVER_DATE_FORMAT), + 'date': ndate.strftime(DEFAULT_SERVER_DATE_FORMAT), 'restriction_id': record.restriction_id.id, 'room_type_id': room_type.id, }) From c2922f6cfa02aa6264636261c6c163b3ecca9d33 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 28 Mar 2019 16:14:17 +0100 Subject: [PATCH 3/8] [UPD] update import from odoo --- hotel/wizard/massive_changes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hotel/wizard/massive_changes.py b/hotel/wizard/massive_changes.py index 8e6065e44..4a78a000d 100644 --- a/hotel/wizard/massive_changes.py +++ b/hotel/wizard/massive_changes.py @@ -1,8 +1,8 @@ # Copyright 2017 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from datetime import timedelta -from openerp import models, fields, api -from openerp.tools import DEFAULT_SERVER_DATE_FORMAT +from odoo import models, fields, api +from odoo.tools import DEFAULT_SERVER_DATE_FORMAT class MassiveChangesWizard(models.TransientModel): From 3d34ab2f2c768047caa878a66c1f1ff724eac53e Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 28 Mar 2019 16:57:02 +0100 Subject: [PATCH 4/8] [UPD] Update fields layout --- .../wizard/inherited_massive_changes.xml | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/hotel_channel_connector/wizard/inherited_massive_changes.xml b/hotel_channel_connector/wizard/inherited_massive_changes.xml index 4377dd910..99c0111a5 100644 --- a/hotel_channel_connector/wizard/inherited_massive_changes.xml +++ b/hotel_channel_connector/wizard/inherited_massive_changes.xml @@ -7,27 +7,18 @@ - - - - - - - - - - - - - - - - - - - - -
Max. Avail.
Quota
No OTA
+ + + + + + + + +
From a5b3ec8f57079c04ce62ef9f072552661913fc2c Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 28 Mar 2019 18:49:41 +0100 Subject: [PATCH 5/8] [IMP] Update fields layout and UX --- hotel/wizard/massive_changes.xml | 14 +++++++------- .../wizard/inherited_massive_changes.xml | 15 +++++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/hotel/wizard/massive_changes.xml b/hotel/wizard/massive_changes.xml index 88b3483a5..0163ec07c 100644 --- a/hotel/wizard/massive_changes.xml +++ b/hotel/wizard/massive_changes.xml @@ -16,13 +16,13 @@ - - - - - - - + + + + + + + diff --git a/hotel_channel_connector/wizard/inherited_massive_changes.xml b/hotel_channel_connector/wizard/inherited_massive_changes.xml index 99c0111a5..964b3935c 100644 --- a/hotel_channel_connector/wizard/inherited_massive_changes.xml +++ b/hotel_channel_connector/wizard/inherited_massive_changes.xml @@ -8,17 +8,20 @@ - + + attrs="{'readonly':[('change_max_avail', '=', False)], + 'invisible':[('change_max_avail', '=', False)]}"/> - + + attrs="{'readonly':[('change_quota', '=', False)], + 'invisible':[('change_quota', '=', False)]}"/> - + + attrs="{'readonly':[('change_no_ota', '=', False)], + 'invisible':[('change_no_ota', '=', False)]}"/> From 8fc032aca2533788cbbc800fd1bf91caaed69352 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 28 Mar 2019 18:50:22 +0100 Subject: [PATCH 6/8] [FIX] task_54 wrong default values in Availability --- .../wizard/inherited_massive_changes.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/hotel_channel_connector/wizard/inherited_massive_changes.py b/hotel_channel_connector/wizard/inherited_massive_changes.py index c6d56e7c2..d1aa6cf38 100644 --- a/hotel_channel_connector/wizard/inherited_massive_changes.py +++ b/hotel_channel_connector/wizard/inherited_massive_changes.py @@ -13,15 +13,26 @@ class MassiveChangesWizard(models.TransientModel): # Availability fields change_quota = fields.Boolean(default=False) - quota = fields.Integer('Quota', default=-1) + quota = fields.Integer('Quota', default=0) change_max_avail = fields.Boolean(default=False) - max_avail = fields.Integer('Max. Avail.', default=-1) + max_avail = fields.Integer('Max. Avail.', default=0) change_no_ota = fields.Boolean(default=False) no_ota = fields.Boolean('No OTA', default=False) @api.model def _get_availability_values(self, ndate, room_type, record): - vals = {} + room_type_avail = self.env['hotel.room.type.availability'].search([ + ('date', '=', ndate.strftime(DEFAULT_SERVER_DATE_FORMAT)), + ('room_type_id', '=', room_type.id) + ]) + channel_room_type = self.env['channel.hotel.room.type'].search([ + ('odoo_id', '=', room_type.id) + ]) or None + vals = { + 'quota': room_type_avail.quota or channel_room_type.default_quota, + 'max_avail': room_type_avail.max_avail or channel_room_type.default_max_avail, + 'no_ota': room_type_avail.no_ota or channel_room_type.default_max_avail, + } if record.change_quota: vals.update({ 'quota': record.quota, From 389621990acd06d7f0c8442cdc6001361c26c5c5 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 28 Mar 2019 20:18:16 +0100 Subject: [PATCH 7/8] [FIX] Hot Fix set channel_pushed = False for no_ota This Fix works because no_ota is a Boolean field. Therefore, if `no_ota` is in fields_checked it is because its value has changed from `True` to `False` or from `False` to `True`. Regardless other fields, a push_availability is mandatory --- .../models/hotel_room_type_availability/common.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hotel_channel_connector/models/hotel_room_type_availability/common.py b/hotel_channel_connector/models/hotel_room_type_availability/common.py index bf83eb3b4..d06b393ee 100644 --- a/hotel_channel_connector/models/hotel_room_type_availability/common.py +++ b/hotel_channel_connector/models/hotel_room_type_availability/common.py @@ -222,6 +222,9 @@ class BindingHotelRoomTypeAvailabilityListener(Component): binding.backend_id.id, room_type_id=record.room_type_id.id) + if 'no_ota' in fields_checked: + binding.write({'channel_pushed': False}) + @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_create(self, record, fields=None): if not any(record.channel_bind_ids): @@ -261,7 +264,7 @@ class ChannelBindingHotelRoomTypeAvailabilityListener(Component): @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_write(self, record, fields=None): - fields_to_check = ('date', 'channel_avail') # no_ota ¿? + fields_to_check = ('date', 'channel_avail') fields_checked = [elm for elm in fields_to_check if elm in fields] _logger.info("==[on_record_write] :: channel.hotel.room.type.availability==") From 2a90f849a2ba6f0cb4bb1c8cad94f6ca664433e4 Mon Sep 17 00:00:00 2001 From: Pablo Date: Fri, 29 Mar 2019 17:49:13 +0100 Subject: [PATCH 8/8] [FIX] wrong default values and no_ota --- .../hotel_room_type_availability/common.py | 66 ++++++++++++++----- .../wizard/inherited_massive_changes.py | 13 +--- 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/hotel_channel_connector/models/hotel_room_type_availability/common.py b/hotel_channel_connector/models/hotel_room_type_availability/common.py index d06b393ee..2e4f53c77 100644 --- a/hotel_channel_connector/models/hotel_room_type_availability/common.py +++ b/hotel_channel_connector/models/hotel_room_type_availability/common.py @@ -18,18 +18,22 @@ class HotelRoomTypeAvailability(models.Model): @api.model def _default_max_avail(self): - room_type_id = self._context.get('room_type_id') - if room_type_id: - room_type_id = self.env['hotel.room_type'].browse(room_type_id) - return room_type_id.default_max_avail if room_type_id else -1 + room_type_id = self.room_type_id.id or self._context.get('room_type_id') + channel_room_type = self.env['channel.hotel.room.type'].search([ + ('odoo_id', '=', room_type_id) + ]) or None + if channel_room_type: + return channel_room_type.default_max_avail return -1 @api.model def _default_quota(self): - room_type_id = self._context.get('room_type_id') - if room_type_id: - room_type_id = self.env['hotel.room_type'].browse(room_type_id) - return room_type_id.default_quota if room_type_id else -1 + room_type_id = self.room_type_id.id or self._context.get('room_type_id') + channel_room_type = self.env['channel.hotel.room.type'].search([ + ('odoo_id', '=', room_type_id) + ]) or None + if channel_room_type: + return channel_room_type.default_quota return -1 room_type_id = fields.Many2one('hotel.room.type', 'Room Type', @@ -44,6 +48,7 @@ class HotelRoomTypeAvailability(models.Model): quota = fields.Integer("Quota", default=_default_quota, help="Quota assigned to the channel.") + # TODO: WHY max_avail IS READONLY ¿? max_avail = fields.Integer("Max. Availability", default=-1, readonly=True, help="Maximum simultaneous availability.") @@ -72,8 +77,34 @@ class HotelRoomTypeAvailability(models.Model): @api.onchange('room_type_id') def onchange_room_type_id(self): - if self.room_type_id: - self.quota = self.room_type_id.default_quota + channel_room_type = self.env['channel.hotel.room.type'].search([ + ('odoo_id', '=', self.room_type_id.id) + ]) or None + if channel_room_type: + self.quota = channel_room_type.default_quota + self.max_avail = channel_room_type.default_max_avail + self.no_ota = 0 + + @api.model + def create(self, vals): + vals.update(self._prepare_add_missing_fields(vals)) + return super().create(vals) + + @api.model + def _prepare_add_missing_fields(self, values): + """ Deduce missing required fields from the onchange """ + res = {} + onchange_fields = ['quota', 'max_avail'] + if values.get('room_type_id'): + record = self.new(values) + if 'quota' not in values: + record.quota = record._default_quota() + if 'max_avail' not in values: + record.max_avail = record._default_max_avail() + for field in onchange_fields: + if field not in values: + res[field] = record._fields[field].convert_to_write(record[field], record) + return res class ChannelHotelRoomTypeAvailability(models.Model): @@ -152,6 +183,8 @@ class ChannelHotelRoomTypeAvailability(models.Model): _logger.info(vals_avail) if room_type_avail_id.channel_avail != avail: vals_avail.update({'channel_avail': avail}) + if self._context.get('update_no_ota', False): + vals_avail.update({'channel_pushed': False}) if vals_avail: room_type_avail_id.write(vals_avail) @@ -209,11 +242,13 @@ class BindingHotelRoomTypeAvailabilityListener(Component): fields_to_check = ('quota', 'max_avail', 'no_ota') fields_checked = [elm for elm in fields_to_check if elm in fields] + _logger.info("==[on_record_write] :: hotel.room.type.availability==") + _logger.info(fields) + if any(fields_checked) and any(record.channel_bind_ids): - - _logger.info("==[on_record_write] :: hotel.room.type.availability==") - _logger.info(fields) - + if 'no_ota' in fields_checked: + self.env.context = dict(self.env.context) + self.env.context.update({'update_no_ota': True}) for binding in record.channel_bind_ids: binding.refresh_availability( record.date, @@ -222,9 +257,6 @@ class BindingHotelRoomTypeAvailabilityListener(Component): binding.backend_id.id, room_type_id=record.room_type_id.id) - if 'no_ota' in fields_checked: - binding.write({'channel_pushed': False}) - @skip_if(lambda self, record, **kwargs: self.no_connector_export(record)) def on_record_create(self, record, fields=None): if not any(record.channel_bind_ids): diff --git a/hotel_channel_connector/wizard/inherited_massive_changes.py b/hotel_channel_connector/wizard/inherited_massive_changes.py index d1aa6cf38..7b7597685 100644 --- a/hotel_channel_connector/wizard/inherited_massive_changes.py +++ b/hotel_channel_connector/wizard/inherited_massive_changes.py @@ -21,18 +21,7 @@ class MassiveChangesWizard(models.TransientModel): @api.model def _get_availability_values(self, ndate, room_type, record): - room_type_avail = self.env['hotel.room.type.availability'].search([ - ('date', '=', ndate.strftime(DEFAULT_SERVER_DATE_FORMAT)), - ('room_type_id', '=', room_type.id) - ]) - channel_room_type = self.env['channel.hotel.room.type'].search([ - ('odoo_id', '=', room_type.id) - ]) or None - vals = { - 'quota': room_type_avail.quota or channel_room_type.default_quota, - 'max_avail': room_type_avail.max_avail or channel_room_type.default_max_avail, - 'no_ota': room_type_avail.no_ota or channel_room_type.default_max_avail, - } + vals = {} if record.change_quota: vals.update({ 'quota': record.quota,