Skip to content

Commit

Permalink
[FIX] pms_api_rest: remove unnecessary sudo's
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Jan 27, 2022
1 parent 9629e8d commit b1359a6
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 115 deletions.
8 changes: 2 additions & 6 deletions pms_api_rest/services/pms_calendar_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ def get_calendar(self, calendar_search_param):
domain.append(("date", "<=", calendar_search_param.date_to))
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(
Expand Down
38 changes: 15 additions & 23 deletions pms_api_rest/services/pms_folio_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ def get_folios(self, folio_search_param):
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:
Expand Down Expand Up @@ -127,7 +123,7 @@ def get_folios(self, folio_search_param):
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:
Expand Down Expand Up @@ -175,20 +171,16 @@ def get_folio_payments(self, folio_id):
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
8 changes: 2 additions & 6 deletions pms_api_rest/services/pms_partner_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,8 @@ def get_partners(self):
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(
Expand Down
82 changes: 34 additions & 48 deletions pms_api_rest/services/pms_pricelist_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_pricelists(self, pricelist_info_search_param, **args):
)
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,
Expand All @@ -60,66 +60,52 @@ def get_pricelists(self, pricelist_info_search_param, **args):
)
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(
Expand Down
20 changes: 6 additions & 14 deletions pms_api_rest/services/pms_property_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ def get_properties(self, property_search_param):
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(
Expand All @@ -59,9 +55,7 @@ def get_properties(self, property_search_param):
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:
Expand Down Expand Up @@ -89,17 +83,15 @@ def get_property(self, property_id):
)
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(
Expand Down
8 changes: 2 additions & 6 deletions pms_api_rest/services/pms_reservation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -181,9 +179,7 @@ def update_reservation(self, reservation_id, reservation_lines_changes):
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:
Expand Down
8 changes: 2 additions & 6 deletions pms_api_rest/services/pms_room_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,8 @@ def get_rooms(self, room_search_param):

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(
Expand Down
8 changes: 2 additions & 6 deletions pms_api_rest/services/pms_room_type_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ def get_room_types(self, room_type_search_param):
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(
Expand Down

0 comments on commit b1359a6

Please sign in to comment.