Skip to content

Commit

Permalink
Merge PR #299 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by DarioLodeiros
  • Loading branch information
OCA-git-bot committed Dec 2, 2024
2 parents 0877438 + c0fb76e commit cd0d451
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 131 deletions.
4 changes: 2 additions & 2 deletions pms_l10n_es/data/cron_jobs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
SES Automatic Sending Pending Traveller Reports Communications
</field>
<field name="active" eval="False" />
<field name="interval_number">1</field>
<field name="interval_number">30</field>
<field name="user_id" ref="base.user_root" />
<field name="interval_type">days</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field name="doall" eval="False" />
<field name="state">code</field>
Expand Down
1 change: 0 additions & 1 deletion pms_l10n_es/models/pms_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class PmsProperty(models.Model):
string="Institution lessor id",
help="Id provided by institution to send data from lessor.",
)

ine_tourism_number = fields.Char(
"Tourism number",
help="Registration number in the Ministry of Tourism. Used for INE statistics.",
Expand Down
69 changes: 68 additions & 1 deletion pms_l10n_es/models/pms_reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,77 @@ class PmsReservation(models.Model):
string="Is SES",
readonly=True,
compute="_compute_is_ses",
store=True,
)
ses_status_reservation = fields.Selection(
string="SES Status",
help="Status of the reservation in SES",
selection=[
("not_applicable", "Not Applicable"),
("to_send", "Pending Notification"),
("to_process", "Pending Processing"),
("error_create", "Error Creating"),
("error_sending", "Error Sending"),
("error_processing", "Error Processing"),
("processed", "Processed"),
],
compute="_compute_ses_status_reservation",
store=True,
)
ses_status_traveller_report = fields.Selection(
string="SES Status traveller",
help="Status of the traveller report in SES",
selection=[
("not_applicable", "Not Applicable"),
("incomplete", "Incomplete checkin data"),
("to_send", "Pending Notification"),
("to_process", "Pending Processing"),
("error_create", "Error Creating"),
("error_sending", "Error Sending"),
("error_processing", "Error Processing"),
("processed", "Processed"),
],
compute="_compute_ses_status_traveller_report",
store=True,
)

@api.depends("pms_property_id")
def _compute_is_ses(self):
for record in self:
record.is_ses = record.pms_property_id.institution == "ses"

@api.depends("ses_communication_ids", "ses_communication_ids.state")
def _compute_ses_status_reservation(self):
for record in self:
if record.pms_property_id.institution != "ses":
record.ses_status_reservation = "not_applicable"
continue
communication = record.ses_communication_ids.filtered(
lambda x: x.entity == "RH"
)
if len(communication) > 1:
# get the last communication
communication = communication.sorted(key=lambda x: x.create_date)[-1]
record.ses_status_reservation = (
communication.state if communication else "error_create"
)

@api.depends("ses_communication_ids", "ses_communication_ids.state")
def _compute_ses_status_traveller_report(self):
for record in self:
if record.pms_property_id.institution != "ses":
record.ses_status_traveller_report = "not_applicable"
continue
communication = record.ses_communication_ids.filtered(
lambda x: x.entity == "PV"
)
if len(communication) > 1:
# get the last communication
communication = communication.sorted(key=lambda x: x.create_date)[-1]
record.ses_status_traveller_report = (
communication.state if communication else "error_create"
)

@api.model
def create_communication(self, reservation_id, operation, entity):
self.env["pms.ses.communication"].create(
Expand Down Expand Up @@ -100,6 +164,9 @@ def create_communication_after_update_reservation(self, reservation, vals):

def write(self, vals):
for record in self:
if record.pms_property_id.institution == "ses":
if (
record.pms_property_id.institution == "ses"
and record.reservation_type != "out"
):
self.create_communication_after_update_reservation(record, vals)
return super(PmsReservation, self).write(vals)
19 changes: 17 additions & 2 deletions pms_l10n_es/models/pms_ses_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,23 @@
class PmsSesCommunication(models.Model):
_name = "pms.ses.communication"
_description = "SES Communication"
_order = "create_date desc"

reservation_id = fields.Many2one(
string="Reservation",
help="Reservation related to this communication",
index=True,
required=True,
comodel_name="pms.reservation",
)
pms_property_id = fields.Many2one(
comodel_name="pms.property",
string="Property",
help="Property related to this communication",
related="reservation_id.pms_property_id",
index=True,
store=True,
)
communication_id = fields.Char(
string="Communication ID",
help="ID of the communication",
Expand All @@ -37,7 +47,6 @@ class PmsSesCommunication(models.Model):
string="Query status time",
help="Date and time of the last state query",
)

state = fields.Selection(
string="State",
help="State of the communication",
Expand All @@ -52,7 +61,6 @@ class PmsSesCommunication(models.Model):
("processed", "Processed"),
],
)

sending_result = fields.Text(
string="Sending Result",
help="Notification sending result",
Expand Down Expand Up @@ -86,3 +94,10 @@ class PmsSesCommunication(models.Model):
string="SOAP Resp. Status",
help="SOAP response status query",
)

