Skip to content

Commit

Permalink
[IMP] pms_api_rest: add filters in get_folios
Browse files Browse the repository at this point in the history
  • Loading branch information
saralb9 authored and miguelpadin committed May 4, 2022
1 parent 87751bb commit a2bb2da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions pms_api_rest/datamodels/pms_folio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class PmsFolioSearchParam(Datamodel):
pms_property_id = fields.Integer(required=True, allow_none=True)
date_from = fields.String(required=False, allow_none=True)
date_to = fields.String(required=False, allow_none=True)
filter = fields.String(required=False, allow_none=True)


class PmsFolioInfo(Datamodel):
Expand Down
34 changes: 30 additions & 4 deletions pms_api_rest/services/pms_folio_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from datetime import datetime

from odoo.osv import expression

from odoo.addons.base_rest import restapi
from odoo.addons.base_rest_datamodel.restapi import Datamodel
from odoo.addons.component.core import Component
Expand All @@ -25,10 +27,33 @@ class PmsFolioService(Component):
auth="jwt_api_pms",
)
def get_folios(self, folio_search_param):
domain = list()
domain.append(("checkin", ">=", folio_search_param.date_from))
domain.append(("checkout", "<", folio_search_param.date_to))
domain.append(("pms_property_id", "=", folio_search_param.pms_property_id))
domain_fields = list()

domain_fields.append(
("pms_property_id", "=", folio_search_param.pms_property_id)
)

if folio_search_param.date_to and folio_search_param.date_from:
domain_fields.append(("checkin", ">=", folio_search_param.date_from))
domain_fields.append(("checkout", "<", folio_search_param.date_to))

domain_filter = list()
if folio_search_param.filter:
for search in folio_search_param.filter.split(" "):
subdomains = [
[("name", "ilike", search)],
[("folio_id.name", "ilike", search)],
[("partner_name", "ilike", search)],
[("partner_id.firstname", "ilike", search)],
[("partner_id.lastname", "ilike", search)],
[("partner_id.id_numbers.name", "ilike", search)],
]
domain_filter.append(expression.OR(subdomains))
domain = []
if domain_filter:
domain = expression.AND([domain_fields, domain_filter[0]])
else:
domain = domain_fields
result_folios = []

reservations_result = (
Expand All @@ -54,6 +79,7 @@ def get_folios(self, folio_search_param):
reservations.append(
{
"id": reservation.id,
"name": reservation.name,
"checkin": datetime.combine(
reservation.checkin, datetime.min.time()
).isoformat(),
Expand Down

0 comments on commit a2bb2da

Please sign in to comment.