diff --git a/pms_api_rest/datamodels/__init__.py b/pms_api_rest/datamodels/__init__.py index 69d305d63..3f34fd5df 100644 --- a/pms_api_rest/datamodels/__init__.py +++ b/pms_api_rest/datamodels/__init__.py @@ -15,3 +15,8 @@ from . import pms_partner_info from . import pms_calendar_swap_info from . import pms_calendar_changes + +from . import pms_property_info +from . import pms_property_search_param +from . import pms_account_journal_info +from . import pms_payment_info diff --git a/pms_api_rest/datamodels/pms_account_journal_info.py b/pms_api_rest/datamodels/pms_account_journal_info.py new file mode 100644 index 000000000..25e2f7683 --- /dev/null +++ b/pms_api_rest/datamodels/pms_account_journal_info.py @@ -0,0 +1,10 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class PmsAccountJournalInfo(Datamodel): + _name = "pms.account.journal.info" + id = fields.Integer(required=False, allow_none=True) + name = fields.String(required=False, allow_none=True) + allowed_pms_payments = fields.Boolean(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_folio_info.py b/pms_api_rest/datamodels/pms_folio_info.py index 64d40c73e..54fe504b1 100644 --- a/pms_api_rest/datamodels/pms_folio_info.py +++ b/pms_api_rest/datamodels/pms_folio_info.py @@ -16,3 +16,5 @@ class PmsFolioInfo(Datamodel): pendingAmount = fields.Float(required=False, allow_none=True) reservations = fields.List(fields.Dict(required=False, allow_none=True)) salesPerson = fields.String(required=False, allow_none=True) + paymentState = fields.String(required=False, allow_none=True) + propertyId = fields.Integer(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_payment_info.py b/pms_api_rest/datamodels/pms_payment_info.py new file mode 100644 index 000000000..63d34602b --- /dev/null +++ b/pms_api_rest/datamodels/pms_payment_info.py @@ -0,0 +1,12 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class PmsPaymentInfo(Datamodel): + _name = "pms.payment.info" + id = fields.Integer(required=False, allow_none=True) + amount = fields.Float(required=False, allow_none=True) + journalId = fields.Integer(required=False, allow_none=True) + journalName = fields.String(required=False, allow_none=True) + date = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_property_info.py b/pms_api_rest/datamodels/pms_property_info.py new file mode 100644 index 000000000..79db92240 --- /dev/null +++ b/pms_api_rest/datamodels/pms_property_info.py @@ -0,0 +1,10 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class PmsPropertyInfo(Datamodel): + _name = "pms.property.info" + id = fields.Integer(required=False, allow_none=True) + name = fields.String(required=False, allow_none=True) + company = fields.String(required=False, allow_none=True) diff --git a/pms_api_rest/datamodels/pms_property_search_param.py b/pms_api_rest/datamodels/pms_property_search_param.py new file mode 100644 index 000000000..c8a1f81b4 --- /dev/null +++ b/pms_api_rest/datamodels/pms_property_search_param.py @@ -0,0 +1,10 @@ +from marshmallow import fields + +from odoo.addons.datamodel.core import Datamodel + + +class PmsPropertySearchParam(Datamodel): + _name = "pms.property.search.param" + + id = fields.Integer(required=False, allow_none=False) + name = fields.String(required=False, allow_none=False) diff --git a/pms_api_rest/services/__init__.py b/pms_api_rest/services/__init__.py index ca589e26c..87c212ea5 100644 --- a/pms_api_rest/services/__init__.py +++ b/pms_api_rest/services/__init__.py @@ -5,4 +5,4 @@ from . import calendar_service from . import partner_services from . import reservation_services - +from . import property_services diff --git a/pms_api_rest/services/folio_services.py b/pms_api_rest/services/folio_services.py index bdfeba4b0..1918bf078 100644 --- a/pms_api_rest/services/folio_services.py +++ b/pms_api_rest/services/folio_services.py @@ -99,6 +99,10 @@ class PmsFolioService(Component): pendingAmount=folio.pending_amount, reservations=[] if not reservations else reservations, salesPerson=folio.user_id.name if folio.user_id else "", + paymentState=dict(folio.fields_get(["payment_state"])["payment_state"]["selection"])[ + folio.payment_state + ] if folio.payment_state else "", + propertyId=folio.pms_property_id, ) ) return result_folios @@ -221,3 +225,53 @@ class PmsFolioService(Component): ) ) return checkin_partners + + @restapi.method( + [ + ( + [ + "//payments", + ], + "GET", + ) + ], + output_param=Datamodel("pms.payment.info", is_list=True), + auth="public", + ) + def get_folio_payments(self, folio_id): + folio = ( + self.env["pms.folio"].sudo().search([("id", "=", folio_id)]) + ) + payments = [] + PmsPaymentInfo = self.env.datamodels["pms.payment.info"] + if not folio: + pass + else: + if folio.payment_state == "not_paid": + pass + # si el folio está sin pagar no tendrá ningún pago o envíar []? + else: + if folio.statement_line_ids: + for payment in folio.statement_line_ids: + payments.append( + PmsPaymentInfo( + id=payment.id, + amount=payment.amount, + journalId=payment.journal_id, + journalName=payment.journal_id.name, + date=str(payment.date), + ) + ) + if folio.payment_ids: + if folio.payment_ids: + for payment in folio.payment_ids: + payments.append( + PmsPaymentInfo( + id=payment.id, + amount=payment.amount, + journalId=payment.journal_id, + journalName=payment.journal_id.name, + date=str(payment.date), + ) + ) + return payments diff --git a/pms_api_rest/services/property_services.py b/pms_api_rest/services/property_services.py new file mode 100644 index 000000000..926cdd794 --- /dev/null +++ b/pms_api_rest/services/property_services.py @@ -0,0 +1,115 @@ +from datetime import datetime + +from odoo.addons.base_rest import restapi +from odoo.addons.base_rest_datamodel.restapi import Datamodel +from odoo.addons.component.core import Component + + +class PmsPropertyComponent(Component): + _inherit = "base.rest.service" + _name = "pms.property.service" + _usage = "properties" + _collection = "pms.reservation.service" + + @restapi.method( + [ + ( + [ + "/", + ], + "GET", + ) + ], + input_param=Datamodel("pms.property.search.param"), + output_param=Datamodel("pms.property.info", is_list=True), + auth="public", + ) + def get_properties(self,property_search_param): + domain = [] + if property_search_param.name: + domain.append(("name", "like", property_search_param.name)) + if property_search_param.id: + 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, + ) + ): + result_properties.append( + PmsPropertyInfo( + id=prop.id, + name=prop.name, + company=prop.company_id.name, + ) + ) + return result_properties + + @restapi.method( + [ + ( + [ + "/", + ], + "GET", + ) + ], + output_param=Datamodel("pms.property.info"), + auth="public", + ) + def get_property(self, property_id): + pms_property = ( + self.env["pms.property"].sudo().search([("id", "=", property_id)]) + ) + res = [] + PmsPropertyInfo = self.env.datamodels["pms.property.info"] + if not pms_property: + pass + else: + res = PmsPropertyInfo( + id=pms_property.id, + name=pms_property.name, + company=pms_property.company_id.name, + ) + + return res + + @restapi.method( + [ + ( + [ + "//paymentmethods", + ], + "GET", + ) + ], + output_param=Datamodel("pms.account.journal.info",is_list=True), + auth="public", + ) + def get_method_payments_property(self, property_id): + + property = ( + self.env["pms.property"].sudo().search([("id", "=", property_id)]) + ) + PmsAccountJournalInfo = self.env.datamodels["pms.account.journal.info"] + res = [] + if not property: + pass + else: + for method in property._get_payment_methods( + automatic_included=True + ): + payment_method = ( + self.env["account.journal"].sudo().search([("id", "=", method.id)]) + ) + res.append( + PmsAccountJournalInfo( + id=payment_method.id, + name=payment_method.name, + allowed_pms_payments=payment_method.allowed_pms_payments, + ) + ) + return res