From deaacd15bfac9c81911cad8c4ca2e267b81cbbb7 Mon Sep 17 00:00:00 2001 From: braisab Date: Thu, 10 Feb 2022 21:09:26 +0100 Subject: [PATCH 1/5] [REF]pms: changed open_mail_composer method from reservation to folio --- pms/models/mail_compose_message.py | 1 + pms/models/pms_folio.py | 62 ++++++++++++++++++++++++++++++ pms/models/pms_reservation.py | 45 +--------------------- 3 files changed, 64 insertions(+), 44 deletions(-) diff --git a/pms/models/mail_compose_message.py b/pms/models/mail_compose_message.py index 3f2070e04..a3aa5b433 100644 --- a/pms/models/mail_compose_message.py +++ b/pms/models/mail_compose_message.py @@ -13,6 +13,7 @@ class MailComposeMessage(models.TransientModel): template = self.env["mail.template"].browse(self._context.get("template_id")) res.update( { + "model": "pms.folio", "composition_mode": "comment", "attachment_ids": False, "template_id": template.id, diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index a30755692..949658ab9 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -1429,6 +1429,68 @@ class PmsFolio(models.Model): ) reservation.to_send_mail = False + def action_open_mail_composer(self): + self.ensure_one() + template = False + pms_property = self.pms_property_id + if ( + all(reservation.to_send_mail for reservation in self.reservation_ids) + and not all( + reservation.is_modified_reservation + for reservation in self.reservation_ids + ) + and all( + reservation.state not in "cancel" + for reservation in self.reservation_ids + ) + ): + if pms_property.property_confirmed_template: + template = pms_property.property_confirmed_template + elif ( + any(reservation.to_send_mail for reservation in self.reservation_ids) + and any( + reservation.is_modified_reservation + for reservation in self.reservation_ids + ) + and all( + reservation.state not in "cancel" + for reservation in self.reservation_ids + ) + ): + if pms_property.property_modified_template: + template = pms_property.property_modified_template + elif any( + reservation.to_send_mail for reservation in self.reservation_ids + ) and any( + reservation.state in "cancel" for reservation in self.reservation_ids + ): + if pms_property.property_canceled_template: + template = pms_property.property_canceled_template + compose_form = self.env.ref( + "mail.email_compose_message_wizard_form", raise_if_not_found=False + ) + ctx = dict( + model="pms.folio", + default_res_model="pms.folio", + default_res_id=self.id, + template_id=template and template.id or False, + composition_mode="comment", + partner_ids=[self.partner_id.id], + force_email=True, + record_id=self.id, + ) + return { + "name": _("Send Mail "), + "type": "ir.actions.act_window", + "view_type": "form", + "view_mode": "form", + "res_model": "mail.compose.message", + "views": [(compose_form.id, "form")], + "view_id": compose_form.id, + "target": "new", + "context": ctx, + } + def action_view_invoice(self): invoices = self.mapped("move_ids") action = self.env["ir.actions.actions"]._for_xml_id( diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index f12562c45..c6d14ab2d 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -1743,50 +1743,7 @@ class PmsReservation(models.Model): } def action_open_mail_composer(self): - self.ensure_one() - template = False - pms_property = self.pms_property_id - if ( - self.to_send_mail - and not self.is_modified_reservation - and self.state not in "cancel" - ): - if pms_property.property_confirmed_template: - template = pms_property.property_confirmed_template - elif ( - self.to_send_mail - and self.is_modified_reservation - and self.state not in "cancel" - ): - if pms_property.property_modified_template: - template = pms_property.property_modified_template - elif self.to_send_mail and self.state in "cancel": - if pms_property.property_canceled_template: - template = pms_property.property_canceled_template - compose_form = self.env.ref( - "mail.email_compose_message_wizard_form", raise_if_not_found=False - ) - ctx = dict( - model="pms.folio", - default_res_model="pms.folio", - default_res_id=self.folio_id.id, - template_id=template and template.id or False, - composition_mode="comment", - partner_ids=[self.partner_id.id], - force_email=True, - record_id=self.folio_id.id, - ) - return { - "name": _("Send Confirmed Reservation Mail "), - "type": "ir.actions.act_window", - "view_type": "form", - "view_mode": "form", - "res_model": "mail.compose.message", - "views": [(compose_form.id, "form")], - "view_id": compose_form.id, - "target": "new", - "context": ctx, - } + return self.folio_id.action_open_mail_composer() def open_wizard_several_partners(self): ctx = dict( From 92951b1fed54039b19e4b88c90cdb811a62e9db5 Mon Sep 17 00:00:00 2001 From: braisab Date: Thu, 10 Feb 2022 21:11:59 +0100 Subject: [PATCH 2/5] [REF]pms: refactored send auto mail methods --- pms/models/pms_folio.py | 82 +++-------------------------------------- 1 file changed, 6 insertions(+), 76 deletions(-) diff --git a/pms/models/pms_folio.py b/pms/models/pms_folio.py index 949658ab9..7aba17aa5 100644 --- a/pms/models/pms_folio.py +++ b/pms/models/pms_folio.py @@ -1279,30 +1279,8 @@ class PmsFolio(models.Model): for folio in folios: if folio.email and folio.create_date.date() == fields.Date.today(): template = folio.pms_property_id.property_confirmed_template - subject = template._render_field( - "subject", - [6, 0, folio.id], - compute_lang=True, - )[folio.id] - body = template._render_field( - "body_html", - [6, 0, folio.id], - compute_lang=True, - )[folio.id] - mail = ( - folio.env["mail.mail"] - .sudo() - .create( - { - "subject": subject, - "body_html": body, - "email_from": folio.pms_property_id.partner_id.email, - "email_to": folio.email, - } - ) - ) try: - mail.send() + template.send_mail(folio.id, force_send=True) except MailDeliveryException: self.env["ir.logging"].create( { @@ -1310,7 +1288,7 @@ class PmsFolio(models.Model): + folio.email, "type": "server", "path": "pms/pms/models/pms_folio.py", - "line": "1339", + "line": "1281", "func": "send_confirmation_email", "message": "Confirmation Mail Delivery Failed", } @@ -1331,32 +1309,8 @@ class PmsFolio(models.Model): for folio in folios: if folio.email: template = folio.pms_property_id.property_modified_template - subject = template._render_field( - "subject", - [6, 0, folio.id], - compute_lang=True, - post_process=True, - )[folio.id] - body = template._render_field( - "body_html", - [6, 0, folio.id], - compute_lang=True, - post_process=True, - )[folio.id] - mail = ( - folio.env["mail.mail"] - .sudo() - .create( - { - "subject": subject, - "body_html": body, - "email_from": folio.pms_property_id.partner_id.email, - "email_to": folio.email, - } - ) - ) try: - mail.send() + template.send_mail(folio.id, force_send=True) except MailDeliveryException: self.env["ir.logging"].create( { @@ -1364,7 +1318,7 @@ class PmsFolio(models.Model): + folio.email, "type": "server", "path": "pms/pms/models/pms_folio.py", - "line": "1391", + "line": "1311", "func": "send_modification_email", "message": "Modification Mail Delivery Failed", } @@ -1389,32 +1343,8 @@ class PmsFolio(models.Model): template = ( reservation.pms_property_id.property_canceled_template ) - subject = template._render_field( - "subject", - [6, 0, reservation.id], - compute_lang=True, - post_process=True, - )[reservation.id] - body = template._render_field( - "body_html", - [6, 0, reservation.id], - compute_lang=True, - post_process=True, - )[reservation.id] - mail = ( - folio.env["mail.mail"] - .sudo() - .create( - { - "subject": subject, - "body_html": body, - "email_from": folio.pms_property_id.partner_id.email, - "email_to": reservation.email, - } - ) - ) try: - mail.send() + template.send_mail(reservation.id, force_send=True) except MailDeliveryException: self.env["ir.logging"].create( { @@ -1422,7 +1352,7 @@ class PmsFolio(models.Model): + reservation.email, "type": "server", "path": "pms/pms/models/pms_folio.py", - "line": "1450", + "line": "1345", "func": "send_cancelation_email", "message": "Cancellation Mail Delivery Failed", } From 8762436554b70b9dc6dcf5e4307077ecb8919bf9 Mon Sep 17 00:00:00 2001 From: braisab Date: Fri, 11 Feb 2022 18:43:24 +0100 Subject: [PATCH 3/5] [REF]: changed object model from reservation to folio in default email templates --- ...s_cancelled_reservation_email_template.xml | 2 +- ...s_confirmed_reservation_email_template.xml | 19 ++++++++++------- ...ms_modified_reservation_email_template.xml | 21 +++++++++++-------- pms/views/pms_reservation_views.xml | 4 ++-- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/pms/data/pms_cancelled_reservation_email_template.xml b/pms/data/pms_cancelled_reservation_email_template.xml index 31ab04cc0..32f1876ed 100644 --- a/pms/data/pms_cancelled_reservation_email_template.xml +++ b/pms/data/pms_cancelled_reservation_email_template.xml @@ -65,7 +65,7 @@
Hello ${object.partner_id.name or ''},
- Your reservation at ${object.pms_property_id.name} has been successfully canceled. + Your reservation at ${object.pms_property_id.name} has been cancelled.
diff --git a/pms/data/pms_confirmed_reservation_email_template.xml b/pms/data/pms_confirmed_reservation_email_template.xml index b4de65eac..35e8273a8 100644 --- a/pms/data/pms_confirmed_reservation_email_template.xml +++ b/pms/data/pms_confirmed_reservation_email_template.xml @@ -3,7 +3,7 @@ Confirmed Reservation - + ${object.company_id.name} has confirmed your reservation in ${object.pms_property_id.name} @@ -116,11 +116,9 @@ style="margin: 16px 0px 16px 0px; font-size: 14px;" >
From ${object.checkin} At ${object.arrival_hour}
+ >From ${object.first_checkin}
To ${object.checkout} At ${object.departure_hour}
+ >To ${object.last_checkout}

Room: ${object.room_type_id.name}
+ >Rooms:
+ % for reservation in object.reservation_ids: + ${reservation.room_type_id.name}
+ % endfor @@ -158,7 +161,7 @@ >
Price: ${object.price_room_services_set} ${object.pms_property_id.country_id.currency_id.symbol}
+ >Price: ${object.amount_total} ${object.pms_property_id.country_id.currency_id.symbol} @@ -205,7 +208,7 @@ diff --git a/pms/data/pms_modified_reservation_email_template.xml b/pms/data/pms_modified_reservation_email_template.xml index 9ca3a0942..6fb107c67 100644 --- a/pms/data/pms_modified_reservation_email_template.xml +++ b/pms/data/pms_modified_reservation_email_template.xml @@ -3,7 +3,7 @@ Modified Reservation - + Your reservation in ${object.pms_property_id.name} has been modified @@ -106,7 +106,7 @@ > - + @@ -158,8 +161,8 @@ style="margin: 16px 0px 16px 0px; font-size: 14px;" >
-
Price: ${object.price_total} ${object.pms_property_id.country_id.currency_id.symbol}
+
Price: ${object.amount_total} ${object.pms_property_id.country_id.currency_id.symbol}
From ${object.checkin} At ${object.arrival_hour}
+ >From ${object.first_checkin}
To ${object.checkout} At ${object.departure_hour}
+ >To ${object.last_checkout}

Room: ${object.room_type_id.name}
+ >Rooms:
+ % for reservation in object.reservation_ids: + ${reservation.room_type_id.name}
+ % endfor
diff --git a/pms/views/pms_reservation_views.xml b/pms/views/pms_reservation_views.xml index 9cf82c060..581403495 100644 --- a/pms/views/pms_reservation_views.xml +++ b/pms/views/pms_reservation_views.xml @@ -1118,7 +1118,7 @@ mail.compose.message form new - + form mail.compose.message form new - + form Date: Fri, 11 Feb 2022 18:56:33 +0100 Subject: [PATCH 4/5] [IMP]pms: hide send mail buttons when reservation_type is out --- pms/views/pms_reservation_views.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pms/views/pms_reservation_views.xml b/pms/views/pms_reservation_views.xml index 581403495..07bb9ad15 100644 --- a/pms/views/pms_reservation_views.xml +++ b/pms/views/pms_reservation_views.xml @@ -47,19 +47,19 @@ name="action_open_mail_composer" string="Send Confirmation Email " type="object" - attrs="{'invisible':['|','|',('to_send_mail', '=', False),('is_modified_reservation', '=', True),('state', 'in', 'cancel')]}" + attrs="{'invisible':['|','|','|',('to_send_mail', '=', False),('is_modified_reservation', '=', True),('state', 'in', 'cancel'),('reservation_type', 'in', 'out')]}" />