From ea40f2ed74f4d275d0e660439ce2ef76c6ab90c3 Mon Sep 17 00:00:00 2001 From: Pablo Date: Fri, 8 Mar 2019 02:38:01 +0100 Subject: [PATCH] [UPD] unconfirmed channel price after create --- .../models/hotel_reservation/common.py | 4 +++ .../models/hotel_reservation/common.py | 18 +++++++++++ .../models/hotel_reservation/importer.py | 30 +++++++++---------- .../importer.py | 1 - 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/hotel_channel_connector/models/hotel_reservation/common.py b/hotel_channel_connector/models/hotel_reservation/common.py index 4aa11b50a..72d212dac 100644 --- a/hotel_channel_connector/models/hotel_reservation/common.py +++ b/hotel_channel_connector/models/hotel_reservation/common.py @@ -6,6 +6,7 @@ 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 +from odoo.addons import decimal_precision as dp class ChannelHotelReservation(models.Model): @@ -35,6 +36,9 @@ class ChannelHotelReservation(models.Model): channel_modified = fields.Boolean("Channel Modified", readonly=True, default=False, old_name='wmodified') + channel_total_amount = fields.Monetary(string='Channel Total Amount', + readonly=True, digits=dp.get_precision('Product Price')) + # Inherit binding constrain becouse two reservations can have # the same external_id _sql_constraints = [ diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/common.py b/hotel_channel_connector_wubook/models/hotel_reservation/common.py index 4b18008a6..0e86668f2 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/common.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/common.py @@ -27,6 +27,24 @@ class ChannelHotelReservation(models.Model): (str(WUBOOK_STATUS_CANCELLED_PENALTY), 'Cancelled with penalty'), ]) + @api.model + def create(self, vals): + # TODO FIX: RuntimeError: RuntimeError('super(): no arguments',) ¿? + record = super(ChannelHotelReservation, self).create(vals) + if record.channel_total_amount != record.odoo_id.price_room_services_set: + record.odoo_id.unconfirmed_channel_price = True + self.env['hotel.channel.connector.issue'].create({ + 'backend_id': record.backend_id.id, + 'section': 'reservation', + 'internal_message': "Disagreement in reservation price. Odoo marked %.2f whereas the channel sent %.2f. %s" % ( + record.odoo_id.price_room_services_set, + record.channel_total_amount, + 'Please, review the board services included in the reservation.'), + 'channel_object_id': record.external_id + }) + + return record + class HotelReservation(models.Model): _inherit = 'hotel.reservation' diff --git a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py index 742eb2a5b..7c059a202 100644 --- a/hotel_channel_connector_wubook/models/hotel_reservation/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_reservation/importer.py @@ -125,6 +125,7 @@ class HotelReservationImporter(Component): 'channel_status': str(book['status']), 'channel_raw_data': json.dumps(book), 'channel_modified': book['was_modified'], + 'channel_total_amount': book['amount'], } vals = { 'real_checkin': real_checkin_str, @@ -134,7 +135,6 @@ class HotelReservationImporter(Component): 'adults': persons, 'children': book['children'], 'reservation_line_ids': reservation_lines, - 'price_unit': tprice, 'to_assign': True, 'state': is_cancellation and 'cancelled' or 'confirm', 'room_type_id': room_type_bind.odoo_id.id, @@ -201,8 +201,8 @@ class HotelReservationImporter(Component): 'channel_status': str(book['status']), 'channel_status_reason': book.get('status_reason', ''), 'to_assign': True, - 'price_unit': book['amount'], 'customer_notes': book['customer_notes'], + 'channel_total_amount': book['amount'], }) if binding.partner_id.unconfirmed: binding.partner_id.write( @@ -340,19 +340,19 @@ class HotelReservationImporter(Component): book, ) # - if vals['price_unit'] != book['amount']: - bs = self.env['hotel.board.service.room.type'].browse(vals['board_service_room_id']) - price_room_services_set = vals['price_unit'] + (bs.amount * len(broom['roomdays'])) - vals.update({'unconfirmed_channel_price': True}) - # check if difference is owing to misconfigured board services - if price_room_services_set != book['amount']: - internal_reason = 'Please, review the board services included in the reservation.' - self.create_issue( - section='reservation', - internal_message="Invalid reservation total price! %.2f (calculated) != %.2f (wubook) %s" % ( - vals['price_unit'], book['amount'], internal_reason), - channel_object_id=book['reservation_code']) - # TODO: Add other reasons in case of need + # if vals['price_unit'] != book['amount']: + # bs = self.env['hotel.board.service.room.type'].browse(vals['board_service_room_id']) + # price_room_services_set = vals['price_unit'] + (bs.amount * len(broom['roomdays'])) + # vals.update({'unconfirmed_channel_price': True}) + # # check if difference is owing to misconfigured board services + # if price_room_services_set != book['amount']: + # internal_reason = 'Please, review the board services included in the reservation.' + # self.create_issue( + # section='reservation', + # internal_message="Invalid reservation total price! %.2f (calculated) != %.2f (wubook) %s" % ( + # vals['price_unit'], book['amount'], internal_reason), + # channel_object_id=book['reservation_code']) + # # TODO: Add other reasons in case of need free_rooms = room_type_bind.odoo_id.check_availability_room_type( diff --git a/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py b/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py index d2be6b573..842a34d1b 100644 --- a/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py +++ b/hotel_channel_connector_wubook/models/hotel_room_type_restriction_item/importer.py @@ -27,7 +27,6 @@ class HotelRoomTypeRestrictionImporter(Component): model_name='channel.hotel.room.type.restriction.item') _logger.info("==[CHANNEL->ODOO]==== RESTRICTIONS ==") _logger.info(plan_restrictions) - import wdb; wdb.set_trace() count = 0 for k_rpid, v_rpid in plan_restrictions.items(): channel_restriction_id = channel_reserv_restriction_obj.search([