[FIX] pms_api_rest: remove unnecessary sudo's

This commit is contained in:
miguelpadin
2022-01-27 08:26:58 +00:00
committed by Darío Lodeiros
parent d8db62c4b7
commit 76ee1ba48a
8 changed files with 65 additions and 115 deletions

View File

@@ -34,12 +34,8 @@ class PmsCalendarService(Component):
)
result_lines = []
PmsCalendarInfo = self.env.datamodels["pms.calendar.info"]
for line in (
self.env["pms.reservation.line"]
.sudo()
.search(
domain,
)
for line in self.env["pms.reservation.line"].search(
domain,
):
result_lines.append(
PmsCalendarInfo(

View File

@@ -31,16 +31,12 @@ class PmsFolioService(Component):
result_folios = []
reservations_result = (
self.env["pms.reservation"].sudo().search(domain).mapped("folio_id").ids
self.env["pms.reservation"].search(domain).mapped("folio_id").ids
)
PmsFolioInfo = self.env.datamodels["pms.folio.info"]
for folio in (
self.env["pms.folio"]
.sudo()
.search(
[("id", "in", reservations_result)],
)
for folio in self.env["pms.folio"].search(
[("id", "in", reservations_result)],
):
reservations = []
for reservation in folio.reservation_ids:
@@ -127,7 +123,7 @@ class PmsFolioService(Component):
auth="jwt_api_pms",
)
def get_folio_payments(self, folio_id):
folio = self.env["pms.folio"].sudo().search([("id", "=", folio_id)])
folio = self.env["pms.folio"].search([("id", "=", folio_id)])
payments = []
PmsPaymentInfo = self.env.datamodels["pms.payment.info"]
if not folio:
@@ -175,20 +171,16 @@ class PmsFolioService(Component):
auth="jwt_api_pms",
)
def create_reservation(self, pms_reservation_info):
reservation = (
self.env["pms.reservation"]
.sudo()
.create(
{
"partner_name": pms_reservation_info.partner,
"pms_property_id": pms_reservation_info.property,
"room_type_id": pms_reservation_info.roomTypeId,
"pricelist_id": pms_reservation_info.pricelistId,
"checkin": pms_reservation_info.checkin,
"checkout": pms_reservation_info.checkout,
"board_service_room_id": pms_reservation_info.boardServiceId,
"channel_type_id": pms_reservation_info.channelTypeId,
}
)
reservation = self.env["pms.reservation"].create(
{
"partner_name": pms_reservation_info.partner,
"pms_property_id": pms_reservation_info.property,
"room_type_id": pms_reservation_info.roomTypeId,
"pricelist_id": pms_reservation_info.pricelistId,
"checkin": pms_reservation_info.checkin,
"checkout": pms_reservation_info.checkout,
"board_service_room_id": pms_reservation_info.boardServiceId,
"channel_type_id": pms_reservation_info.channelTypeId,
}
)
return reservation.id

View File

@@ -25,12 +25,8 @@ class PmsPartnerService(Component):
domain = []
result_partners = []
PmsPartnerInfo = self.env.datamodels["pms.partner.info"]
for partner in (
self.env["res.partner"]
.sudo()
.search(
domain,
)
for partner in self.env["res.partner"].search(
domain,
):
result_partners.append(

View File

@@ -36,7 +36,7 @@ class PmsPricelistService(Component):
)
PmsPricelistInfo = self.env.datamodels["pms.pricelist.info"]
result_pricelists = []
for pricelist in self.env["product.pricelist"].sudo().search(domain):
for pricelist in self.env["product.pricelist"].search(domain):
result_pricelists.append(
PmsPricelistInfo(
id=pricelist.id,
@@ -60,66 +60,52 @@ class PmsPricelistService(Component):
)
def get_pricelists_items(self, pricelist_id, pricelist_item_search_param):
result = []
record_pricelist_id = (
self.env["product.pricelist"].sudo().search([("id", "=", pricelist_id)])
record_pricelist_id = self.env["product.pricelist"].search(
[("id", "=", pricelist_id)]
)
if not record_pricelist_id:
raise MissingError
PmsPricelistItemInfo = self.env.datamodels["pms.pricelist.item.info"]
rooms = (
self.env["pms.room"]
.sudo()
.search(
[("pms_property_id", "=", pricelist_item_search_param.pms_property_id)]
)
rooms = self.env["pms.room"].search(
[("pms_property_id", "=", pricelist_item_search_param.pms_property_id)]
)
for room_type in (
self.env["pms.room.type"]
.sudo()
.search([("id", "in", rooms.mapped("room_type_id").ids)])
for room_type in self.env["pms.room.type"].search(
[("id", "in", rooms.mapped("room_type_id").ids)]
):
for item in (
self.env["product.pricelist.item"]
.sudo()
.search(
for item in self.env["product.pricelist.item"].search(
[
("pricelist_id", "=", pricelist_id),
("applied_on", "=", "0_product_variant"),
("product_id", "=", room_type.product_id.id),
(
"date_start_consumption",
">=",
pricelist_item_search_param.date_from,
),
(
"date_end_consumption",
"<=",
pricelist_item_search_param.date_to,
),
]
):
rule = self.env["pms.availability.plan.rule"].search(
[
("pricelist_id", "=", pricelist_id),
("applied_on", "=", "0_product_variant"),
("product_id", "=", room_type.product_id.id),
(
"date_start_consumption",
">=",
pricelist_item_search_param.date_from,
"availability_plan_id",
"=",
record_pricelist_id.availability_plan_id.id,
),
("date", "=", item.date_start_consumption),
("date", "=", item.date_end_consumption),
("room_type_id", "=", room_type.id),
(
"date_end_consumption",
"<=",
pricelist_item_search_param.date_to,
"pms_property_id",
"=",
pricelist_item_search_param.pms_property_id,
),
]
)
):
rule = (
self.env["pms.availability.plan.rule"]
.sudo()
.search(
[
(
"availability_plan_id",
"=",
record_pricelist_id.availability_plan_id.id,
),
("date", "=", item.date_start_consumption),
("date", "=", item.date_end_consumption),
("room_type_id", "=", room_type.id),
(
"pms_property_id",
"=",
pricelist_item_search_param.pms_property_id,
),
]
)
)
rule.ensure_one()
result.append(
PmsPricelistItemInfo(

View File

@@ -30,12 +30,8 @@ class PmsPropertyService(Component):
domain.append(("id", "=", property_search_param.id))
result_properties = []
PmsPropertyInfo = self.env.datamodels["pms.property.info"]
for prop in (
self.env["pms.property"]
.sudo()
.search(
domain,
)
for prop in self.env["pms.property"].search(
domain,
):
result_properties.append(
PmsPropertyInfo(
@@ -59,9 +55,7 @@ class PmsPropertyService(Component):
auth="jwt_api_pms",
)
def get_property(self, property_id):
pms_property = (
self.env["pms.property"].sudo().search([("id", "=", property_id)])
)
pms_property = self.env["pms.property"].search([("id", "=", property_id)])
res = []
PmsPropertyInfo = self.env.datamodels["pms.property.info"]
if not pms_property:
@@ -89,17 +83,15 @@ class PmsPropertyService(Component):
)
def get_method_payments_property(self, property_id):
pms_property = (
self.env["pms.property"].sudo().search([("id", "=", property_id)])
)
pms_property = self.env["pms.property"].search([("id", "=", property_id)])
PmsAccountJournalInfo = self.env.datamodels["pms.account.journal.info"]
res = []
if not pms_property:
pass
else:
for method in pms_property._get_payment_methods(automatic_included=True):
payment_method = (
self.env["account.journal"].sudo().search([("id", "=", method.id)])
payment_method = self.env["account.journal"].search(
[("id", "=", method.id)]
)
res.append(
PmsAccountJournalInfo(

View File

@@ -24,9 +24,7 @@ class PmsReservationService(Component):
auth="jwt_api_pms",
)
def get_reservation(self, reservation_id):
reservation = (
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
)
reservation = self.env["pms.reservation"].search([("id", "=", reservation_id)])
res = []
PmsReservationInfo = self.env.datamodels["pms.reservation.info"]
if not reservation:
@@ -181,9 +179,7 @@ class PmsReservationService(Component):
auth="jwt_api_pms",
)
def get_checkin_partners(self, reservation_id):
reservation = (
self.env["pms.reservation"].sudo().search([("id", "=", reservation_id)])
)
reservation = self.env["pms.reservation"].search([("id", "=", reservation_id)])
checkin_partners = []
PmsCheckinPartnerInfo = self.env.datamodels["pms.checkin.partner.info"]
if not reservation:

View File

@@ -33,12 +33,8 @@ class PmsRoomService(Component):
result_rooms = []
PmsRoomInfo = self.env.datamodels["pms.room.info"]
for room in (
self.env["pms.room"]
.sudo()
.search(
domain,
)
for room in self.env["pms.room"].search(
domain,
):
result_rooms.append(

View File

@@ -30,12 +30,8 @@ class PmsRoomTypeService(Component):
domain.append(("id", "=", room_type_search_param.id))
result_rooms = []
PmsRoomTypeInfo = self.env.datamodels["pms.room.type.info"]
for room in (
self.env["pms.room.type"]
.sudo()
.search(
domain,
)
for room in self.env["pms.room.type"].search(
domain,
):
result_rooms.append(