From 1fedb1bff210ecd1ccc9b45da5f01b92ad693650 Mon Sep 17 00:00:00 2001 From: miguelpadin Date: Tue, 28 Dec 2021 23:30:19 +0100 Subject: [PATCH] [IMP] pms-api-rest: filter folios by date --- pms_api_rest/datamodels/pms_folio_search_param.py | 4 ++-- pms_api_rest/services/folio_services.py | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pms_api_rest/datamodels/pms_folio_search_param.py b/pms_api_rest/datamodels/pms_folio_search_param.py index 027e65660b7..5a37c60034d 100644 --- a/pms_api_rest/datamodels/pms_folio_search_param.py +++ b/pms_api_rest/datamodels/pms_folio_search_param.py @@ -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) diff --git a/pms_api_rest/services/folio_services.py b/pms_api_rest/services/folio_services.py index 22d360eddcb..f202d1f813e 100644 --- a/pms_api_rest/services/folio_services.py +++ b/pms_api_rest/services/folio_services.py @@ -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 = []