[ADD]pms_api_rest: PMS API Client conexion data

This commit is contained in:
Darío Lodeiros
2024-02-26 09:51:14 +01:00
parent 1980224512
commit 344f53d6a3
6 changed files with 121 additions and 12 deletions

View File

@@ -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",
)

View File

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

View File

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