Skip to content

Commit

Permalink
[IMP] pms-api-rest: filter folios by date
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelpadin committed Dec 28, 2021
1 parent 6802c2a commit 1fedb1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions pms_api_rest/datamodels/pms_folio_search_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
class PmsFolioSearchParam(Datamodel):
_name = "pms.folio.search.param"

id = fields.Integer(required=False, allow_none=False)
name = fields.String(required=False, allow_none=False)
date_from = fields.String(required=False, allow_none=True)
date_to = fields.String(required=False, allow_none=True)
15 changes: 9 additions & 6 deletions pms_api_rest/services/folio_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,21 @@ class PmsFolioService(Component):
output_param=Datamodel("pms.folio.info", is_list=True),
)
def get_folios(self, folio_search_param):
domain = []
if folio_search_param.name:
domain.append(("name", "like", folio_search_param.name))
if folio_search_param.id:
domain.append(("id", "=", folio_search_param.id))
domain = list()
domain.append(("checkin", ">=", folio_search_param.date_from))
domain.append(("checkout", "<", folio_search_param.date_to))
result_folios = []

reservations_result = (
self.env["pms.reservation"].sudo().search(domain).mapped("folio_id").ids
)

PmsFolioInfo = self.env.datamodels["pms.folio.info"]
for folio in (
self.env["pms.folio"]
.sudo()
.search(
domain,
[("id", "in", reservations_result)],
)
):
reservations = []
Expand Down

0 comments on commit 1fedb1b

Please sign in to comment.