mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms-api-rest: added post for folio charges
This commit is contained in:
@@ -14,7 +14,7 @@ from . import pms_partner
|
||||
|
||||
from . import pms_property
|
||||
from . import pms_account_journal
|
||||
from . import pms_payment
|
||||
from . import pms_account_payment
|
||||
|
||||
from . import pms_user
|
||||
|
||||
|
||||
20
pms_api_rest/datamodels/pms_account_payment.py
Normal file
20
pms_api_rest/datamodels/pms_account_payment.py
Normal file
@@ -0,0 +1,20 @@
|
||||
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)
|
||||
date = fields.String(required=False, allow_none=True)
|
||||
|
||||
|
||||
class PmsAccountPaymentInfo(Datamodel):
|
||||
_name = "pms.account.payment.short.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
date = fields.String(required=False, allow_none=True)
|
||||
journalId = fields.Integer(required=False, allow_none=True)
|
||||
amount = fields.Float(required=False, allow_none=True)
|
||||
partnerName = fields.String(required=False, allow_none=True)
|
||||
@@ -22,6 +22,7 @@ class PmsFolioInfo(Datamodel):
|
||||
state = fields.String(required=False, allow_none=True)
|
||||
amountTotal = fields.Float(required=False, allow_none=True)
|
||||
reservationType = fields.String(required=False, allow_none=True)
|
||||
pendingAmount = fields.Float(required=False, allow_none=True)
|
||||
|
||||
|
||||
class PmsFolioShortInfo(Datamodel):
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
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)
|
||||
date = fields.String(required=False, allow_none=True)
|
||||
@@ -46,6 +46,7 @@ class PmsFolioService(Component):
|
||||
],
|
||||
amountTotal=round(folio.amount_total, 2),
|
||||
reservationType=folio.reservation_type,
|
||||
pendingAmount=folio.pending_amount,
|
||||
)
|
||||
else:
|
||||
raise MissingError(_("Folio not found"))
|
||||
@@ -189,8 +190,20 @@ class PmsFolioService(Component):
|
||||
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:
|
||||
# if folio.statement_line_ids:
|
||||
# for payment in folio.statement_line_ids:
|
||||
# payments.append(
|
||||
# PmsPaymentInfo(
|
||||
# id=payment.id,
|
||||
# amount=round(payment.amount, 2),
|
||||
# journalId=payment.journal_id.id,
|
||||
# date=datetime.combine(
|
||||
# payment.date, datetime.min.time()
|
||||
# ).isoformat(),
|
||||
# )
|
||||
# )
|
||||
if folio.payment_ids:
|
||||
for payment in folio.payment_ids:
|
||||
payments.append(
|
||||
PmsPaymentInfo(
|
||||
id=payment.id,
|
||||
@@ -201,21 +214,57 @@ class PmsFolioService(Component):
|
||||
).isoformat(),
|
||||
)
|
||||
)
|
||||
if folio.payment_ids:
|
||||
if folio.payment_ids:
|
||||
for payment in folio.payment_ids:
|
||||
payments.append(
|
||||
PmsPaymentInfo(
|
||||
id=payment.id,
|
||||
amount=round(payment.amount, 2),
|
||||
journalId=payment.journal_id.id,
|
||||
date=datetime.combine(
|
||||
payment.date, datetime.min.time()
|
||||
).isoformat(),
|
||||
)
|
||||
)
|
||||
return payments
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:folio_id>/payments",
|
||||
],
|
||||
"POST",
|
||||
)
|
||||
],
|
||||
input_param=Datamodel("pms.account.payment.short.info", is_list=False),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def create_folio_charge(self, folio_id, pms_account_payment_info):
|
||||
partner = self.env["res.partner"].search(
|
||||
[("name", "=", pms_account_payment_info.partnerName)]
|
||||
)
|
||||
folio = self.env["pms.folio"].browse(folio_id)
|
||||
|
||||
if partner:
|
||||
partner_id = partner
|
||||
elif not partner and pms_account_payment_info.partnerName:
|
||||
partner_id = self.env["res.partner"].create(
|
||||
{"name": pms_account_payment_info.partnerName}
|
||||
)
|
||||
else:
|
||||
partner_id = folio.partner_id
|
||||
charge_date_str = (
|
||||
pms_account_payment_info.date[3:5]
|
||||
+ "/"
|
||||
+ pms_account_payment_info.date[:2]
|
||||
+ "/"
|
||||
+ pms_account_payment_info.date[6:]
|
||||
)
|
||||
charge_date = datetime.strptime(charge_date_str, "%m/%d/%Y")
|
||||
journal_id = self.env["account.journal"].browse(
|
||||
pms_account_payment_info.journalId
|
||||
)
|
||||
self.env["pms.folio"].do_payment(
|
||||
journal_id,
|
||||
journal_id.suspense_account_id,
|
||||
self.env.user,
|
||||
pms_account_payment_info.amount,
|
||||
folio,
|
||||
reservations=False,
|
||||
services=False,
|
||||
partner=partner_id,
|
||||
date=charge_date,
|
||||
)
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user