mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]pms_api_rest: PMS API Client conexion data
This commit is contained in:
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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],
|
||||
)
|
||||
|
||||
@@ -102,6 +102,16 @@
|
||||
options="{'no_create': True}"
|
||||
/>
|
||||
<field name="pms_api_payment_identifier" />
|
||||
<field
|
||||
name="main_avail_plan_id"
|
||||
string="Main Availability Plan"
|
||||
/>
|
||||
<field name="main_pricelist_id" string="Main Pricelist" />
|
||||
<field
|
||||
name="excluded_room_type_ids"
|
||||
widget="many2many_tags"
|
||||
string="Excluded Room Types"
|
||||
/>
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
|
||||
@@ -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'))]"
|
||||
/>
|
||||
</group>
|
||||
<group string="Clien API configuration">
|
||||
<field
|
||||
name="pms_api_client"
|
||||
string="PMS API Client"
|
||||
help="This user is used to PMS API's client (channel managers, precheckin apps, booking engines, etc.)"
|
||||
/>
|
||||
<field
|
||||
name="url_endpoint_prices"
|
||||
string="Prices Endpoint"
|
||||
help="URL endpoint to get prices"
|
||||
attrs="{'invisible': [('pms_api_client', '=', False)]}"
|
||||
/>
|
||||
<field
|
||||
name="url_endpoint_availability"
|
||||
string="Availability Endpoint"
|
||||
help="URL endpoint to get availability"
|
||||
attrs="{'invisible': [('pms_api_client', '=', False)]}"
|
||||
/>
|
||||
<field
|
||||
name="url_endpoint_rules"
|
||||
string="Avail Rules Endpoint"
|
||||
help="URL endpoint to get reservations"
|
||||
attrs="{'invisible': [('pms_api_client', '=', False)]}"
|
||||
/>
|
||||
<field
|
||||
name="external_public_token"
|
||||
string="Public Token"
|
||||
help="URL endpoint to get rules"
|
||||
attrs="{'invisible': [('pms_api_client', '=', False)]}"
|
||||
/>
|
||||
</group>
|
||||
</group>
|
||||
</xpath>
|
||||
|
||||
Reference in New Issue
Block a user