mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF] pms_l10n_es: refactor use constants when create/delete ses communications"
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from odoo import api, fields, models
|
||||
|
||||
from ..wizards.traveller_report import CREATE_OPERATION_CODE, DELETE_OPERATION_CODE
|
||||
|
||||
|
||||
class PmsReservation(models.Model):
|
||||
_inherit = "pms.reservation"
|
||||
@@ -34,7 +36,7 @@ class PmsReservation(models.Model):
|
||||
def create(self, vals):
|
||||
reservation = super(PmsReservation, self).create(vals)
|
||||
if reservation.pms_property_id.institution == "ses":
|
||||
self.create_communication(reservation.id, "A", "RH")
|
||||
self.create_communication(reservation.id, CREATE_OPERATION_CODE, "RH")
|
||||
return reservation
|
||||
|
||||
@api.model
|
||||
@@ -72,14 +74,26 @@ class PmsReservation(models.Model):
|
||||
)
|
||||
|
||||
if state_changed:
|
||||
if vals["state"] == "cancel" and last_communication.operation == "A":
|
||||
self.create_communication(reservation.id, "B", "RH")
|
||||
elif vals["state"] != "cancel" and last_communication.operation == "B":
|
||||
self.create_communication(reservation.id, "A", "RH")
|
||||
if (
|
||||
vals["state"] == "cancel"
|
||||
and last_communication.operation == CREATE_OPERATION_CODE
|
||||
):
|
||||
self.create_communication(
|
||||
reservation.id, DELETE_OPERATION_CODE, "RH"
|
||||
)
|
||||
elif (
|
||||
vals["state"] != "cancel"
|
||||
and last_communication.operation == DELETE_OPERATION_CODE
|
||||
):
|
||||
self.create_communication(
|
||||
reservation.id, CREATE_OPERATION_CODE, "RH"
|
||||
)
|
||||
elif check_changed:
|
||||
if last_communication.operation == "A":
|
||||
self.create_communication(reservation.id, "B", "RH")
|
||||
self.create_communication(reservation.id, "A", "RH")
|
||||
if last_communication.operation == CREATE_OPERATION_CODE:
|
||||
self.create_communication(
|
||||
reservation.id, DELETE_OPERATION_CODE, "RH"
|
||||
)
|
||||
self.create_communication(reservation.id, CREATE_OPERATION_CODE, "RH")
|
||||
|
||||
def write(self, vals):
|
||||
for record in self:
|
||||
|
||||
@@ -30,6 +30,7 @@ XML_OK = "1"
|
||||
XML_PROCESSING = "4"
|
||||
XML_PENDING = "5"
|
||||
|
||||
CREATE_OPERATION_CODE = "A"
|
||||
DELETE_OPERATION_CODE = "B"
|
||||
|
||||
# Disable insecure request warnings
|
||||
@@ -995,12 +996,14 @@ class TravellerReport(models.TransientModel):
|
||||
|
||||
@api.model
|
||||
def ses_send_communications(self, entity):
|
||||
|
||||
for communication in self.env["pms.ses.communication"].search(
|
||||
[
|
||||
("state", "=", "to_send"),
|
||||
("entity", "=", entity),
|
||||
]
|
||||
):
|
||||
|
||||
data = False
|
||||
if communication.entity == "RH":
|
||||
data = self.generate_xml_reservations([communication.reservation_id.id])
|
||||
@@ -1032,7 +1035,7 @@ class TravellerReport(models.TransientModel):
|
||||
result_code = root.find(".//codigo").text
|
||||
if result_code == REQUEST_CODE_OK:
|
||||
communication.communication_id = root.find(".//lote").text
|
||||
if communication.operation == "A":
|
||||
if communication.operation == CREATE_OPERATION_CODE:
|
||||
communication.state = "to_process"
|
||||
else:
|
||||
communication.state = "processed"
|
||||
@@ -1125,6 +1128,6 @@ class TravellerReport(models.TransientModel):
|
||||
).unlink()
|
||||
self.env["pms.reservation"].create_communication(
|
||||
reservation.id,
|
||||
"A",
|
||||
CREATE_OPERATION_CODE,
|
||||
"PV",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user