def force_send_communication(self):
for record in self:
self.env["traveller.report.wizard"].ses_send_communication(
entity=record.entity,
communication_id=record.communication_id,
)
62 changes: 0 additions & 62 deletions pms_l10n_es/tests/test_pms_ses_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,65 +221,3 @@ def test_create_notification_when_modify_reservation_and_is_sent(self):
reservation_communications,
"Update adults should create 2 notifications with operations A and B",
)

def test_create_notification_when_checkin_partner_on_board(self):
# ARRANGE
partner = self.env["res.partner"].create(
{
"name": "name test",
"firstname": "firstname test",
"lastname": "lastname test",
"lastname2": "lastname2 test",
"birthdate_date": "1995-12-10",
"gender": "male",
"nationality_id": self.env.ref("base.es").id,
"residence_street": "street test",
"residence_city": "city test",
"residence_zip": "zip test",
"residence_country_id": self.env.ref("base.us").id,
}
)
reservation = self.env["pms.reservation"].create(
{
"pms_property_id": self.pms_property1.id,
"room_type_id": self.room_type.id,
"checkin": fields.date.today(),
"checkout": fields.date.today() + datetime.timedelta(days=13),
"adults": 1,
"children": 0,
"sale_channel_origin_id": self.sale_channel_direct1.id,
"partner_name": "Test reservation",
}
)
document_type_dni = self.env["res.partner.id_category"].search(
[("code", "=", "D")], limit=1
)
checkin_partner = self.env["pms.checkin.partner"].create(
{
"reservation_id": reservation.id,
"partner_id": partner.id,
"document_number": "11111111H",
"document_type": document_type_dni.id,
"document_expedition_date": fields.date.today()
+ datetime.timedelta(days=1),
"support_number": "123456",
}
)
checkin_partner.action_on_board()
# ACT
self.env[
"traveller.report.wizard"
].create_pending_notifications_traveller_report()
# ASSERT
last_notification = self.env["pms.ses.communication"].search(
[
("reservation_id", "=", reservation.id),
("operation", "=", "A"),
("state", "=", "to_send"),
("entity", "=", "PV"),
],
)
self.assertTrue(
last_notification,
"Notification should be created when checkin partner is on board",
)
87 changes: 81 additions & 6 deletions pms_l10n_es/views/pms_ses_communication_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@
<field name="name">pms.ses.communication.tree</field>
<field name="model">pms.ses.communication</field>
<field name="arch" type="xml">
<tree name="Property Ubications" create="false">
<tree
name="Property Ubications"
create="false"
decoration-danger="state in ('error_sending', 'error_processing')"
decoration-muted="state=='processed'"
decoration-info="state=='incomplete'"
decoration-success="state=='to_process'"
>
<field name="pms_property_id" />
<field name="reservation_id" />
<field name="communication_id" />
<field name="operation" />
Expand All @@ -64,17 +72,84 @@
<field name="model">pms.ses.communication</field>
<field name="arch" type="xml">
<search string="Log SES Communications">
<field name="pms_property_id" widget="selection" />
<field name="communication_id" />
<field name="reservation_id" />
<!-- times -->
<field name="create_date" />
<field name="communication_time" />
<field name="query_status_time" />
<field name="state" />
<!-- filters -->
<separator string="Results" colspan="4" />
<filter
string="To Process"
name="to_process"
domain="[('state', '=', 'to_process')]"
/>
<filter
string="Processed"
name="processed"
domain="[('state', '=', 'processed')]"
/>
<filter
string="Error Sending"
name="error_sending"
domain="[('state', '=', 'error_sending')]"
/>
<filter
string="Error Processing"
name="error_processing"
domain="[('state', '=', 'error_processing')]"
/>
<filter
string="Wait checkins"
name="incomplete"
domain="[('state', '=', 'incomplete')]"
/>
<separator string="Times" colspan="4" />
<filter
string="Today"
name="today"
domain="[('create_date', '&gt;=', (context_today() + ' 00:00:00'))]"
/>
<filter
string="This Week"
name="this_week"
domain="[('create_date', '&gt;=', (context_today() + ' 00:00:00'))]"
/>
<filter
string="This Month"
name="this_month"
domain="[('create_date', '&gt;=', (context_today() + ' 00:00:00'))]"
/>
<!-- groups -->
<group expand="0" string="Group By">
<filter
name="group_by_pms_property_id"
string="Property"
context="{'group_by': 'pms_property_id'}"
/>
<filter
name="group_by_state"
string="State"
context="{'group_by': 'state'}"
/>
</group>
</search>
</field>
</record>

<!-- action to force_send_communication -->
<record
model="ir.actions.server"
id="pms_ses_communication_force_send_communication"
>
<field name="name">Force Send Communication</field>
<field name="model_id" ref="model_pms_ses_communication" />
<field name="state">code</field>
<field name="code">
records.force_send_communication()
</field>
<field name="binding_model_id" ref="model_pms_ses_communication" />
<field name="binding_view_types">form,list</field>
</record>

<record model="ir.actions.act_window" id="open_pms_ses_communication_form_tree">
<field name="name">SES Communications</field>
<field name="res_model">pms.ses.communication</field>
Expand Down
Loading

0 comments on commit cd0d451

Please sign in to comment.