mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF]pms: refactoring iteration of folios in send mail
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import datetime
|
||||||
from itertools import groupby
|
from itertools import groupby
|
||||||
|
|
||||||
from odoo import _, api, fields, models
|
from odoo import _, api, fields, models
|
||||||
@@ -513,6 +514,13 @@ class PmsFolio(models.Model):
|
|||||||
compute="_compute_last_checkout",
|
compute="_compute_last_checkout",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
date_creation = fields.Date(
|
||||||
|
string="Creation Date",
|
||||||
|
readonly=False,
|
||||||
|
store=True,
|
||||||
|
compute="_compute_date_creation",
|
||||||
|
)
|
||||||
|
|
||||||
def name_get(self):
|
def name_get(self):
|
||||||
result = []
|
result = []
|
||||||
for folio in self:
|
for folio in self:
|
||||||
@@ -1088,6 +1096,12 @@ class PmsFolio(models.Model):
|
|||||||
checkouts = record.reservation_ids.mapped("checkout")
|
checkouts = record.reservation_ids.mapped("checkout")
|
||||||
record.last_checkout = max(checkouts)
|
record.last_checkout = max(checkouts)
|
||||||
|
|
||||||
|
@api.depends("create_date")
|
||||||
|
def _compute_date_creation(self):
|
||||||
|
for record in self:
|
||||||
|
if record.create_date:
|
||||||
|
record.date_creation = datetime.strftime(record.create_date, "%Y-%m-%d")
|
||||||
|
|
||||||
def _search_invoice_ids(self, operator, value):
|
def _search_invoice_ids(self, operator, value):
|
||||||
if operator == "in" and value:
|
if operator == "in" and value:
|
||||||
self.env.cr.execute(
|
self.env.cr.execute(
|
||||||
@@ -1286,125 +1300,98 @@ class PmsFolio(models.Model):
|
|||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def send_confirmation_mail(self):
|
def send_confirmation_mail(self):
|
||||||
folios = self.env["pms.folio"].search([])
|
today = fields.Date.today()
|
||||||
if folios and all(
|
folios = self.env["pms.folio"].search(
|
||||||
is_confirmed_auto_mail
|
[
|
||||||
for is_confirmed_auto_mail in folios.pms_property_id.mapped(
|
("pms_property_id.is_confirmed_auto_mail", "=", True),
|
||||||
"is_confirmed_auto_mail"
|
("reservation_ids.is_mail_send", "=", False),
|
||||||
)
|
("reservation_ids.is_modified_reservation", "=", False),
|
||||||
):
|
("date_creation", "=", today),
|
||||||
for folio in folios:
|
]
|
||||||
create_date = folio.create_date.date()
|
)
|
||||||
if (
|
for folio in folios:
|
||||||
folio.state in "confirm"
|
if folio.email:
|
||||||
and create_date == fields.Date.today()
|
template = folio.pms_property_id.property_confirmed_template
|
||||||
and all(
|
subject = template._render_field(
|
||||||
not mail_send
|
"subject",
|
||||||
for mail_send in folio.reservation_ids.mapped("is_mail_send")
|
[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,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
and all(
|
)
|
||||||
not is_modified_reservation
|
mail.send()
|
||||||
for is_modified_reservation in folio.reservation_ids.mapped(
|
for reservation in folio.reservation_ids:
|
||||||
"is_modified_reservation"
|
reservation.is_mail_send = True
|
||||||
)
|
|
||||||
)
|
|
||||||
):
|
|
||||||
template = folio.pms_property_id.property_confirmed_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]
|
|
||||||
invitation_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,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
invitation_mail.send()
|
|
||||||
for reservation in folio.reservation_ids:
|
|
||||||
reservation.is_mail_send = True
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def send_modification_mail(self):
|
def send_modification_mail(self):
|
||||||
folios = self.env["pms.folio"].search([])
|
folios = self.env["pms.folio"].search(
|
||||||
if folios and all(
|
[
|
||||||
is_modified_auto_mail
|
("pms_property_id.is_modified_auto_mail", "=", True),
|
||||||
for is_modified_auto_mail in folios.pms_property_id.mapped(
|
("reservation_ids.is_mail_send", "=", False),
|
||||||
"is_modified_auto_mail"
|
("reservation_ids.is_modified_reservation", "=", True),
|
||||||
)
|
]
|
||||||
):
|
)
|
||||||
for folio in folios:
|
for folio in folios:
|
||||||
if (
|
if folio.email:
|
||||||
folio.state in ("confirm", "onboard")
|
template = folio.pms_property_id.property_modified_template
|
||||||
and any(
|
subject = template._render_field(
|
||||||
not mail_send
|
"subject",
|
||||||
for mail_send in folio.reservation_ids.mapped("is_mail_send")
|
[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,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
and any(
|
)
|
||||||
is_modified_reservation
|
mail.send()
|
||||||
for is_modified_reservation in folio.reservation_ids.mapped(
|
for reservation in folio.reservation_ids:
|
||||||
"is_modified_reservation"
|
reservation.is_mail_send = True
|
||||||
)
|
|
||||||
)
|
|
||||||
):
|
|
||||||
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]
|
|
||||||
invitation_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,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
invitation_mail.send()
|
|
||||||
for reservation in folio.reservation_ids:
|
|
||||||
reservation.is_mail_send = True
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def send_cancelation_mail(self):
|
def send_cancelation_mail(self):
|
||||||
folios = self.env["pms.folio"].search([])
|
folios = self.env["pms.folio"].search(
|
||||||
if folios and all(
|
[("pms_property_id.is_canceled_auto_mail", "=", True)]
|
||||||
is_canceled_auto_mail
|
)
|
||||||
for is_canceled_auto_mail in folios.pms_property_id.mapped(
|
for folio in folios:
|
||||||
"is_canceled_auto_mail"
|
reservations = folio.reservation_ids.filtered(lambda r: r.state in "cancel")
|
||||||
)
|
for reservation in reservations:
|
||||||
):
|
if folio.email:
|
||||||
for folio in folios:
|
if (
|
||||||
reservations = folio.reservation_ids.filtered(
|
not reservation.is_mail_send
|
||||||
lambda r: r.state in "cancel"
|
and reservation.email
|
||||||
)
|
and reservation.state not in "out"
|
||||||
for reservation in reservations:
|
):
|
||||||
if not reservation.is_mail_send:
|
|
||||||
template = (
|
template = (
|
||||||
reservation.pms_property_id.property_canceled_template
|
reservation.pms_property_id.property_canceled_template
|
||||||
)
|
)
|
||||||
@@ -1420,7 +1407,7 @@ class PmsFolio(models.Model):
|
|||||||
compute_lang=True,
|
compute_lang=True,
|
||||||
post_process=True,
|
post_process=True,
|
||||||
)[reservation.id]
|
)[reservation.id]
|
||||||
invitation_mail = (
|
mail = (
|
||||||
folio.env["mail.mail"]
|
folio.env["mail.mail"]
|
||||||
.sudo()
|
.sudo()
|
||||||
.create(
|
.create(
|
||||||
@@ -1428,13 +1415,12 @@ class PmsFolio(models.Model):
|
|||||||
"subject": subject,
|
"subject": subject,
|
||||||
"body_html": body,
|
"body_html": body,
|
||||||
"email_from": folio.pms_property_id.partner_id.email,
|
"email_from": folio.pms_property_id.partner_id.email,
|
||||||
"email_to": folio.email,
|
"email_to": reservation.email,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
invitation_mail.send()
|
mail.send()
|
||||||
for reservation in folio.reservation_ids:
|
reservation.is_mail_send = True
|
||||||
reservation.is_mail_send = True
|
|
||||||
|
|
||||||
def action_view_invoice(self):
|
def action_view_invoice(self):
|
||||||
invoices = self.mapped("move_ids")
|
invoices = self.mapped("move_ids")
|
||||||
|
|||||||
Reference in New Issue
Block a user