From 344f53d6a322d4e371034687b9cf817c9748a069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Mon, 26 Feb 2024 09:51:14 +0100 Subject: [PATCH] [ADD]pms_api_rest: PMS API Client conexion data --- pms_api_rest/models/ota_property_settings.py | 15 ++++++ pms_api_rest/models/pms_property.py | 51 +++++++++++++++++--- pms_api_rest/models/res_users.py | 17 ++++++- pms_api_rest/services/pms_folio_service.py | 14 ++++-- pms_api_rest/views/pms_property_views.xml | 10 ++++ pms_api_rest/views/res_users_views.xml | 26 ++++++++++ 6 files changed, 121 insertions(+), 12 deletions(-) diff --git a/pms_api_rest/models/ota_property_settings.py b/pms_api_rest/models/ota_property_settings.py index 0298b8bbc..1e79642bd 100644 --- a/pms_api_rest/models/ota_property_settings.py +++ b/pms_api_rest/models/ota_property_settings.py @@ -32,3 +32,18 @@ class OtaPropertySettings(models.Model): The string will be searched within the partnerRequests parameter. """, ) + main_avail_plan_id = fields.Many2one( + string="Main Availability Plan", + help="Main Availability Plan", + comodel_name="pms.availability.plan", + ) + main_pricelist_id = fields.Many2one( + string="Main Pricelist", + help="Main Pricelist", + comodel_name="product.pricelist", + ) + excluded_room_type_ids = fields.Many2many( + string="Excluded Room Types", + help="Excluded Room Types", + comodel_name="pms.room.type", + ) diff --git a/pms_api_rest/models/pms_property.py b/pms_api_rest/models/pms_property.py index ec4df7f74..31afd5e25 100644 --- a/pms_api_rest/models/pms_property.py +++ b/pms_api_rest/models/pms_property.py @@ -114,11 +114,17 @@ class PmsProperty(models.Model): # PUSH API NOTIFICATIONS def get_payload_avail(self, avails, client): self.ensure_one() - endpoint = client.url_endpoint_avail + endpoint = client.url_endpoint_availability pms_property_id = self.id avails_dict = {"pmsPropertyId": pms_property_id, "avails": []} room_type_ids = avails.mapped("room_type_id.id") - plan_avail = client.main_avail_plan_id + property_client_conf = self.env["ota.property.settings"].search( + [ + ("pms_property_id", "=", self.id), + ("agency_id", "=", client.id), + ] + ) + plan_avail = property_client_conf.main_avail_plan_id for room_type_id in room_type_ids: room_type_avails = sorted( avails.filtered(lambda r: r.room_type_id.id == room_type_id), @@ -292,7 +298,13 @@ class PmsProperty(models.Model): date_from + datetime.timedelta(days=x) for x in range((date_to - date_from).days + 1) ] - plan_avail = client.main_avail_plan_id + property_client_conf = self.env["ota.property.settings"].search( + [ + ("pms_property_id", "=", pms_property_id), + ("agency_id", "=", client.id), + ] + ) + plan_avail = property_client_conf.main_avail_plan_id for date in all_dates: avail_record = avail_records.filtered(lambda r: r.date == date) if avail_record: @@ -386,13 +398,23 @@ class PmsProperty(models.Model): } ] """ + property_client_conf = self.env["ota.property.settings"].search( + [ + ("pms_property_id", "=", pms_property_id), + ("agency_id", "=", client.id), + ] + ) rules_records = self.env["pms.availability.plan.rule"].search( [ ("date", ">=", date_from), ("date", "<=", date_to), ("pms_property_id", "=", pms_property_id), ("room_type_id", "=", room_type_id), - ("availability_plan_id", "=", self.main_avail_plan_id.id), + ( + "availability_plan_id", + "=", + property_client_conf.main_avail_plan_id.id, + ), ], order="date", ) @@ -463,8 +485,14 @@ class PmsProperty(models.Model): for x in range((date_to - date_from).days + 1) ] product = self.env["pms.room.type"].browse(room_type_id).product_id + property_client_conf = self.env["ota.property.settings"].search( + [ + ("pms_property_id", "=", pms_property_id), + ("agency_id", "=", client.id), + ] + ) pms_property = self.env["pms.property"].browse(pms_property_id) - pricelist = client.main_pricelist_id + pricelist = property_client_conf.main_pricelist_id product_context = dict( self.env.context, date=datetime.datetime.today().date(), @@ -544,6 +572,12 @@ class PmsProperty(models.Model): clients = client else: clients = self.env["res.users"].search([("pms_api_client", "=", True)]) + property_client_conf = self.env["ota.property.settings"].search( + [ + ("pms_property_id", "in", clients.pms_property_ids.ids), + ("agency_id", "in", clients.ids), + ] + ) _logger.info("PMS API push batch") if isinstance(date_from, str): date_from = datetime.datetime.strptime(date_from, "%Y-%m-%d").date() @@ -571,7 +605,10 @@ class PmsProperty(models.Model): else self.env["pms.room"] .search([("pms_property_id", "=", pms_property_id)]) .mapped("room_type_id") - .filtered(lambda r: r.id not in client.excluded_room_type_ids.ids) + .filtered( + lambda r: r.id + not in property_client_conf.excluded_room_type_ids.ids + ) .ids ) payload = { @@ -580,7 +617,7 @@ class PmsProperty(models.Model): data = [] for room_type_id in room_type_ids: if call_type == "availability": - endpoint = client.url_endpoint_avail + endpoint = client.url_endpoint_availability data.extend( pms_property.generate_availability_json( date_from=date_from, diff --git a/pms_api_rest/models/res_users.py b/pms_api_rest/models/res_users.py index 9c173007b..85e174563 100644 --- a/pms_api_rest/models/res_users.py +++ b/pms_api_rest/models/res_users.py @@ -21,11 +21,26 @@ class ResUsers(models.Model): store=True, readonly=False, ) - pms_api_client = fields.Boolean( string="PMS API Client", help="PMS API Client", ) + url_endpoint_prices = fields.Char( + string="URL Endpoint Prices", + help="URL Endpoint Prices", + ) + url_endpoint_availability = fields.Char( + string="URL Endpoint Availability", + help="URL Endpoint Availability", + ) + url_endpoint_rules = fields.Char( + string="URL Endpoint Rules", + help="URL Endpoint Rules", + ) + external_public_token = fields.Char( + string="External Public Token", + help="External Public Token", + ) def _get_default_avail_rule_fields(self): default_avail_rule_fields = self.env["ir.model.fields"].search( diff --git a/pms_api_rest/services/pms_folio_service.py b/pms_api_rest/services/pms_folio_service.py index 5db13fe9c..fb97dca11 100644 --- a/pms_api_rest/services/pms_folio_service.py +++ b/pms_api_rest/services/pms_folio_service.py @@ -1764,14 +1764,20 @@ class PmsFolioService(Component): It is used to override potential availability changes on the channel made unilaterally, for example, upon entering or canceling a reservation. """ - if not room_type_ids: + api_clients = self.env["res.users"].search( + [ + ("pms_api_client", "=", True), + ("pms_property_ids", "in", pms_property_id), + ] + ) + if not room_type_ids or not api_clients: return False for room_type_id in room_type_ids: - pms_property_id = self.env["pms.property"].browse(pms_property_id) - self.env["pms.property"].neobookings_push_batch( + pms_property = self.env["pms.property"].browse(pms_property_id) + self.env["pms.property"].pms_api_push_batch( call_type="availability", # 'availability', 'prices', 'restrictions' date_from=date_from.strftime("%Y-%m-%d"), # 'YYYY-MM-DD' date_to=date_to.strftime("%Y-%m-%d"), # 'YYYY-MM-DD' filter_room_type_id=room_type_id, - pms_property_codes=[pms_property_id.pms_property_code], + pms_property_codes=[pms_property.pms_property_code], ) diff --git a/pms_api_rest/views/pms_property_views.xml b/pms_api_rest/views/pms_property_views.xml index 03a52368f..e0b528615 100644 --- a/pms_api_rest/views/pms_property_views.xml +++ b/pms_api_rest/views/pms_property_views.xml @@ -102,6 +102,16 @@ options="{'no_create': True}" /> + + + diff --git a/pms_api_rest/views/res_users_views.xml b/pms_api_rest/views/res_users_views.xml index 81176b78b..c639349d5 100644 --- a/pms_api_rest/views/res_users_views.xml +++ b/pms_api_rest/views/res_users_views.xml @@ -17,11 +17,37 @@ options="{'no_create': True}" domain="['&',('model_id', '=', 'pms.availability.plan.rule'), ('name', 'in', ('min_stay', 'max_stay', 'quota', 'max_stay_arrival', 'closed_arrival', 'closed', 'closed_departure', 'min_stay_arrival', 'max_avail'))]" /> + + + + + +