[UPD] unconfirmed channel price after create

This commit is contained in:
Pablo
2019-03-08 02:38:01 +01:00
parent 0abcbdabd7
commit ea40f2ed74
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.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 = [

View File

@@ -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'

View File

@@ -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(

View File

@@ -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([