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 odoo import api, fields, models
|
||||||
|
|
||||||
|
from ..wizards.traveller_report import CREATE_OPERATION_CODE, DELETE_OPERATION_CODE
|
||||||
|
|
||||||
|
|
||||||
class PmsReservation(models.Model):
|
class PmsReservation(models.Model):
|
||||||
_inherit = "pms.reservation"
|
_inherit = "pms.reservation"
|
||||||
@@ -34,7 +36,7 @@ class PmsReservation(models.Model):
|
|||||||
def create(self, vals):
|
def create(self, vals):
|
||||||
reservation = super(PmsReservation, self).create(vals)
|
reservation = super(PmsReservation, self).create(vals)
|
||||||
if reservation.pms_property_id.institution == "ses":
|
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
|
return reservation
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -72,14 +74,26 @@ class PmsReservation(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if state_changed:
|
if state_changed:
|
||||||
if vals["state"] == "cancel" and last_communication.operation == "A":
|
if (
|
||||||
self.create_communication(reservation.id, "B", "RH")
|
vals["state"] == "cancel"
|
||||||
elif vals["state"] != "cancel" and last_communication.operation == "B":
|
and last_communication.operation == CREATE_OPERATION_CODE
|
||||||
self.create_communication(reservation.id, "A", "RH")
|
):
|
||||||
|
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:
|
elif check_changed:
|
||||||
if last_communication.operation == "A":
|
if last_communication.operation == CREATE_OPERATION_CODE:
|
||||||
self.create_communication(reservation.id, "B", "RH")
|
self.create_communication(
|
||||||
self.create_communication(reservation.id, "A", "RH")
|
reservation.id, DELETE_OPERATION_CODE, "RH"
|
||||||
|
)
|
||||||
|
self.create_communication(reservation.id, CREATE_OPERATION_CODE, "RH")
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
for record in self:
|
for record in self:
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ XML_OK = "1"
|
|||||||
XML_PROCESSING = "4"
|
XML_PROCESSING = "4"
|
||||||
XML_PENDING = "5"
|
XML_PENDING = "5"
|
||||||
|
|
||||||
|
CREATE_OPERATION_CODE = "A"
|
||||||
DELETE_OPERATION_CODE = "B"
|
DELETE_OPERATION_CODE = "B"
|
||||||
|
|
||||||
# Disable insecure request warnings
|
# Disable insecure request warnings
|
||||||
@@ -995,12 +996,14 @@ class TravellerReport(models.TransientModel):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def ses_send_communications(self, entity):
|
def ses_send_communications(self, entity):
|
||||||
|
|
||||||
for communication in self.env["pms.ses.communication"].search(
|
for communication in self.env["pms.ses.communication"].search(
|
||||||
[
|
[
|
||||||
("state", "=", "to_send"),
|
("state", "=", "to_send"),
|
||||||
("entity", "=", entity),
|
("entity", "=", entity),
|
||||||
]
|
]
|
||||||
):
|
):
|
||||||
|
|
||||||
data = False
|
data = False
|
||||||
if communication.entity == "RH":
|
if communication.entity == "RH":
|
||||||
data = self.generate_xml_reservations([communication.reservation_id.id])
|
data = self.generate_xml_reservations([communication.reservation_id.id])
|
||||||
@@ -1032,7 +1035,7 @@ class TravellerReport(models.TransientModel):
|
|||||||
result_code = root.find(".//codigo").text
|
result_code = root.find(".//codigo").text
|
||||||
if result_code == REQUEST_CODE_OK:
|
if result_code == REQUEST_CODE_OK:
|
||||||
communication.communication_id = root.find(".//lote").text
|
communication.communication_id = root.find(".//lote").text
|
||||||
if communication.operation == "A":
|
if communication.operation == CREATE_OPERATION_CODE:
|
||||||
communication.state = "to_process"
|
communication.state = "to_process"
|
||||||
else:
|
else:
|
||||||
communication.state = "processed"
|
communication.state = "processed"
|
||||||
@@ -1125,6 +1128,6 @@ class TravellerReport(models.TransientModel):
|
|||||||
).unlink()
|
).unlink()
|
||||||
self.env["pms.reservation"].create_communication(
|
self.env["pms.reservation"].create_communication(
|
||||||
reservation.id,
|
reservation.id,
|
||||||
"A",
|
CREATE_OPERATION_CODE,
|
||||||
"PV",
|
"PV",
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user