mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[IMP]pms_api_rest: added GET services for sale lines and invoices
This commit is contained in:
@@ -52,3 +52,5 @@ from . import pms_account_payment_term
|
|||||||
|
|
||||||
from . import pms_room_closure_reason
|
from . import pms_room_closure_reason
|
||||||
from . import pms_report
|
from . import pms_report
|
||||||
|
from . import pms_folio_sale_line
|
||||||
|
from . import pms_invoice_line
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
from marshmallow import fields
|
from marshmallow import fields
|
||||||
|
|
||||||
from odoo.addons.datamodel.core import Datamodel
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
from odoo.addons.datamodel.fields import NestedModel
|
||||||
|
|
||||||
|
|
||||||
class PmsAccountMove(Datamodel):
|
class PmsAccountMoveInfo(Datamodel):
|
||||||
_name = "pms.account.move.info"
|
_name = "pms.account.move.info"
|
||||||
id = fields.Integer(required=False, allow_none=True)
|
id = fields.Integer(required=False, allow_none=True)
|
||||||
amount = fields.Float(required=False, allow_none=True)
|
amount = fields.Float(required=False, allow_none=True)
|
||||||
@@ -11,3 +12,5 @@ class PmsAccountMove(Datamodel):
|
|||||||
date = fields.String(required=False, allow_none=True)
|
date = fields.String(required=False, allow_none=True)
|
||||||
paymentState = fields.String(required=False, allow_none=True)
|
paymentState = fields.String(required=False, allow_none=True)
|
||||||
state = fields.String(required=False, allow_none=True)
|
state = fields.String(required=False, allow_none=True)
|
||||||
|
partnerName = fields.String(required=False, allow_none=True)
|
||||||
|
moveLines = fields.List(NestedModel("pms.invoice.line.info"))
|
||||||
|
|||||||
17
pms_api_rest/datamodels/pms_folio_sale_line.py
Normal file
17
pms_api_rest/datamodels/pms_folio_sale_line.py
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsFolioSaleInfo(Datamodel):
|
||||||
|
_name = "pms.folio.sale.line.info"
|
||||||
|
id = fields.Integer(required=False, allow_none=True)
|
||||||
|
name = fields.String(required=False, allow_none=True)
|
||||||
|
priceUnit = fields.Float(required=False, allow_none=True)
|
||||||
|
qtyToInvoice = fields.Float(required=False, allow_none=True)
|
||||||
|
qtyInvoiced = fields.Float(required=False, allow_none=True)
|
||||||
|
priceTotal = fields.Float(required=False, allow_none=True)
|
||||||
|
productQty = fields.Float(required=False, allow_none=True)
|
||||||
|
reservationId = fields.Integer(required=False, allow_none=True)
|
||||||
|
serviceId = fields.Integer(required=False, allow_none=True)
|
||||||
|
displayType = fields.String(required=False, allow_none=True)
|
||||||
12
pms_api_rest/datamodels/pms_invoice_line.py
Normal file
12
pms_api_rest/datamodels/pms_invoice_line.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from marshmallow import fields
|
||||||
|
|
||||||
|
from odoo.addons.datamodel.core import Datamodel
|
||||||
|
|
||||||
|
|
||||||
|
class PmsInvoiceLineInfo(Datamodel):
|
||||||
|
_name = "pms.invoice.line.info"
|
||||||
|
id = fields.Integer(required=False, allow_none=True)
|
||||||
|
name = fields.String(required=False, allow_none=True)
|
||||||
|
quantity = fields.Float(required=False, allow_none=True)
|
||||||
|
total = fields.Float(required=False, allow_none=True)
|
||||||
|
displayType = fields.String(required=False, allow_none=True)
|
||||||
@@ -421,3 +421,118 @@ class PmsFolioService(Component):
|
|||||||
self.env["pms.service"].create(vals)
|
self.env["pms.service"].create(vals)
|
||||||
|
|
||||||
return folio.id
|
return folio.id
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:folio_id>/sale-lines",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
output_param=Datamodel("pms.folio.sale.line.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_folio_sale_lines(self, folio_id):
|
||||||
|
folio = self.env["pms.folio"].browse(folio_id)
|
||||||
|
sale_lines = []
|
||||||
|
if not folio:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
PmsFolioSaleLineInfo = self.env.datamodels["pms.folio.sale.line.info"]
|
||||||
|
if folio.sale_line_ids:
|
||||||
|
for sale_line in folio.sale_line_ids:
|
||||||
|
sale_lines.append(
|
||||||
|
PmsFolioSaleLineInfo(
|
||||||
|
id=sale_line.id if sale_line.id else None,
|
||||||
|
name=sale_line.name if sale_line.name else None,
|
||||||
|
priceUnit=sale_line.price_unit
|
||||||
|
if sale_line.price_unit
|
||||||
|
else None,
|
||||||
|
qtyToInvoice=sale_line.qty_to_invoice
|
||||||
|
if sale_line.qty_to_invoice
|
||||||
|
else None,
|
||||||
|
qtyInvoiced=sale_line.qty_invoiced
|
||||||
|
if sale_line.qty_invoiced
|
||||||
|
else None,
|
||||||
|
priceTotal=sale_line.price_total
|
||||||
|
if sale_line.price_total
|
||||||
|
else None,
|
||||||
|
productQty=sale_line.product_uom_qty
|
||||||
|
if sale_line.product_uom_qty
|
||||||
|
else None,
|
||||||
|
reservationId=sale_line.reservation_id
|
||||||
|
if sale_line.reservation_id
|
||||||
|
else None,
|
||||||
|
serviceId=sale_line.service_id
|
||||||
|
if sale_line.service_id
|
||||||
|
else None,
|
||||||
|
displayType=sale_line.display_type
|
||||||
|
if sale_line.display_type
|
||||||
|
else None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
return sale_lines
|
||||||
|
|
||||||
|
@restapi.method(
|
||||||
|
[
|
||||||
|
(
|
||||||
|
[
|
||||||
|
"/<int:folio_id>/invoices",
|
||||||
|
],
|
||||||
|
"GET",
|
||||||
|
)
|
||||||
|
],
|
||||||
|
output_param=Datamodel("pms.account.move.info", is_list=True),
|
||||||
|
auth="jwt_api_pms",
|
||||||
|
)
|
||||||
|
def get_folio_invoices(self, folio_id):
|
||||||
|
folio = self.env["pms.folio"].browse(folio_id)
|
||||||
|
invoices = []
|
||||||
|
if not folio:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
PmsFolioInvoiceInfo = self.env.datamodels["pms.account.move.info"]
|
||||||
|
PmsInvoiceLineInfo = self.env.datamodels["pms.invoice.line.info"]
|
||||||
|
if folio.move_ids:
|
||||||
|
for move_id in folio.move_ids:
|
||||||
|
move_lines = []
|
||||||
|
for move_line in move_id.invoice_line_ids:
|
||||||
|
move_lines.append(
|
||||||
|
PmsInvoiceLineInfo(
|
||||||
|
id=move_line.id,
|
||||||
|
name=move_line.name if move_line.name else None,
|
||||||
|
quantity=move_line.quantity
|
||||||
|
if move_line.quantity
|
||||||
|
else None,
|
||||||
|
total=move_line.price_total
|
||||||
|
if move_line.price_total
|
||||||
|
else None,
|
||||||
|
displayType=move_line.display_type
|
||||||
|
if move_line.display_type
|
||||||
|
else None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
invoices.append(
|
||||||
|
PmsFolioInvoiceInfo(
|
||||||
|
id=move_id.id if move_id.id else None,
|
||||||
|
name=move_id.name if move_id.name else None,
|
||||||
|
amount=round(move_id.amount_total, 2)
|
||||||
|
if move_id.amount_total
|
||||||
|
else None,
|
||||||
|
date=move_id.date.strftime("%d/%m/%Y")
|
||||||
|
if move_id.date
|
||||||
|
else None,
|
||||||
|
state=move_id.state if move_id.state else None,
|
||||||
|
paymentState=move_id.payment_state
|
||||||
|
if move_id.payment_state
|
||||||
|
else None,
|
||||||
|
partnerName=move_id.partner_id.name
|
||||||
|
if move_id.partner_id.name
|
||||||
|
else None,
|
||||||
|
moveLines=move_lines if move_lines else None,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return invoices
|
||||||
|
|||||||
Reference in New Issue
Block a user