From bcc38c2184b7c57044a80953b1d7e57c4dc458b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Mon, 14 Aug 2023 09:51:35 +0200 Subject: [PATCH] [ADD]pms_api_rest: add transaction in folio POST/PATCH --- pms_api_rest/datamodels/pms_folio.py | 3 +++ pms_api_rest/services/pms_folio_service.py | 22 ++++++---------------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pms_api_rest/datamodels/pms_folio.py b/pms_api_rest/datamodels/pms_folio.py index f94b8bd4b..76389921f 100644 --- a/pms_api_rest/datamodels/pms_folio.py +++ b/pms_api_rest/datamodels/pms_folio.py @@ -48,6 +48,9 @@ class PmsFolioInfo(Datamodel): invoiceStatus = fields.String(required=False, allow_none=True) portalUrl = fields.String(required=False, allow_none=True) language = fields.String(required=False, allow_none=True) + transactions = fields.List( + NestedModel("pms.transaction.info"), required=False, allow_none=True + ) class PmsFolioShortInfo(Datamodel): diff --git a/pms_api_rest/services/pms_folio_service.py b/pms_api_rest/services/pms_folio_service.py index 1f594fd80..15d847ebd 100644 --- a/pms_api_rest/services/pms_folio_service.py +++ b/pms_api_rest/services/pms_folio_service.py @@ -671,21 +671,10 @@ class PmsFolioService(Component): return folio.id def compute_transactions(self, folio, transactions): - """ - "transactions": [ - { - "transactionReference": "De34deaDea43242", - "amount": 32.94, - "date": "2023-05-17", - "transactionType": "inbound" - }, - ... - ], - """ for transaction in transactions: reference = folio.name + " - " - if transaction.transactionReference: - reference += transaction.transactionReference + if transaction.reference: + reference += transaction.reference else: raise ValidationError(_("The transaction reference is required")) if not self.env["account.payment"].search( @@ -693,7 +682,7 @@ class PmsFolioService(Component): ("pms_property_id", "=", folio.pms_property_id.id), ("payment_type", "=", transaction.transactionType), ("folio_ids", "in", folio.id), - ("ref", "ilike", transaction.transactionReference), + ("ref", "ilike", transaction.reference), ] ): # TODO: Move this to the user API payment configuration @@ -725,7 +714,7 @@ class PmsFolioService(Component): reservations=False, services=False, partner=False, - date=datetime.strptime(transaction.date, "%m/%d/%Y"), + date=datetime.strptime(transaction.date, "%Y-%m-%d"), ref=reference, ) @@ -1516,7 +1505,8 @@ class PmsFolioService(Component): skip_compute_service_ids=True, force_overbooking=True if call_type == "external_app" else False, ).write(folio_vals) - _logger.info("FOLIO VALS", folio_vals) + if pms_folio_info.transactions: + self.compute_transactions(folio, pms_folio_info.transactions) def wrapper_reservations(self, folio, info_reservations): """