mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[ADD]pms_api_rest: basic reports services
This commit is contained in:
@@ -997,12 +997,12 @@ class PmsReservation(models.Model):
|
||||
]
|
||||
)
|
||||
# Avoid recalculating services if the boardservice has not changed
|
||||
if (
|
||||
old_board_lines
|
||||
and reservation.board_service_room_id
|
||||
== reservation._origin.board_service_room_id
|
||||
):
|
||||
return
|
||||
# if (
|
||||
# old_board_lines
|
||||
# and reservation.board_service_room_id
|
||||
# == reservation._origin.board_service_room_id
|
||||
# ):
|
||||
# return
|
||||
if reservation.board_service_room_id:
|
||||
board = self.env["pms.board.service.room.type"].browse(
|
||||
reservation.board_service_room_id.id
|
||||
|
||||
@@ -14,11 +14,13 @@
|
||||
"auth_jwt_login",
|
||||
"base_location",
|
||||
"l10n_es_aeat",
|
||||
"sql_export_excel",
|
||||
],
|
||||
"external_dependencies": {
|
||||
"python": ["jwt", "simplejson", "marshmallow", "jose"],
|
||||
},
|
||||
"data": [
|
||||
"data/sql_reports.xml",
|
||||
"data/auth_jwt_validator.xml",
|
||||
"views/pms_property_views.xml",
|
||||
"views/res_users_views.xml",
|
||||
|
||||
130
pms_api_rest/data/sql_reports.xml
Normal file
130
pms_api_rest/data/sql_reports.xml
Normal file
@@ -0,0 +1,130 @@
|
||||
<odoo noupdate="1">
|
||||
|
||||
<record id="date_from_field_variable_sql" model="ir.model.fields">
|
||||
<field name="name">x_date_from</field>
|
||||
<field name="field_description">Date</field>
|
||||
<field name="ttype">date</field>
|
||||
<field name="model_id" ref="sql_export.model_sql_file_wizard" />
|
||||
<field name="model">sql.file.wizard</field>
|
||||
<field name="state">manual</field>
|
||||
</record>
|
||||
|
||||
<record id="pms_property_field_variable_sql" model="ir.model.fields">
|
||||
<field name="name">x_pms_property_id</field>
|
||||
<field name="field_description">Property</field>
|
||||
<field name="ttype">integer</field>
|
||||
<field name="model_id" ref="sql_export.model_sql_file_wizard" />
|
||||
<field name="model">sql.file.wizard</field>
|
||||
<field name="state">manual</field>
|
||||
</record>
|
||||
|
||||
<!-- DEPARTURES REPORT -->
|
||||
<record id="sql_export_departures" model="sql.export">
|
||||
<field name="name">Export Departures</field>
|
||||
<field name="file_format">excel</field>
|
||||
<field name="query">
|
||||
SELECT
|
||||
TO_CHAR(reservation.checkout, 'DD-MM-YYYY') as "Departure",
|
||||
folio.name as "Reservation",
|
||||
room.name as "Room",
|
||||
reservation.partner_name as "Customer",
|
||||
folio.pending_amount as "Pending Amount"
|
||||
FROM pms_reservation reservation
|
||||
LEFT JOIN pms_reservation_line night
|
||||
ON reservation.id = night.reservation_id AND night.date = reservation.checkout - interval '1' day
|
||||
LEFT JOIN pms_room room
|
||||
ON room.id = night.room_id
|
||||
LEFT JOIN pms_folio folio
|
||||
ON folio.id = reservation.folio_id
|
||||
WHERE (reservation.pms_property_id = %(x_pms_property_id)s)
|
||||
AND (reservation.checkout = %(x_date_from)s)
|
||||
AND (night.occupies_availability = True)
|
||||
ORDER BY reservation.name
|
||||
</field>
|
||||
<field
|
||||
eval="[(6, 0, [ref('date_from_field_variable_sql'), ref('pms_property_field_variable_sql')])]"
|
||||
name="field_ids"
|
||||
/>
|
||||
</record>
|
||||
|
||||
<function
|
||||
model="sql.export"
|
||||
name="button_validate_sql_expression"
|
||||
eval="([ref('pms_api_rest.sql_export_departures')])"
|
||||
/>
|
||||
|
||||
<!-- ARRIVALS REPORT -->
|
||||
<record id="sql_export_arrivals" model="sql.export">
|
||||
<field name="name">Export Arrivals</field>
|
||||
<field name="file_format">excel</field>
|
||||
<field name="query">
|
||||
SELECT
|
||||
TO_CHAR(reservation.checkin, 'DD-MM-YYYY') as "Arrival",
|
||||
folio.name as "Reservation",
|
||||
room.name as "Room",
|
||||
reservation.partner_name as "Customer",
|
||||
folio.pending_amount as "Pending Amount"
|
||||
FROM pms_reservation reservation
|
||||
LEFT JOIN pms_reservation_line night
|
||||
ON reservation.id = night.reservation_id AND night.date = reservation.checkin
|
||||
LEFT JOIN pms_room room
|
||||
ON room.id = night.room_id
|
||||
LEFT JOIN pms_folio folio
|
||||
ON folio.id = reservation.folio_id
|
||||
WHERE (reservation.pms_property_id = %(x_pms_property_id)s)
|
||||
AND (reservation.checkin = %(x_date_from)s)
|
||||
AND (night.occupies_availability = True)
|
||||
ORDER BY reservation.name
|
||||
</field>
|
||||
<field
|
||||
eval="[(6, 0, [ref('date_from_field_variable_sql'), ref('pms_property_field_variable_sql')])]"
|
||||
name="field_ids"
|
||||
/>
|
||||
</record>
|
||||
|
||||
<function
|
||||
model="sql.export"
|
||||
name="button_validate_sql_expression"
|
||||
eval="([ref('pms_api_rest.sql_export_arrivals')])"
|
||||
/>
|
||||
|
||||
<!-- SERVICES REPORT -->
|
||||
<record id="sql_export_services" model="sql.export">
|
||||
<field name="name">Export Services</field>
|
||||
<field name="file_format">excel</field>
|
||||
<field name="query">
|
||||
SELECT
|
||||
TO_CHAR(line.date, 'DD-MM-YYYY') as "Date",
|
||||
reservation.name as "Reservation",
|
||||
reservation.rooms,
|
||||
product_tmpl.name as "Name",
|
||||
line.day_qty as "Units",
|
||||
reservation.adults as "Room Adults",
|
||||
reservation.children as "Room Childrens",
|
||||
line.is_board_service as "Board Service"
|
||||
FROM pms_service_line line
|
||||
LEFT JOIN product_product product
|
||||
ON line.product_id = product.id
|
||||
LEFT JOIN product_template product_tmpl
|
||||
ON product.product_tmpl_id = product_tmpl.id
|
||||
LEFT JOIN pms_reservation reservation
|
||||
ON line.reservation_id = reservation.id
|
||||
LEFT JOIN pms_checkin_partner room_host
|
||||
ON room_host.reservation_id = reservation.id
|
||||
WHERE (line.date = %(x_date_from)s)
|
||||
AND (line.pms_property_id = %(x_pms_property_id)s)
|
||||
GROUP BY
|
||||
line.id, product_tmpl.name, reservation.name, reservation.rooms, reservation.adults, reservation.children;
|
||||
</field>
|
||||
<field
|
||||
eval="[(6, 0, [ref('date_from_field_variable_sql'), ref('pms_property_field_variable_sql')])]"
|
||||
name="field_ids"
|
||||
/>
|
||||
</record>
|
||||
|
||||
<function
|
||||
model="sql.export"
|
||||
name="button_validate_sql_expression"
|
||||
eval="([ref('pms_api_rest.sql_export_services')])"
|
||||
/>
|
||||
</odoo>
|
||||
@@ -1,3 +1,4 @@
|
||||
from . import pms_property
|
||||
from . import res_users
|
||||
from . import account_payment
|
||||
from . import sql_export
|
||||
|
||||
15
pms_api_rest/models/sql_export.py
Normal file
15
pms_api_rest/models/sql_export.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class SqlExport(models.Model):
|
||||
_inherit = "sql.export"
|
||||
|
||||
def unlink(self):
|
||||
if (
|
||||
self.env.ref("pms_api_rest.sql_export_services") in self
|
||||
or self.env.ref("pms_api_rest.sql_export_departures") in self
|
||||
or self.env.ref("pms_api_rest.sql_export_arrivals") in self
|
||||
):
|
||||
raise UserError(_("You can not delete PMS SQL query"))
|
||||
return super().unlink()
|
||||
@@ -791,19 +791,17 @@ class PmsReservationService(Component):
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def kelly_report(self, pms_report_search_param):
|
||||
# TODO: Implement kelly report
|
||||
pms_property_id = pms_report_search_param.pmsPropertyId
|
||||
date_from = fields.Date.from_string(pms_report_search_param.dateFrom)
|
||||
date_to = fields.Date.from_string(pms_report_search_param.dateTo)
|
||||
|
||||
report_wizard = self.env["cash.daily.report.wizard"].create(
|
||||
report_wizard = self.env["kellysreport"].create(
|
||||
{
|
||||
"date_start": date_from,
|
||||
"date_end": date_to,
|
||||
"pms_property_id": pms_property_id,
|
||||
}
|
||||
)
|
||||
result = report_wizard._export()
|
||||
report_wizard.calculate_report()
|
||||
result = report_wizard._excel_export()
|
||||
file_name = result["xls_filename"]
|
||||
base64EncodedStr = result["xls_binary"]
|
||||
PmsResponse = self.env.datamodels["pms.report"]
|
||||
@@ -823,21 +821,25 @@ class PmsReservationService(Component):
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def arrivals_report(self, pms_report_search_param):
|
||||
# TODO: Implment arrivals report
|
||||
pms_property_id = pms_report_search_param.pmsPropertyId
|
||||
date_from = fields.Date.from_string(pms_report_search_param.dateFrom)
|
||||
date_to = fields.Date.from_string(pms_report_search_param.dateTo)
|
||||
|
||||
report_wizard = self.env["cash.daily.report.wizard"].create(
|
||||
{
|
||||
"date_start": date_from,
|
||||
"date_end": date_to,
|
||||
"pms_property_id": pms_property_id,
|
||||
}
|
||||
)
|
||||
result = report_wizard._export()
|
||||
file_name = result["xls_filename"]
|
||||
base64EncodedStr = result["xls_binary"]
|
||||
query = self.env.ref("pms_api_rest.sql_export_arrivals")
|
||||
if not query:
|
||||
raise MissingError(_("SQL query not found"))
|
||||
report_wizard = self.env["sql.file.wizard"].create({"sql_export_id": query.id})
|
||||
if not report_wizard._fields.get(
|
||||
"x_date_from"
|
||||
) or not report_wizard._fields.get("x_pms_property_id"):
|
||||
raise MissingError(
|
||||
_("The Query params was modifieds, please contact the administrator")
|
||||
)
|
||||
report_wizard.x_date_from = date_from
|
||||
report_wizard.x_pms_property_id = pms_property_id
|
||||
|
||||
report_wizard.export_sql()
|
||||
file_name = report_wizard.file_name
|
||||
base64EncodedStr = report_wizard.binary_file
|
||||
PmsResponse = self.env.datamodels["pms.report"]
|
||||
return PmsResponse(fileName=file_name, binary=base64EncodedStr)
|
||||
|
||||
@@ -855,20 +857,26 @@ class PmsReservationService(Component):
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def departures_report(self, pms_report_search_param):
|
||||
# TODO: Implement departures report
|
||||
pms_property_id = pms_report_search_param.pmsPropertyId
|
||||
date_from = fields.Date.from_string(pms_report_search_param.dateFrom)
|
||||
date_to = fields.Date.from_string(pms_report_search_param.dateTo)
|
||||
|
||||
report_wizard = self.env["cash.daily.report.wizard"].create(
|
||||
{
|
||||
"date_start": date_from,
|
||||
"date_end": date_to,
|
||||
"pms_property_id": pms_property_id,
|
||||
}
|
||||
)
|
||||
result = report_wizard._export()
|
||||
file_name = result["xls_filename"]
|
||||
base64EncodedStr = result["xls_binary"]
|
||||
query = self.env.ref("pms_api_rest.sql_export_departures")
|
||||
if not query:
|
||||
raise MissingError(_("SQL query not found"))
|
||||
if query.state == "draft":
|
||||
query.button_validate_sql_expression()
|
||||
report_wizard = self.env["sql.file.wizard"].create({"sql_export_id": query.id})
|
||||
if not report_wizard._fields.get(
|
||||
"x_date_from"
|
||||
) or not report_wizard._fields.get("x_pms_property_id"):
|
||||
raise MissingError(
|
||||
_("The Query params was modifieds, please contact the administrator")
|
||||
)
|
||||
report_wizard.x_date_from = date_from
|
||||
report_wizard.x_pms_property_id = pms_property_id
|
||||
|
||||
report_wizard.export_sql()
|
||||
file_name = report_wizard.file_name
|
||||
base64EncodedStr = report_wizard.binary_file
|
||||
PmsResponse = self.env.datamodels["pms.report"]
|
||||
return PmsResponse(fileName=file_name, binary=base64EncodedStr)
|
||||
|
||||
@@ -186,20 +186,23 @@ class PmsServiceService(Component):
|
||||
auth="jwt_api_pms",
|
||||
)
|
||||
def services_report(self, pms_report_search_param):
|
||||
# TODO: Implment arrivals report
|
||||
pms_property_id = pms_report_search_param.pmsPropertyId
|
||||
date_from = fields.Date.from_string(pms_report_search_param.dateFrom)
|
||||
date_to = fields.Date.from_string(pms_report_search_param.dateTo)
|
||||
|
||||
report_wizard = self.env["cash.daily.report.wizard"].create(
|
||||
{
|
||||
"date_start": date_from,
|
||||
"date_end": date_to,
|
||||
"pms_property_id": pms_property_id,
|
||||
}
|
||||
)
|
||||
result = report_wizard._export()
|
||||
file_name = result["xls_filename"]
|
||||
base64EncodedStr = result["xls_binary"]
|
||||
query = self.env.ref("pms_api_rest.sql_export_services")
|
||||
if not query:
|
||||
raise MissingError(_("SQL query not found"))
|
||||
report_wizard = self.env["sql.file.wizard"].create({"sql_export_id": query.id})
|
||||
report_wizard.x_date_from = date_from
|
||||
report_wizard.x_pms_property_id = pms_property_id
|
||||
if not report_wizard._fields.get(
|
||||
"x_date_from"
|
||||
) or not report_wizard._fields.get("x_pms_property_id"):
|
||||
raise MissingError(
|
||||
_("The Query params was modifieds, please contact the administrator")
|
||||
)
|
||||
report_wizard.export_sql()
|
||||
file_name = report_wizard.file_name
|
||||
base64EncodedStr = report_wizard.binary_file
|
||||
PmsResponse = self.env.datamodels["pms.report"]
|
||||
return PmsResponse(fileName=file_name, binary=base64EncodedStr)
|
||||
|
||||
Reference in New Issue
Block a user