[UPD] unconfirmed channel price after create

This commit is contained in:
Pablo
2019-03-08 02:38:01 +01:00
committed by Dario Lodeiros
parent 4b67c3bf1c
commit 1e710c8731
4 changed files with 37 additions and 16 deletions

View File

@@ -6,6 +6,7 @@ from odoo.exceptions import UserError
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
from odoo.addons import decimal_precision as dp
class ChannelHotelReservation(models.Model): class ChannelHotelReservation(models.Model):
@@ -35,6 +36,9 @@ class ChannelHotelReservation(models.Model):
channel_modified = fields.Boolean("Channel Modified", readonly=True, channel_modified = fields.Boolean("Channel Modified", readonly=True,
default=False, old_name='wmodified') 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 # Inherit binding constrain becouse two reservations can have
# the same external_id # the same external_id
_sql_constraints = [ _sql_constraints = [

View File

@@ -27,6 +27,24 @@ class ChannelHotelReservation(models.Model):
(str(WUBOOK_STATUS_CANCELLED_PENALTY), 'Cancelled with penalty'), (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): class HotelReservation(models.Model):
_inherit = 'hotel.reservation' _inherit = 'hotel.reservation'

View File

@@ -125,6 +125,7 @@ class HotelReservationImporter(Component):
'channel_status': str(book['status']), 'channel_status': str(book['status']),
'channel_raw_data': json.dumps(book), 'channel_raw_data': json.dumps(book),
'channel_modified': book['was_modified'], 'channel_modified': book['was_modified'],
'channel_total_amount': book['amount'],
} }
vals = { vals = {
'real_checkin': real_checkin_str, 'real_checkin': real_checkin_str,
@@ -134,7 +135,6 @@ class HotelReservationImporter(Component):
'adults': persons, 'adults': persons,
'children': book['children'], 'children': book['children'],
'reservation_line_ids': reservation_lines, 'reservation_line_ids': reservation_lines,
'price_unit': tprice,
'to_assign': True, 'to_assign': True,
'state': is_cancellation and 'cancelled' or 'confirm', 'state': is_cancellation and 'cancelled' or 'confirm',
'room_type_id': room_type_bind.odoo_id.id, 'room_type_id': room_type_bind.odoo_id.id,
@@ -201,8 +201,8 @@ class HotelReservationImporter(Component):
'channel_status': str(book['status']), 'channel_status': str(book['status']),
'channel_status_reason': book.get('status_reason', ''), 'channel_status_reason': book.get('status_reason', ''),
'to_assign': True, 'to_assign': True,
'price_unit': book['amount'],
'customer_notes': book['customer_notes'], 'customer_notes': book['customer_notes'],
'channel_total_amount': book['amount'],
}) })
if binding.partner_id.unconfirmed: if binding.partner_id.unconfirmed:
binding.partner_id.write( binding.partner_id.write(
@@ -340,19 +340,19 @@ class HotelReservationImporter(Component):
book, book,
) )
# #
if vals['price_unit'] != book['amount']: # if vals['price_unit'] != book['amount']:
bs = self.env['hotel.board.service.room.type'].browse(vals['board_service_room_id']) # 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'])) # price_room_services_set = vals['price_unit'] + (bs.amount * len(broom['roomdays']))
vals.update({'unconfirmed_channel_price': True}) # vals.update({'unconfirmed_channel_price': True})
# check if difference is owing to misconfigured board services # # check if difference is owing to misconfigured board services
if price_room_services_set != book['amount']: # if price_room_services_set != book['amount']:
internal_reason = 'Please, review the board services included in the reservation.' # internal_reason = 'Please, review the board services included in the reservation.'
self.create_issue( # self.create_issue(
section='reservation', # section='reservation',
internal_message="Invalid reservation total price! %.2f (calculated) != %.2f (wubook) %s" % ( # internal_message="Invalid reservation total price! %.2f (calculated) != %.2f (wubook) %s" % (
vals['price_unit'], book['amount'], internal_reason), # vals['price_unit'], book['amount'], internal_reason),
channel_object_id=book['reservation_code']) # channel_object_id=book['reservation_code'])
# TODO: Add other reasons in case of need # # TODO: Add other reasons in case of need
free_rooms = room_type_bind.odoo_id.check_availability_room_type( free_rooms = room_type_bind.odoo_id.check_availability_room_type(

View File

@@ -27,7 +27,6 @@ class HotelRoomTypeRestrictionImporter(Component):
model_name='channel.hotel.room.type.restriction.item') model_name='channel.hotel.room.type.restriction.item')
_logger.info("==[CHANNEL->ODOO]==== RESTRICTIONS ==") _logger.info("==[CHANNEL->ODOO]==== RESTRICTIONS ==")
_logger.info(plan_restrictions) _logger.info(plan_restrictions)
import wdb; wdb.set_trace()
count = 0 count = 0
for k_rpid, v_rpid in plan_restrictions.items(): for k_rpid, v_rpid in plan_restrictions.items():
channel_restriction_id = channel_reserv_restriction_obj.search([ channel_restriction_id = channel_reserv_restriction_obj.search([