From 49127a9f415ac9a123cd0804ede3d01b355d8723 Mon Sep 17 00:00:00 2001 From: Jose Luis Date: Tue, 9 Apr 2019 11:29:21 +0200 Subject: [PATCH] [ADD] Multiple commit --- hotel_roommatik/__manifest__.py | 1 + hotel_roommatik/models/__init__.py | 2 + .../models/inherited_hotel_checkin_partner.py | 78 ++++++++++--------- .../models/inherited_hotel_folio.py | 14 ++-- .../models/inherited_hotel_reservation.py | 23 ++++++ .../models/inherited_hotel_room_type.py | 49 ++++++++++++ .../models/inherited_res_partner.py | 5 +- hotel_roommatik/models/roommatik.py | 19 ++++- .../views/inherit_hotel_reservation.xml | 17 ++++ 9 files changed, 162 insertions(+), 46 deletions(-) create mode 100644 hotel_roommatik/models/inherited_hotel_reservation.py create mode 100644 hotel_roommatik/models/inherited_hotel_room_type.py create mode 100644 hotel_roommatik/views/inherit_hotel_reservation.xml diff --git a/hotel_roommatik/__manifest__.py b/hotel_roommatik/__manifest__.py index a26f5833b..de79f8b56 100755 --- a/hotel_roommatik/__manifest__.py +++ b/hotel_roommatik/__manifest__.py @@ -21,6 +21,7 @@ 'partner_contact_birthdate' ], 'data': [ + 'views/inherit_hotel_reservation.xml', ], 'demo': [ ], diff --git a/hotel_roommatik/models/__init__.py b/hotel_roommatik/models/__init__.py index 9352d8efe..9b5209f6d 100755 --- a/hotel_roommatik/models/__init__.py +++ b/hotel_roommatik/models/__init__.py @@ -1,4 +1,6 @@ from . import inherited_hotel_folio from . import inherited_hotel_checkin_partner from . import inherited_res_partner +from . import inherited_hotel_room_type from . import roommatik +from . import inherited_hotel_reservation diff --git a/hotel_roommatik/models/inherited_hotel_checkin_partner.py b/hotel_roommatik/models/inherited_hotel_checkin_partner.py index 47fcb2cec..7243fa943 100644 --- a/hotel_roommatik/models/inherited_hotel_checkin_partner.py +++ b/hotel_roommatik/models/inherited_hotel_checkin_partner.py @@ -1,4 +1,4 @@ -# Copyright 2018 Jose Luis Algara (Alda hotels) +# Copyright 2019 Jose Luis Algara (Alda hotels) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import json @@ -12,11 +12,12 @@ class HotelFolio(models.Model): @api.model def rm_checkin_partner(self, stay): - # CHECK-IN _logger = logging.getLogger(__name__) + # CHECK-IN 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.', @@ -61,6 +62,9 @@ class HotelFolio(models.Model): stay['Id'] = record.id json_response = stay except: + # Debug Stop ------------------- + import wdb; wdb.set_trace() + # Debug Stop ------------------- json_response = {'Estate': 'Error not create Checkin'} _logger.error('ROOMMATIK writing %s in reservation: %s).', checkin_partner_val['document_number'], @@ -77,42 +81,42 @@ class HotelFolio(models.Model): @api.model def rm_get_stay(self, code): + # BUSQUEDA POR LOCALIZADOR 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') - stay['Customers'] = [] - for idx, cpi in enumerate(reserva.reservation_id.checkin_partner_ids): - stay['Customers'].append({'Customer': {}}) - stay['Customers'][idx]['Customer'] = self.env[ - 'res.partner'].rm_get_a_customer(cpi.partner_id.id) - 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 + if any(reserva): + stay = {'Code': reserva.reservation_id.localizator} + 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') + stay['Customers'] = [] + for idx, cpi in enumerate(reserva.reservation_id.checkin_partner_ids): + stay['Customers'].append({'Customer': {}}) + stay['Customers'][idx]['Customer'] = self.env[ + 'res.partner'].rm_get_a_customer(cpi.partner_id.id) + 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 + + else: + stay = {'Code': ""} json_response = json.dumps(stay) - return json_response - - # Debug Stop ------------------- - #import wdb; wdb.set_trace() - # Debug Stop ------------------- diff --git a/hotel_roommatik/models/inherited_hotel_folio.py b/hotel_roommatik/models/inherited_hotel_folio.py index 490bc323a..4d2cdabdd 100755 --- a/hotel_roommatik/models/inherited_hotel_folio.py +++ b/hotel_roommatik/models/inherited_hotel_folio.py @@ -1,4 +1,4 @@ -# Copyright 2018 Jose Luis Algara (Alda hotels) +# Copyright 2019 Jose Luis Algara (Alda hotels) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import json @@ -25,19 +25,21 @@ class HotelFolio(models.Model): 'Deposit': folio_res.amount_total, } for i, line in enumerate(folio_lin): + total_chekins = folio_lin.checkin_partner_pending_count json_response.setdefault('Rooms', [i]).append({ 'Id': line.id, 'Adults': line.adults, - # Need a function (Clean and no Checkin) - 'IsAvailable': 0, + 'IsAvailable': True if total_chekins > 0 else False, + # IsAvailable “false” Rooms not need check-in 'Price': line.price_total, 'RoomTypeId': line.room_type_id.id, 'RoomTypeName': line.room_type_id.name, 'RoomName': line.room_id.name, }) + # Debug Stop ------------------- + # import wdb; wdb.set_trace() + # Debug Stop ------------------- else: _logger.warning('ROOMMATIK Not Found Folio search %s', Code) json_response = {'Error': 'Not Found ' + str(Code)} - json_response = json.dumps(json_response) - - return json_response + return json.dumps(json_response) diff --git a/hotel_roommatik/models/inherited_hotel_reservation.py b/hotel_roommatik/models/inherited_hotel_reservation.py new file mode 100644 index 000000000..856e12ec8 --- /dev/null +++ b/hotel_roommatik/models/inherited_hotel_reservation.py @@ -0,0 +1,23 @@ +# Copyright 2019 Jose Luis Algara (Alda hotels) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models, fields +from datetime import datetime, timedelta +import logging +import random + +class HotelReservation(models.Model): + + _inherit = 'hotel.reservation' + + def _compute_localizator(self): + random.seed(self.id) + number = str(random.random()) + leters = "ABCEFGHJKL" + locali = str(self.folio_id.id) + leters[int(number[11])] + locali += number[2:10] + leters[int(number[12])] + locali += str(self.id) + self.localizator = locali + return + + localizator = fields.Char('Localizator', compute='_compute_localizator') diff --git a/hotel_roommatik/models/inherited_hotel_room_type.py b/hotel_roommatik/models/inherited_hotel_room_type.py new file mode 100644 index 000000000..e281243c3 --- /dev/null +++ b/hotel_roommatik/models/inherited_hotel_room_type.py @@ -0,0 +1,49 @@ +# Copyright 2019 Jose Luis Algara (Alda hotels) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models +from datetime import datetime, timedelta +import logging + + +class HotelRoomType(models.Model): + + _inherit = "hotel.room.type" + + @api.model + def rm_get_all_room_type_rates(self): + # types = self.env['hotel.room.type'].search(['active', '=', True]) + types = self.env['hotel.room.type'].search([]) + dfrom = datetime.now() + dto = (dfrom + timedelta(hours=24)) + + room_type_rates = [] + for i, type in enumerate(types): + frees = self.check_availability_room_type(dfrom, dto, type.id) + if any(frees): + room_type_rates.append({ + "RoomType": { + "Id": type.id, + "Name": type.product_id.name, + "GuestNumber": type.get_capacity() + }, + "TimeInterval": { + "Id": "1", + "Name": "1 day", + "Minutes": "1440" + }, + "Price": "", + "IsAvailable": "", + }) + + return room_type_rates + + @api.model + def rm_get_prices(self, start_date, time_interval, number_intervals, room_type, guest_number): + # TODO: FALTA POR COMPLETO + _logger = logging.getLogger(__name__) + _logger.info('ROOMMATIK get prices date %s Room: %s for %s Guests', + start_date, + room_type, + guest_number) + return {'start_date': start_date, 'time_interval': time_interval, 'number_intervals': number_intervals} diff --git a/hotel_roommatik/models/inherited_res_partner.py b/hotel_roommatik/models/inherited_res_partner.py index 673d5518b..7a0354b3b 100755 --- a/hotel_roommatik/models/inherited_res_partner.py +++ b/hotel_roommatik/models/inherited_res_partner.py @@ -1,4 +1,4 @@ -# Copyright 2018 Jose Luis Algara (Alda hotels) +# Copyright 2019 Jose Luis Algara (Alda hotels) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import json @@ -59,7 +59,7 @@ class ResPartner(models.Model): street_2 = customer['Address']['House'] street_2 += ' ' + customer['Address']['Flat'] street_2 += ' ' + customer['Address']['Number'] - return { + metadata = { 'firstname': customer['FirstName'], 'lastname': customer['LastName1'], 'lastname2': customer['LastName2'], @@ -80,6 +80,7 @@ class ResPartner(models.Model): 'IdentityDocument']['ExpeditionDate'], "%d%m%Y").date(), } + return {k: v for k, v in metadata.items() if v is not ""} def rm_get_a_customer(self, customer): # Prepare a Customer for RoomMatik diff --git a/hotel_roommatik/models/roommatik.py b/hotel_roommatik/models/roommatik.py index d16585a9d..3b0c0f5cb 100755 --- a/hotel_roommatik/models/roommatik.py +++ b/hotel_roommatik/models/roommatik.py @@ -51,7 +51,24 @@ class RoomMatik(models.Model): # (if code is related to a current stay) # (MANDATORY for check-out kiosk) apidata = self.env['hotel.checkin.partner'] + return apidata.rm_get_stay(check_in_code) + + @api.model + def rm_get_all_room_type_rates(self): + # Gets the current room rates and availability. (MANDATORY) + # return ArrayOfRoomTypeRate + _logger.info('ROOMMATIK Get Rooms and Rates') + apidata = self.env['hotel.room.type'] + return apidata.rm_get_all_room_type_rates() + + @api.model + def rm_get_prices(self, start_date, time_interval, number_intervals, room_type, guest_number): + # Gets some prices related to different dates of the same stay. + # return ArrayOfDecimal + _logger.info('ROOMMATIK Get Prices') + apidata = self.env['hotel.room.type'] + return apidata.rm_get_prices(start_date, time_interval, number_intervals, room_type, guest_number) + # Debug Stop ------------------- # import wdb; wdb.set_trace() # Debug Stop ------------------- - return apidata.rm_get_stay(check_in_code) diff --git a/hotel_roommatik/views/inherit_hotel_reservation.xml b/hotel_roommatik/views/inherit_hotel_reservation.xml new file mode 100644 index 000000000..bbfd71953 --- /dev/null +++ b/hotel_roommatik/views/inherit_hotel_reservation.xml @@ -0,0 +1,17 @@ + + + + + + + roommatik.reservation_form + hotel.reservation + + + + + + + + +