[ADD] Room Matik Get Stay

This commit is contained in:
Jose Luis
2019-04-05 13:24:41 +02:00
parent 73e895ed79
commit d85499c213
4 changed files with 109 additions and 29 deletions

View File

@@ -8,21 +8,21 @@ import logging
class HotelFolio(models.Model):
_inherit = 'hotel.folio'
_inherit = 'hotel.checkin.partner'
@api.model
def rm_checkin_partner(self, stay):
# CHECK-IN
_logger = logging.getLogger(__name__)
folio_rm = self.env['hotel.folio'].search([('id', '=', stay['Code'])])
reservation_rm = self.env['hotel.reservation'].search([('id', '=', stay['Code'])])
# folio_res = self.env['hotel.checkin.partner'].search([('id', '=', stay['Code'])])
json_response = dict()
# folio_rm = self.env['hotel.folio'].search([('id', '=', stay['Code'])])
reservation_rm = self.env['hotel.reservation'].search([('id', '=',
stay['Code'])])
# Need checkin?
total_chekins = reservation_rm.checkin_partner_pending_count
if total_chekins > 0 and len(stay["Customers"]) <= total_chekins:
_logger.info('ROOMMATIK checkin %s customer in %s Reservation.', total_chekins, reservation_rm.id)
_logger.info('ROOMMATIK checkin %s customer in %s Reservation.',
total_chekins,
reservation_rm.id)
for room_partner in stay["Customers"]:
# ADD costumer ?
# costumer = self.env['res.partner'].rm_add_customer(room_partner["Customer"])
@@ -33,22 +33,32 @@ class HotelFolio(models.Model):
checkin_partner_val = {
'folio_id': reservation_rm.folio_id.id,
'reservation_id': reservation_rm.id,
'enter_date': datetime.strptime(stay["Arrival"], "%d%m%Y").date(),
'exit_date': datetime.strptime(stay["Departure"], "%d%m%Y").date(),
'enter_date': datetime.strptime(stay["Arrival"],
"%d%m%Y").date(),
'exit_date': datetime.strptime(stay["Departure"],
"%d%m%Y").date(),
'partner_id': room_partner["Customer"]["Id"],
'email': room_partner["Customer"]["Contact"]["Email"],
'mobile': room_partner["Customer"]["Contact"]["Mobile"],
'document_type': room_partner["Customer"]["IdentityDocument"]["Type"],
'document_number': room_partner["Customer"]["IdentityDocument"]["Number"],
'document_expedition_date': datetime.strptime(room_partner["Customer"]["IdentityDocument"]["ExpiryDate"], "%d%m%Y").date(),
'document_type': room_partner["Customer"][
"IdentityDocument"]["Type"],
'document_number': room_partner["Customer"][
"IdentityDocument"]["Number"],
'document_expedition_date': datetime.strptime(room_partner[
"Customer"]["IdentityDocument"][
"ExpiryDate"], "%d%m%Y").date(),
'gender': room_partner["Customer"]["Sex"],
'birthdate_date': datetime.strptime(room_partner["Customer"]["Birthday"], "%d%m%Y").date(),
'code_ine_id': room_partner["Customer"]["Address"]["Province"],
'birthdate_date': datetime.strptime(room_partner[
"Customer"]["Birthday"], "%d%m%Y").date(),
'code_ine_id': room_partner["Customer"][
"Address"]["Province"],
'state': 'booking',
}
try:
record = self.env['hotel.checkin.partner'].create(checkin_partner_val)
_logger.info('ROOMMATIK check-in Document: %s in (%s Reservation) ID:%s.',
record = self.env['hotel.checkin.partner'].create(
checkin_partner_val)
_logger.info('ROOMMATIK check-in Document: %s in \
(%s Reservation) ID:%s.',
checkin_partner_val['document_number'],
checkin_partner_val['reservation_id'],
record.id)
@@ -56,15 +66,82 @@ class HotelFolio(models.Model):
json_response = stay
except:
json_response = {'Estate': 'Error not create Checkin'}
_logger.error('ROOMMATIK writing %s in (%s reservation_id).',
_logger.error('ROOMMATIK writing %s in reservation: %s).',
checkin_partner_val['document_number'],
checkin_partner_val['reservation_id'])
return json_response
# ATENCION SI LO CREA, AUNQUE DA ERROR CUANDO ES LA MISMA PERSONA.
else:
json_response = {'Estate': 'Error checkin_partner_pending_count values do not match.'}
_logger.error('ROOMMATIK checkin pending count do not match for Reservation ID %s.', reservation_rm.id)
json_response = {'Estate': 'Error checkin_partner_pending_count \
values do not match.'}
_logger.error('ROOMMATIK checkin pending count do not match for \
Reservation ID %s.', reservation_rm.id)
json_response = json.dumps(json_response)
return json_response
@api.model
def rm_get_stay(self, code):
reserva = self.search([('id', '=', code)])
stay = {'Code': code}
stay['Id'] = reserva.folio_id.id
stay['Room'] = {}
stay['Room']['Id'] = reserva.reservation_id.room_id.id
stay['Room']['Name'] = reserva.reservation_id.room_id.name
stay['RoomType'] = {}
stay['RoomType']['Id'] = reserva.reservation_id.room_type_id.id
stay['RoomType']['Name'] = reserva.reservation_id.room_type_id.name
stay['RoomType']['GuestNumber'] = "xxxxxxx"
stay['Arrival'] = reserva.reservation_id.real_checkin + 'T' + reserva.reservation_id.arrival_hour + ':00'
stay['Departure'] = reserva.reservation_id.real_checkout + 'T' + reserva.reservation_id.departure_hour + ':00'
# TODO ADD Customers ......................................................checkin_partner_ids
stay['Customers'] = []
for idx, cpi in enumerate(reserva.reservation_id.checkin_partner_ids):
stay['Customers'].append({'Customer':{}})
stay['Customers'][idx]['Customer']['Id'] = cpi.id
stay['Customers'][idx]['Customer']['FirstName'] = cpi.partner_id.firstname
stay['Customers'][idx]['Customer']['LastName1'] = cpi.partner_id.lastname
stay['Customers'][idx]['Customer']['LastName2'] = cpi.partner_id.lastname2
stay['Customers'][idx]['Customer']['Birthday'] = cpi.partner_id.birthdate_date
stay['Customers'][idx]['Customer']['Sex'] = cpi.partner_id.gender
stay['Customers'][idx]['Customer']['Address'] = {
'Nationality': {},
'Country': cpi.partner_id.country_id.name,
'ZipCode': cpi.partner_id.zip,
'City': cpi.partner_id.city,
'Street': cpi.partner_id.street,
'House': cpi.partner_id.street2,
# 'Flat': "xxxxxxx",
# 'Number': "xxxxxxx",
'Province': cpi.partner_id.state_id.name,
}
stay['Customers'][idx]['Customer']['IdentityDocument'] = {
'Number': cpi.document_number,
'Type': cpi.document_type,
'ExpiryDate': "",
'ExpeditionDate': cpi.document_expedition_date,
}
stay['TimeInterval'] = {}
stay['TimeInterval']['Id'] = {}
stay['TimeInterval']['Name'] = {}
stay['TimeInterval']['Minutes'] = {}
stay['Adults'] = reserva.reservation_id.adults
stay['ReservationCode'] = {}
stay['Total'] = reserva.reservation_id.price_total
stay['Paid'] = stay['Total'] - reserva.reservation_id.folio_pending_amount
stay['Outstanding'] = {}
stay['Taxable'] = reserva.reservation_id.price_tax
# Debug Stop -------------------
# import wdb; wdb.set_trace()
# Debug Stop -------------------
json_response = json.dumps(stay)
return json_response
# return stay
# stay1 = {
#
# "Id": 123,
@@ -156,7 +233,3 @@ class HotelFolio(models.Model):
# "Outstanding": 10.5,
# "Taxable": 10.5,
# }
json_response = json.dumps(json_response)
return json_response

View File

@@ -36,7 +36,7 @@ class HotelFolio(models.Model):
'RoomName': line.room_id.name,
})
else:
_logger.info('ROOMMATIK Not Found Folio search %s', Code)
_logger.warning('ROOMMATIK Not Found Folio search %s', Code)
json_response = {'Error': 'Not Found ' + str(Code)}
json_response = json.dumps(json_response)

