mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: added post/patch for pricelist_items and avail_plan_rules
This commit is contained in:
@@ -23,3 +23,4 @@ class PmsAvailabilityPlanRuleInfo(Datamodel):
|
|||||||
roomTypeId = fields.Integer(required=False, allow_none=True)
|
roomTypeId = fields.Integer(required=False, allow_none=True)
|
||||||
date = fields.String(required=False, allow_none=True)
|
date = fields.String(required=False, allow_none=True)
|
||||||
quota = fields.Integer(required=False, allow_none=True)
|
quota = fields.Integer(required=False, allow_none=True)
|
||||||
|
pmsPropertyId = fields.Integer(required=False, allow_none=True)
|
||||||
|
|||||||
@@ -16,3 +16,4 @@ class PmsPricelistItemInfo(Datamodel):
|
|||||||
price = fields.Float(required=False, allow_none=True)
|
price = fields.Float(required=False, allow_none=True)
|
||||||
roomTypeId = fields.Integer(required=False, allow_none=True)
|
roomTypeId = fields.Integer(required=False, allow_none=True)
|
||||||
date = fields.String(required=False, allow_none=True)
|
date = fields.String(required=False, allow_none=True)
|
||||||
|
pmsPropertyId = fields.Integer(required=False, allow_none=True)
|
||||||
|
|||||||
@@ -149,3 +149,94 @@ class PmsAvailabilityPlanService(Component):
|
|||||||
result.append(availability_plan_rule_info)
|
result.append(availability_plan_rule_info)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:availability_plan_id>/availability-plan-rule",
|
||||||
|
],
|
||||||
|
"POST",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.availability.plan.rule.info", is_list=False),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def create_availability_plan_rule(
|
||||||
|
self, availability_plan_id, pms_avail_plan_rule_info
|
||||||
|
):
|
||||||
|
day = datetime.strptime(
|
||||||
|
pms_avail_plan_rule_info.date[:10], "%Y-%m-%d"
|
||||||
|
) + timedelta(days=1)
|
||||||
|
vals = {
|
||||||
|
"room_type_id": pms_avail_plan_rule_info.roomTypeId,
|
||||||
|
"date": day,
|
||||||
|
"pms_property_id": pms_avail_plan_rule_info.pmsPropertyId,
|
||||||
|
"availability_plan_id": availability_plan_id,
|
||||||
|
}
|
||||||
|
|
||||||
|
if pms_avail_plan_rule_info.minStay:
|
||||||
|
vals.update({"min_stay": pms_avail_plan_rule_info.minStay})
|
||||||
|
if pms_avail_plan_rule_info.minStayArrival:
|
||||||
|
vals.update({"min_stay_arrival": pms_avail_plan_rule_info.minStayArrival})
|
||||||
|
if pms_avail_plan_rule_info.maxStay:
|
||||||
|
vals.update({"max_stay": pms_avail_plan_rule_info.maxStay})
|
||||||
|
if pms_avail_plan_rule_info.maxStayArrival:
|
||||||
|
vals.update({"max_stay_arrival": pms_avail_plan_rule_info.maxStayArrival})
|
||||||
|
if pms_avail_plan_rule_info.closed:
|
||||||
|
vals.update({"closed": pms_avail_plan_rule_info.closed})
|
||||||
|
if pms_avail_plan_rule_info.closedDeparture:
|
||||||
|
vals.update({"closed_departure": pms_avail_plan_rule_info.closedDeparture})
|
||||||
|
if pms_avail_plan_rule_info.closedArrival:
|
||||||
|
vals.update({"closed_arrival": pms_avail_plan_rule_info.closedArrival})
|
||||||
|
if pms_avail_plan_rule_info.quota:
|
||||||
|
vals.update({"quota": pms_avail_plan_rule_info.quota})
|
||||||
|
avail_plan_rule = self.env["pms.availability.plan.rule"].create(vals)
|
||||||
|
return avail_plan_rule.id
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:availability_plan_id>/availability-plan-rule/",
|
||||||
|
],
|
||||||
|
"PATCH",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.availability.plan.rule.info", is_list=False),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def write_availability_plan_rule(
|
||||||
|
self, availability_plan_id, pms_avail_plan_rule_info
|
||||||
|
):
|
||||||
|
vals = dict()
|
||||||
|
avail_rule = self.env["pms.availability.plan.rule"].search(
|
||||||
|
[
|
||||||
|
("id", "=", pms_avail_plan_rule_info.availabilityRuleId),
|
||||||
|
("availability_plan_id", "=", availability_plan_id),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if avail_rule:
|
||||||
|
if pms_avail_plan_rule_info.minStay:
|
||||||
|
vals.update({"min_stay": pms_avail_plan_rule_info.minStay})
|
||||||
|
if pms_avail_plan_rule_info.minStayArrival:
|
||||||
|
vals.update(
|
||||||
|
{"min_stay_arrival": pms_avail_plan_rule_info.minStayArrival}
|
||||||
|
)
|
||||||
|
if pms_avail_plan_rule_info.maxStay:
|
||||||
|
vals.update({"max_stay": pms_avail_plan_rule_info.maxStay})
|
||||||
|
if pms_avail_plan_rule_info.maxStayArrival:
|
||||||
|
vals.update(
|
||||||
|
{"max_stay_arrival": pms_avail_plan_rule_info.maxStayArrival}
|
||||||
|
)
|
||||||
|
if pms_avail_plan_rule_info.closed:
|
||||||
|
vals.update({"closed": pms_avail_plan_rule_info.closed})
|
||||||
|
if pms_avail_plan_rule_info.closedDeparture:
|
||||||
|
vals.update(
|
||||||
|
{"closed_departure": pms_avail_plan_rule_info.closedDeparture}
|
||||||
|
)
|
||||||
|
if pms_avail_plan_rule_info.closedArrival:
|
||||||
|
vals.update({"closed_arrival": pms_avail_plan_rule_info.closedArrival})
|
||||||
|
if pms_avail_plan_rule_info.quota:
|
||||||
|
vals.update({"quota": pms_avail_plan_rule_info.quota})
|
||||||
|
avail_rule.write(vals)
|
||||||
|
|||||||
@@ -136,3 +136,64 @@ class PmsPricelistService(Component):
|
|||||||
result.append(pricelist_info)
|
result.append(pricelist_info)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:pricelist_id>/pricelist-item",
|
||||||
|
],
|
||||||
|
"POST",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.pricelist.item.info", is_list=False),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def create_pricelist_item(self, pricelist_id, pms_pricelist_item_info):
|
||||||
|
day = datetime.strptime(
|
||||||
|
pms_pricelist_item_info.date[:10], "%Y-%m-%d"
|
||||||
|
) + timedelta(days=1)
|
||||||
|
product_id = (
|
||||||
|
self.env["pms.room.type"]
|
||||||
|
.browse(pms_pricelist_item_info.roomTypeId)
|
||||||
|
.product_id
|
||||||
|
)
|
||||||
|
pricelist_item = self.env["product.pricelist.item"].create(
|
||||||
|
{
|
||||||
|
"applied_on": "0_product_variant",
|
||||||
|
"product_id": product_id.id,
|
||||||
|
"pms_property_ids": [pms_pricelist_item_info.pmsPropertyId],
|
||||||
|
"date_start_consumption": day,
|
||||||
|
"date_end_consumption": day,
|
||||||
|
"compute_price": "fixed",
|
||||||
|
"fixed_price": pms_pricelist_item_info.price,
|
||||||
|
"pricelist_id": pricelist_id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return pricelist_item.id
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:pricelist_id>/pricelist-item",
|
||||||
|
],
|
||||||
|
"PATCH",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
input_param=Datamodel("pms.pricelist.item.info", is_list=False),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def write_pricelist_item(self, pricelist_id, pms_pricelist_item_info):
|
||||||
|
product_pricelist_item = self.env["product.pricelist.item"].search(
|
||||||
|
[
|
||||||
|
("id", "=", pms_pricelist_item_info.pricelistItemId),
|
||||||
|
("pricelist_id", "=", pricelist_id),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if product_pricelist_item and pms_pricelist_item_info.price:
|
||||||
|
product_pricelist_item.write(
|
||||||
|
{
|
||||||
|
"fixed_price": pms_pricelist_item_info.price,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user