From a33d9c26f1d6d6cd7ef67b678bfba3e07ca60895 Mon Sep 17 00:00:00 2001 From: braisab Date: Fri, 24 May 2024 17:39:03 +0200 Subject: [PATCH] [IMP]pms_api_rest: added signature field in checkin partner datamodel & addres and other fields in property datamodel --- .../datamodels/pms_checkin_partner.py | 1 + pms_api_rest/datamodels/pms_property.py | 8 +++ pms_api_rest/services/pms_property_service.py | 57 ++++++++++++++++++- .../services/pms_reservation_service.py | 17 ++++++ 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/pms_api_rest/datamodels/pms_checkin_partner.py b/pms_api_rest/datamodels/pms_checkin_partner.py index 2b5a558bb..8f334dfaa 100644 --- a/pms_api_rest/datamodels/pms_checkin_partner.py +++ b/pms_api_rest/datamodels/pms_checkin_partner.py @@ -31,3 +31,4 @@ class PmsCheckinPartnerInfo(Datamodel): checkinPartnerState = fields.String(required=False, allow_none=True) actionOnBoard = fields.Boolean(required=False, allow_none=True) originInputData = fields.String(required=False, allow_none=True) + signature = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_property.py b/pms_api_rest/datamodels/pms_property.py index f723b3c02..fb1c4e573 100644 --- a/pms_api_rest/datamodels/pms_property.py +++ b/pms_api_rest/datamodels/pms_property.py @@ -31,3 +31,11 @@ class PmsPropertyInfo(Datamodel): simpleFutureColor = fields.String(required=False, allow_none=True) language = fields.String(required=True, allow_none=False) hotelImageUrl = fields.String(required=False, allow_none=True) + street = fields.String(required=False, allow_none=True) + street2 = fields.String(required=False, allow_none=True) + zip = fields.String(required=False, allow_none=True) + city = fields.String(required=False, allow_none=True) + stateName = fields.Integer(required=False, allow_none=True) + ineCategory = fields.String(required=False, allow_none=True) + cardexWarning = fields.String(required=False, allow_none=True) + companyPrivacyPolicy = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/services/pms_property_service.py b/pms_api_rest/services/pms_property_service.py index fa0e770f8..f8ba1489f 100644 --- a/pms_api_rest/services/pms_property_service.py +++ b/pms_api_rest/services/pms_property_service.py @@ -1,4 +1,5 @@ import base64 +import re from odoo import fields @@ -35,17 +36,30 @@ class PmsPropertyService(Component): domain, ): state_name = False + ine_category = False + privacy_policy = False + tokens_to_replace = re.compile("<.*?>") + if prop.company_id.privacy_policy: + privacy_policy = re.sub( + tokens_to_replace, "", prop.company_id.privacy_policy + ) if prop.state_id: state_name = ( self.env["res.country.state"] .search([("id", "=", prop.state_id.id)]) .name ) + if prop.ine_category_id: + ine_category = ( + prop.ine_category_id.category + + " (" + + prop.ine_category_id.type + + ")" + ) result_properties.append( PmsPropertyInfo( id=prop.id, name=prop.name, - stateName=state_name if state_name else None, defaultPricelistId=prop.default_pricelist_id.id, colorOptionConfig=prop.color_option_config, preReservationColor=prop.pre_reservation_color, @@ -65,6 +79,16 @@ class PmsPropertyService(Component): hotelImageUrl=url_image_pms_api_rest( "pms.property", prop.id, "hotel_image_pms_api_rest" ), + street=prop.street if prop.street else None, + street2=prop.street2 if prop.street2 else None, + zip=prop.zip if prop.zip else None, + city=prop.city if prop.city else None, + stateName=state_name if state_name else None, + ineCategory=ine_category if ine_category else None, + cardexWarning=prop.cardex_warning if prop.cardex_warning else None, + companyPrivacyPolicy=privacy_policy + if prop.company_id.privacy_policy + else None, ) ) return result_properties @@ -88,6 +112,25 @@ class PmsPropertyService(Component): if not pms_property: pass else: + state_name = False + ine_category = False + if pms_property.state_id: + state_name = ( + self.env["res.country.state"] + .search([("id", "=", pms_property.state_id.id)]) + .name + ) + if pms_property.ine_category_id: + ine_category = ( + pms_property.ine_category_id.category + + " (" + + pms_property.ine_category_id.type + + ")" + ) + tokens_to_replace = re.compile("<.*?>") + privacy_policy = re.sub( + tokens_to_replace, "", pms_property.company_id.privacy_policy + ) res = PmsPropertyInfo( id=pms_property.id, name=pms_property.name, @@ -104,6 +147,18 @@ class PmsPropertyService(Component): toAssignReservationColor=pms_property.to_assign_reservation_color, pendingPaymentReservationColor=pms_property.pending_payment_reservation_color, language=pms_property.lang, + street=pms_property.street if pms_property.street else None, + street2=pms_property.street2 if pms_property.street2 else None, + zip=pms_property.zip if pms_property.zip else None, + city=pms_property.city if pms_property.city else None, + stateName=state_name if state_name else None, + ineCategory=ine_category if ine_category else None, + cardexWarning=pms_property.cardex_warning + if pms_property.cardex_warning + else None, + companyPrivacyPolicy=privacy_policy + if pms_property.company_id.privacy_policy + else None, ) return res diff --git a/pms_api_rest/services/pms_reservation_service.py b/pms_api_rest/services/pms_reservation_service.py index 4bc7ee519..9eb54b192 100644 --- a/pms_api_rest/services/pms_reservation_service.py +++ b/pms_api_rest/services/pms_reservation_service.py @@ -1,4 +1,6 @@ import base64 +import os +import tempfile from datetime import datetime, timedelta from odoo import _, fields @@ -625,6 +627,9 @@ class PmsReservationService(Component): if checkin_partner.residence_country_id else None, checkinPartnerState=checkin_partner.state, + signature=checkin_partner.signature + if checkin_partner.signature + else None, ) ) return checkin_partners @@ -926,6 +931,18 @@ class PmsReservationService(Component): vals.update({"birthdate_date": birthdate}) else: vals.update({"birthdate_date": False}) + if pms_checkin_partner_info.signature: + with tempfile.NamedTemporaryFile(delete=False) as f: + f.write(base64.b64decode(pms_checkin_partner_info.signature)) + temp_path = f.name + + with open(temp_path, "rb") as f: + signature_image = f.read() + os.unlink(temp_path) + + vals.update({"signature": base64.b64encode(signature_image)}) + else: + vals.update({"signature": False}) return vals @restapi.method(