View File

@@ -88,9 +88,9 @@ class ResPartner(models.Model):
city_srch = self.env['res.country.state'].search([
('name', 'ilike', customer['Address']['Province'])])
# Create Street2
street_2 = '' + customer['Address']['House']
street_2 += ', ' + customer['Address']['Flat']
street_2 += ', ' + customer['Address']['Number']
street_2 = customer['Address']['House']
street_2 += ' ' + customer['Address']['Flat']
street_2 += ' ' + customer['Address']['Number']
return {
'firstname': customer['FirstName'],
'lastname': customer['LastName1'],

View File

@@ -42,9 +42,16 @@ class RoomMatik(models.Model):
# RoomMatik API Check-in a stay.
# Addition will be ok if the returned stay has ID. (MANDATORY)
_logger.info('ROOMMATIK Check-IN')
apidata = self.env['hotel.folio']
apidata = self.env['hotel.checkin.partner']
return apidata.rm_checkin_partner(stay)
@api.model
def rm_get_stay(self, check_in_code):
# RoomMatik API Gets stay information through check-in code
# (if code is related to a current stay)
# (MANDATORY for check-out kiosk)
apidata = self.env['hotel.checkin.partner']
# Debug Stop -------------------
# import wdb; wdb.set_trace()
# Debug Stop -------------------
return apidata.rm_get_stay(check_in_code)