mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add payments in folio and property service
This commit is contained in:
committed by
Darío Lodeiros
parent
7f6faae55d
commit
b3ed4109bb
@@ -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
|
||||
|
||||
10
pms_api_rest/datamodels/pms_account_journal_info.py
Normal file
10
pms_api_rest/datamodels/pms_account_journal_info.py
Normal file
@@ -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)
|
||||
@@ -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)
|
||||
|
||||
12
pms_api_rest/datamodels/pms_payment_info.py
Normal file
12
pms_api_rest/datamodels/pms_payment_info.py
Normal file
@@ -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)
|
||||
10
pms_api_rest/datamodels/pms_property_info.py
Normal file
10
pms_api_rest/datamodels/pms_property_info.py
Normal file
@@ -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)
|
||||
10
pms_api_rest/datamodels/pms_property_search_param.py
Normal file
10
pms_api_rest/datamodels/pms_property_search_param.py
Normal file
@@ -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)
|
||||
@@ -5,4 +5,4 @@ from . import calendar_service
|
||||
from . import partner_services
|
||||
|
||||
from . import reservation_services
|
||||
|
||||
from . import property_services
|
||||
|
||||
@@ -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(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:id>/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
|
||||
|
||||
115
pms_api_rest/services/property_services.py
Normal file
115
pms_api_rest/services/property_services.py
Normal file
@@ -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(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:property_id>",
|
||||
],
|
||||
"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(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:property_id>/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
|
||||
Reference in New Issue
Block a user