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(