mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
@@ -4,7 +4,7 @@
|
||||
{
|
||||
"name": "PMS (Property Management System)",
|
||||
"summary": "A property management system",
|
||||
"version": "14.0.2.23.0",
|
||||
"version": "14.0.2.22.1",
|
||||
"development_status": "Alpha",
|
||||
"category": "Generic Modules/Property Management System",
|
||||
"website": "https://github.com/OCA/pms",
|
||||
|
||||
2
pms/migrations/14.0.2.22.1/post-migrate.py
Normal file
2
pms/migrations/14.0.2.22.1/post-migrate.py
Normal file
@@ -0,0 +1,2 @@
|
||||
def migrate(cr, version):
|
||||
cr.execute("UPDATE pms_reservation SET to_send_mail = NOT is_mail_send")
|
||||
@@ -21,19 +21,6 @@ class MailComposeMessage(models.TransientModel):
|
||||
return res
|
||||
|
||||
def send_mail(self, auto_commit=False):
|
||||
# if (
|
||||
# self._context.get("default_model") == "pms.folio"
|
||||
# and self._context.get("default_res_id")
|
||||
# and self._context.get("mark_so_as_sent")
|
||||
# ):
|
||||
# # TODO: WorkFlow Mails
|
||||
# folio = self.env["pms.folio"].browse([self._context["default_res_id"]])
|
||||
# if folio:
|
||||
# cmds = [
|
||||
# (1, lid, {"to_send": False}) for lid in folio.reservation_ids.ids
|
||||
# ]
|
||||
# if any(cmds):
|
||||
# folio.reservation_ids = cmds
|
||||
res = super(MailComposeMessage, self).send_mail(auto_commit=auto_commit)
|
||||
if self._context.get("record_id"):
|
||||
folio = self.env["pms.folio"].search(
|
||||
@@ -41,5 +28,5 @@ class MailComposeMessage(models.TransientModel):
|
||||
)
|
||||
reservations = folio.reservation_ids
|
||||
for reservation in reservations:
|
||||
reservation.is_mail_send = True
|
||||
reservation.to_send_mail = False
|
||||
return res
|
||||
|
||||
@@ -9,6 +9,8 @@ from odoo import _, api, fields, models
|
||||
from odoo.exceptions import AccessError, UserError, ValidationError
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
from odoo.addons.base.models.ir_mail_server import MailDeliveryException
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -1286,125 +1288,124 @@ class PmsFolio(models.Model):
|
||||
|
||||
@api.model
|
||||
def send_confirmation_mail(self):
|
||||
folios = self.env["pms.folio"].search([])
|
||||
if folios and all(
|
||||
is_confirmed_auto_mail
|
||||
for is_confirmed_auto_mail in folios.pms_property_id.mapped(
|
||||
"is_confirmed_auto_mail"
|
||||
)
|
||||
):
|
||||
for folio in folios:
|
||||
create_date = folio.create_date.date()
|
||||
if (
|
||||
folio.state in "confirm"
|
||||
and create_date == fields.Date.today()
|
||||
and all(
|
||||
not mail_send
|
||||
for mail_send in folio.reservation_ids.mapped("is_mail_send")
|
||||
folios = self.env["pms.folio"].search(
|
||||
[
|
||||
("pms_property_id.is_confirmed_auto_mail", "=", True),
|
||||
("reservation_ids.to_send_mail", "=", True),
|
||||
("reservation_ids.is_modified_reservation", "=", False),
|
||||
("reservation_ids.state", "!=", "cancel"),
|
||||
]
|
||||
)
|
||||
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,
|
||||
}
|
||||
)
|
||||
and all(
|
||||
not is_modified_reservation
|
||||
for is_modified_reservation in folio.reservation_ids.mapped(
|
||||
"is_modified_reservation"
|
||||
)
|
||||
)
|
||||
try:
|
||||
mail.send()
|
||||
except MailDeliveryException:
|
||||
self.env["ir.logging"].create(
|
||||
{
|
||||
"name": "Failed to send confirmation email to "
|
||||
+ folio.email,
|
||||
"type": "server",
|
||||
"path": "pms/pms/models/pms_folio.py",
|
||||
"line": "1339",
|
||||
"func": "send_confirmation_email",
|
||||
"message": "Confirmation Mail Delivery Failed",
|
||||
}
|
||||
)
|
||||
):
|
||||
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
|
||||
for reservation in folio.reservation_ids:
|
||||
reservation.to_send_mail = False
|
||||
|
||||
@api.model
|
||||
def send_modification_mail(self):
|
||||
folios = self.env["pms.folio"].search([])
|
||||
if folios and all(
|
||||
is_modified_auto_mail
|
||||
for is_modified_auto_mail in folios.pms_property_id.mapped(
|
||||
"is_modified_auto_mail"
|
||||
)
|
||||
):
|
||||
for folio in folios:
|
||||
if (
|
||||
folio.state in ("confirm", "onboard")
|
||||
and any(
|
||||
not mail_send
|
||||
for mail_send in folio.reservation_ids.mapped("is_mail_send")
|
||||
folios = self.env["pms.folio"].search(
|
||||
[
|
||||
("pms_property_id.is_modified_auto_mail", "=", True),
|
||||
("reservation_ids.to_send_mail", "=", True),
|
||||
("reservation_ids.is_modified_reservation", "=", True),
|
||||
("reservation_ids.state", "!=", "cancel"),
|
||||
]
|
||||
)
|
||||
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,
|
||||
}
|
||||
)
|
||||
and any(
|
||||
is_modified_reservation
|
||||
for is_modified_reservation in folio.reservation_ids.mapped(
|
||||
"is_modified_reservation"
|
||||
)
|
||||
)
|
||||
try:
|
||||
mail.send()
|
||||
except MailDeliveryException:
|
||||
self.env["ir.logging"].create(
|
||||
{
|
||||
"name": "Failed to send modification email to "
|
||||
+ folio.email,
|
||||
"type": "server",
|
||||
"path": "pms/pms/models/pms_folio.py",
|
||||
"line": "1391",
|
||||
"func": "send_modification_email",
|
||||
"message": "Modification Mail Delivery Failed",
|
||||
}
|
||||
)
|
||||
):
|
||||
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
|
||||
for reservation in folio.reservation_ids:
|
||||
reservation.to_send_mail = False
|
||||
|
||||
@api.model
|
||||
def send_cancelation_mail(self):
|
||||
folios = self.env["pms.folio"].search([])
|
||||
if folios and all(
|
||||
is_canceled_auto_mail
|
||||
for is_canceled_auto_mail in folios.pms_property_id.mapped(
|
||||
"is_canceled_auto_mail"
|
||||
)
|
||||
):
|
||||
for folio in folios:
|
||||
reservations = folio.reservation_ids.filtered(
|
||||
lambda r: r.state in "cancel"
|
||||
)
|
||||
for reservation in reservations:
|
||||
if not reservation.is_mail_send:
|
||||
folios = self.env["pms.folio"].search(
|
||||
[("pms_property_id.is_canceled_auto_mail", "=", True)]
|
||||
)
|
||||
for folio in folios:
|
||||
reservations = folio.reservation_ids.filtered(lambda r: r.state in "cancel")
|
||||
for reservation in reservations:
|
||||
if reservation.email:
|
||||
if (
|
||||
not reservation.to_send_mail
|
||||
and reservation.email
|
||||
and reservation.state not in "out"
|
||||
):
|
||||
template = (
|
||||
reservation.pms_property_id.property_canceled_template
|
||||
)
|
||||
@@ -1420,7 +1421,7 @@ class PmsFolio(models.Model):
|
||||
compute_lang=True,
|
||||
post_process=True,
|
||||
)[reservation.id]
|
||||
invitation_mail = (
|
||||
mail = (
|
||||
folio.env["mail.mail"]
|
||||
.sudo()
|
||||
.create(
|
||||
@@ -1428,13 +1429,25 @@ class PmsFolio(models.Model):
|
||||
"subject": subject,
|
||||
"body_html": body,
|
||||
"email_from": folio.pms_property_id.partner_id.email,
|
||||
"email_to": folio.email,
|
||||
"email_to": reservation.email,
|
||||
}
|
||||
)
|
||||
)
|
||||
invitation_mail.send()
|
||||
for reservation in folio.reservation_ids:
|
||||
reservation.is_mail_send = True
|
||||
try:
|
||||
mail.send()
|
||||
except MailDeliveryException:
|
||||
self.env["ir.logging"].create(
|
||||
{
|
||||
"name": "Failed to send cancellation email to "
|
||||
+ reservation.email,
|
||||
"type": "server",
|
||||
"path": "pms/pms/models/pms_folio.py",
|
||||
"line": "1450",
|
||||
"func": "send_cancelation_email",
|
||||
"message": "Cancellation Mail Delivery Failed",
|
||||
}
|
||||
)
|
||||
reservation.to_send_mail = False
|
||||
|
||||
def action_view_invoice(self):
|
||||
invoices = self.mapped("move_ids")
|
||||
|
||||
@@ -643,7 +643,12 @@ class PmsReservation(models.Model):
|
||||
comodel_name="res.partner",
|
||||
inverse_name="reservation_possible_customer_id",
|
||||
)
|
||||
is_mail_send = fields.Boolean(string="Mail Sent", default=False)
|
||||
to_send_mail = fields.Boolean(
|
||||
string="Mail Sent",
|
||||
compute="_compute_to_send_mail",
|
||||
readonly=False,
|
||||
store=True,
|
||||
)
|
||||
|
||||
is_modified_reservation = fields.Boolean(
|
||||
string="Is A Modified Reservation",
|
||||
@@ -1470,9 +1475,9 @@ class PmsReservation(models.Model):
|
||||
for record in self:
|
||||
if record.state in "draft":
|
||||
record.is_modified_reservation = False
|
||||
elif record.state in ("confirm", "onboard") and record.is_mail_send:
|
||||
elif record.state in ("confirm", "onboard") and not record.to_send_mail:
|
||||
record.is_modified_reservation = True
|
||||
record.is_mail_send = False
|
||||
record.to_send_mail = True
|
||||
else:
|
||||
record.is_modified_reservation = False
|
||||
|
||||
@@ -1484,6 +1489,14 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
record.lang = self.env["res.lang"].get_installed()
|
||||
|
||||
@api.depends("reservation_type")
|
||||
def _compute_to_send_mail(self):
|
||||
for record in self:
|
||||
if record.reservation_type == "out":
|
||||
record.to_send_mail = False
|
||||
else:
|
||||
record.to_send_mail = True
|
||||
|
||||
def _search_allowed_checkin(self, operator, value):
|
||||
if operator not in ("=",):
|
||||
raise UserError(
|
||||
@@ -1730,20 +1743,20 @@ class PmsReservation(models.Model):
|
||||
template = False
|
||||
pms_property = self.pms_property_id
|
||||
if (
|
||||
not self.is_mail_send
|
||||
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 (
|
||||
not self.is_mail_send
|
||||
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 not self.is_mail_send and self.state in "cancel":
|
||||
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(
|
||||
@@ -1931,7 +1944,7 @@ class PmsReservation(models.Model):
|
||||
else:
|
||||
record.state = "cancel"
|
||||
record.folio_id._compute_amount()
|
||||
record.is_mail_send = False
|
||||
record.to_send_mail = True
|
||||
|
||||
def action_assign(self):
|
||||
for record in self:
|
||||
|
||||
@@ -3462,7 +3462,7 @@ class TestPmsReservations(TestPms):
|
||||
----------------------
|
||||
A reservation is created. The checkin and checkout fields of
|
||||
the reservation are modified. The state of the boolean
|
||||
is_mail_send is changed to True so that the compute of
|
||||
to_send_mail is changed to False so that the compute of
|
||||
the is_modified_reservation field is activated correctly
|
||||
and it is verified that the state of this field is True.
|
||||
"""
|
||||
@@ -3482,7 +3482,7 @@ class TestPmsReservations(TestPms):
|
||||
# ACT
|
||||
writed_checkin = fields.date.today() + datetime.timedelta(days=4)
|
||||
writed_checkout = fields.date.today() + datetime.timedelta(days=6)
|
||||
reservation.is_mail_send = True
|
||||
reservation.to_send_mail = False
|
||||
reservation.update(
|
||||
{
|
||||
"checkin": writed_checkin,
|
||||
|
||||
@@ -47,22 +47,22 @@
|
||||
name="action_open_mail_composer"
|
||||
string="Send Confirmation Email "
|
||||
type="object"
|
||||
attrs="{'invisible':['|','|',('is_mail_send', '=', True),('is_modified_reservation', '=', True),('state', 'in', 'cancel')]}"
|
||||
attrs="{'invisible':['|','|',('to_send_mail', '=', False),('is_modified_reservation', '=', True),('state', 'in', 'cancel')]}"
|
||||
/>
|
||||
<button
|
||||
name="action_open_mail_composer"
|
||||
string="Send Modification Email "
|
||||
type="object"
|
||||
attrs="{'invisible':['|','|',('is_mail_send', '=', True), ('is_modified_reservation', '=', False), ('state', 'in', 'cancel')]}"
|
||||
attrs="{'invisible':['|','|',('to_send_mail', '=', False), ('is_modified_reservation', '=', False), ('state', 'in', 'cancel')]}"
|
||||
/>
|
||||
<button
|
||||
name="action_open_mail_composer"
|
||||
string="Send Cancellation Email "
|
||||
type="object"
|
||||
attrs="{'invisible':['|',('is_mail_send', '=', True), ('state', 'not in', 'cancel')]}"
|
||||
attrs="{'invisible':['|',('to_send_mail', '=', False), ('state', 'not in', 'cancel')]}"
|
||||
/>
|
||||
<field name="state" widget="statusbar" />
|
||||
<field name="is_mail_send" invisible="1" />
|
||||
<field name="to_send_mail" invisible="1" />
|
||||
<field name="is_modified_reservation" invisible="1" />
|
||||
</header>
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user