mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP] pms_api_rest: add get for payments and invoices in partner service
This commit is contained in:
@@ -15,6 +15,7 @@ from . import pms_partner
|
||||
from . import pms_property
|
||||
from . import pms_account_journal
|
||||
from . import pms_account_payment
|
||||
from . import pms_account_move
|
||||
|
||||
from . import pms_user
|
||||
|
||||
|
||||
13
pms_api_rest/datamodels/pms_account_move.py
Normal file
13
pms_api_rest/datamodels/pms_account_move.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from marshmallow import fields
|
||||
|
||||
from odoo.addons.datamodel.core import Datamodel
|
||||
|
||||
|
||||
class PmsAccountMove(Datamodel):
|
||||
_name = "pms.account.move.info"
|
||||
id = fields.Integer(required=False, allow_none=True)
|
||||
amount = fields.Float(required=False, allow_none=True)
|
||||
name = fields.String(required=False, allow_none=True)
|
||||
date = fields.String(required=False, allow_none=True)
|
||||
paymentState = fields.String(required=False, allow_none=True)
|
||||
state = fields.String(required=False, allow_none=True)
|
||||
12
pms_api_rest/datamodels/pms_payment.py
Normal file
12
pms_api_rest/datamodels/pms_payment.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)
|
||||
date = fields.String(required=False, allow_none=True)
|
||||
memo = fields.String(required=False, allow_none=True)
|
||||
@@ -241,6 +241,69 @@ class PmsPartnerService(Component):
|
||||
)
|
||||
return reservations
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:partner_id>/payments",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.payment.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_partner_payments(self, partner_id):
|
||||
partnerPayments = self.env["account.payment"].search(
|
||||
[("partner_id", "=", partner_id)]
|
||||
)
|
||||
PmsPaymentInfo = self.env.datamodels["pms.payment.info"]
|
||||
payments = []
|
||||
for payment in partnerPayments:
|
||||
payments.append(
|
||||
PmsPaymentInfo(
|
||||
id=payment.id,
|
||||
amount=round(payment.amount, 2),
|
||||
journalId=payment.journal_id.id,
|
||||
date=payment.date.strftime("%d/%m/%Y"),
|
||||
memo=payment.ref,
|
||||
)
|
||||
)
|
||||
return payments
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
[
|
||||
"/<int:partner_id>/invoices",
|
||||
],
|
||||
"GET",
|
||||
)
|
||||
],
|
||||
output_param=Datamodel("pms.account.move.info", is_list=True),
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def get_partner_invoices(self, partner_id):
|
||||
partnerInvoices = self.env["account.move"].search(
|
||||
[("partner_id", "=", partner_id)]
|
||||
)
|
||||
PmsAcoountMoveInfo = self.env.datamodels["pms.account.move.info"]
|
||||
invoices = []
|
||||
for invoice in partnerInvoices:
|
||||
invoices.append(
|
||||
PmsAcoountMoveInfo(
|
||||
id=invoice.id,
|
||||
name=invoice.name,
|
||||
amount=round(invoice.amount_total, 2),
|
||||
date=invoice.date.strftime("%d/%m/%Y"),
|
||||
state=invoice.state,
|
||||
paymentState=invoice.payment_state
|
||||
if invoice.payment_state
|
||||
else None,
|
||||
)
|
||||
)
|
||||
return invoices
|
||||
|
||||
@restapi.method(
|
||||
[
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user