diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index c05b180d3..351df914f 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -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 diff --git a/pms_api_rest/__manifest__.py b/pms_api_rest/__manifest__.py index c55bf7683..e884b0fbe 100644 --- a/pms_api_rest/__manifest__.py +++ b/pms_api_rest/__manifest__.py @@ -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", diff --git a/pms_api_rest/data/sql_reports.xml b/pms_api_rest/data/sql_reports.xml new file mode 100644 index 000000000..3e9626ec9 --- /dev/null +++ b/pms_api_rest/data/sql_reports.xml @@ -0,0 +1,130 @@ + + + + x_date_from + Date + date + + sql.file.wizard + manual + + + + x_pms_property_id + Property + integer + + sql.file.wizard + manual + + + + + Export Departures + excel + + 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 + + + + + + + + + Export Arrivals + excel + + 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 + + + + + + + + + Export Services + excel + + 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; + + + + + + diff --git a/pms_api_rest/models/__init__.py b/pms_api_rest/models/__init__.py index 495168b21..4713a4d6b 100644 --- a/pms_api_rest/models/__init__.py +++ b/pms_api_rest/models/__init__.py @@ -1,3 +1,4 @@ from . import pms_property from . import res_users from . import account_payment +from . import sql_export diff --git a/pms_api_rest/models/sql_export.py b/pms_api_rest/models/sql_export.py new file mode 100644 index 000000000..26c26b8a1 --- /dev/null +++ b/pms_api_rest/models/sql_export.py @@ -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() diff --git a/pms_api_rest/services/pms_reservation_service.py b/pms_api_rest/services/pms_reservation_service.py index cfae9a42b..52e6addc2 100644 --- a/pms_api_rest/services/pms_reservation_service.py +++ b/pms_api_rest/services/pms_reservation_service.py @@ -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) diff --git a/pms_api_rest/services/pms_service_service.py b/pms_api_rest/services/pms_service_service.py index 76018fcd5..4c93c1de6 100644 --- a/pms_api_rest/services/pms_service_service.py +++ b/pms_api_rest/services/pms_service_service.py @@ -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)