mirror of
https://github.com/OCA/pms.git
synced 2025-01-29 00:17:45 +02:00
[REF]pms: pms_automated_mails model refactoring
This commit is contained in:
@@ -61,11 +61,11 @@ class PmsAutomatedMails(models.Model):
|
||||
string="Moment",
|
||||
help="Moment in relation to the action in which the email will be sent",
|
||||
selection=[
|
||||
("in_act", "In the act"),
|
||||
("before", "Before"),
|
||||
("after", "After"),
|
||||
("in_act", "In the act"),
|
||||
],
|
||||
default="before",
|
||||
default="in_act",
|
||||
)
|
||||
|
||||
active = fields.Boolean(
|
||||
@@ -94,6 +94,9 @@ class PmsAutomatedMails(models.Model):
|
||||
"usage": "ir_cron",
|
||||
"model_id": dict_val["model_id"],
|
||||
}
|
||||
if action == "checkout":
|
||||
code = "record.send_exit_email(" + str(template_id) + ")"
|
||||
action_server_vals.update({"state": "code", "code": code})
|
||||
action_server = self.env["ir.actions.server"].create(action_server_vals)
|
||||
automated_actions_vals = {
|
||||
"active": active,
|
||||
@@ -127,7 +130,7 @@ class PmsAutomatedMails(models.Model):
|
||||
result = super(PmsAutomatedMails, self).write(vals)
|
||||
is_create = False
|
||||
if (
|
||||
self.action in ("creation", "write", "cancel", "invoice")
|
||||
self.action in ("creation", "write", "cancel", "invoice", "checkout")
|
||||
and self.moment == "before"
|
||||
):
|
||||
raise UserError(_("The moment for this action cannot be 'Before'"))
|
||||
@@ -142,6 +145,9 @@ class PmsAutomatedMails(models.Model):
|
||||
"usage": "ir_cron",
|
||||
"model_id": dict_val["model_id"],
|
||||
}
|
||||
if vals.get("action") == "checkout":
|
||||
code = "record.send_exit_email(" + str(self.template_id) + ")"
|
||||
action_server_vals.update({"state": "code", "code": code})
|
||||
action_server.write(action_server_vals)
|
||||
automated_actions_vals = {
|
||||
"active": self.active,
|
||||
@@ -181,14 +187,14 @@ class PmsAutomatedMails(models.Model):
|
||||
@api.model
|
||||
def _get_auto_action_fields_in_creation_action(self, moment, time):
|
||||
model_field = False
|
||||
model_id = self.env["ir.model"].search([("model", "=", "pms.reservation")]).id
|
||||
model_id = self.env["ir.model"].search([("model", "=", "pms.folio")]).id
|
||||
if moment == "in_act":
|
||||
trigger = "on_create"
|
||||
time = 0
|
||||
else:
|
||||
trigger = "on_time"
|
||||
model_field = self.env["ir.model.fields"].search(
|
||||
[("model", "=", "pms.reservation"), ("name", "=", "create_date")]
|
||||
[("model", "=", "pms.folio"), ("name", "=", "create_date")]
|
||||
)
|
||||
result = {
|
||||
"model_id": model_id,
|
||||
@@ -240,16 +246,20 @@ class PmsAutomatedMails(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_auto_action_fields_in_checkout_action(self, moment, time):
|
||||
model_id = self.env["ir.model"].search([("model", "=", "pms.reservation")]).id
|
||||
trigger = "on_time"
|
||||
model_field = self.env["ir.model.fields"].search(
|
||||
[("model", "=", "pms.reservation"), ("name", "=", "checkout")]
|
||||
model_id = (
|
||||
self.env["ir.model"].search([("model", "=", "pms.checkin.partner")]).id
|
||||
)
|
||||
trigger = "on_write"
|
||||
model_field = self.env["ir.model.fields"].search(
|
||||
[("model", "=", "pms.checkin.partner"), ("name", "=", "state")]
|
||||
)
|
||||
if moment == "before":
|
||||
time = time * (-1)
|
||||
if moment == "in_act":
|
||||
trigger = "on_write"
|
||||
time = 0
|
||||
else:
|
||||
trigger = "on_time"
|
||||
model_field = self.env["ir.model.fields"].search(
|
||||
[("model", "=", "pms.checkin.partner"), ("name", "=", "departure")]
|
||||
)
|
||||
result = {
|
||||
"model_id": model_id,
|
||||
"trigger": trigger,
|
||||
@@ -308,14 +318,21 @@ class PmsAutomatedMails(models.Model):
|
||||
dict_val = {}
|
||||
if action == "creation":
|
||||
dict_val = self._get_auto_action_fields_in_creation_action(moment, time)
|
||||
filter_domain = [
|
||||
("first_checkin", ">=", str(fields.date.today())),
|
||||
("reservation_ids.to_send_mail", "=", True),
|
||||
]
|
||||
elif action == "write" or action == "cancel":
|
||||
dict_val = self._get_auto_action_fields_in_write_or_cancel_action(
|
||||
moment, time
|
||||
)
|
||||
if action == "cancel":
|
||||
filter_domain = [
|
||||
("state", "=", "cancelled"),
|
||||
("state", "=", "cancel"),
|
||||
]
|
||||
trigger_fields = self.env["ir.model.fields"].search(
|
||||
[("model", "=", "pms.reservation"), ("name", "=", "state")]
|
||||
)
|
||||
elif action == "checkin":
|
||||
dict_val = self._get_auto_action_fields_in_checkin_action(moment, time)
|
||||
if moment == "in_act":
|
||||
@@ -330,11 +347,15 @@ class PmsAutomatedMails(models.Model):
|
||||
dict_val = self._get_auto_action_fields_in_checkout_action(moment, time)
|
||||
if moment == "in_act":
|
||||
trigger_fields = self.env["ir.model.fields"].search(
|
||||
[("model", "=", "pms.reservation"), ("name", "=", "state")]
|
||||
[("model", "=", "pms.checkin.partner"), ("name", "=", "state")]
|
||||
)
|
||||
filter_pre_domain = [("state", "=", "onboard")]
|
||||
filter_domain = [
|
||||
("state", "=", "out"),
|
||||
("state", "=", "done"),
|
||||
]
|
||||
else:
|
||||
filter_domain = [
|
||||
("state", "=", "done"),
|
||||
]
|
||||
elif action == "payment":
|
||||
dict_val = self._get_auto_action_fields_in_payment_action(moment, time)
|
||||
|
||||
@@ -16,7 +16,7 @@ from odoo.tools.safe_eval import safe_eval
|
||||
class PmsCheckinPartner(models.Model):
|
||||
_name = "pms.checkin.partner"
|
||||
_description = "Partner Checkins"
|
||||
_inherit = ["portal.mixin"]
|
||||
_inherit = ["mail.thread", "mail.activity.mixin", "portal.mixin"]
|
||||
_rec_name = "identifier"
|
||||
|
||||
identifier = fields.Char(
|
||||
@@ -833,7 +833,7 @@ class PmsCheckinPartner(models.Model):
|
||||
for record in self.filtered(lambda c: c.state == "onboard"):
|
||||
vals = {
|
||||
"state": "done",
|
||||
"departure": record.reservation_id.checkout,
|
||||
"departure": fields.Datetime.now(),
|
||||
}
|
||||
record.update(vals)
|
||||
return True
|
||||
@@ -937,3 +937,39 @@ class PmsCheckinPartner(models.Model):
|
||||
)
|
||||
|
||||
invitation_mail.send()
|
||||
|
||||
def send_exit_email(self, template_id):
|
||||
template = self.env["mail.template"].browse(template_id)
|
||||
if self.email:
|
||||
template.send_mail(
|
||||
self.id,
|
||||
force_send=True,
|
||||
raise_exception=False,
|
||||
email_values={"email_to": self.email, "auto_delete": False},
|
||||
)
|
||||
body = template._render_field(
|
||||
"body_html", [6, 0, self.id], compute_lang=True, post_process=True
|
||||
)[self.id]
|
||||
self.reservation_id.message_post(body=body)
|
||||
|
||||
if self.reservation_id.to_send_mail:
|
||||
emails = self.reservation_id.checkin_partner_ids.mapped("email")
|
||||
if (
|
||||
self.reservation_id.partner_id
|
||||
and self.reservation_id.partner_id.email
|
||||
and self.reservation_id.partner_id.email not in emails
|
||||
):
|
||||
template.send_mail(
|
||||
self.partner_id.id,
|
||||
force_send=True,
|
||||
raise_exception=False,
|
||||
email_values={
|
||||
"email_to": self.reservation_id.email,
|
||||
"auto_delete": False,
|
||||
},
|
||||
)
|
||||
body = template._render_field(
|
||||
"body_html", [6, 0, self.id], compute_lang=True, post_process=True
|
||||
)[self.id]
|
||||
self.reservation_id.message_post(body=body)
|
||||
self.reservation_id.to_send_mail = False
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
from odoo import models, fields, api
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class PmsTeam(models.Model):
|
||||
_name = "pms.team"
|
||||
_inherit = ['mail.thread']
|
||||
_inherit = ["mail.thread"]
|
||||
_description = "PMS Team"
|
||||
_check_pms_properties_auto = True
|
||||
|
||||
name = fields.Char('PMS Team', required=True)
|
||||
sequence = fields.Integer('Sequence', default=10)
|
||||
name = fields.Char("PMS Team", required=True)
|
||||
sequence = fields.Integer("Sequence", default=10)
|
||||
active = fields.Boolean(default=True)
|
||||
pms_property_id = fields.Many2one(
|
||||
'pms.property', string='Property')
|
||||
user_id = fields.Many2one('res.users', string='Team Leader')
|
||||
member_ids = fields.One2many(
|
||||
'res.users', 'pms_team_id', string='Channel Members')
|
||||
pms_property_id = fields.Many2one("pms.property", string="Property")
|
||||
user_id = fields.Many2one("res.users", string="Team Leader")
|
||||
member_ids = fields.One2many("res.users", "pms_team_id", string="Channel Members")
|
||||
|
||||
Reference in New Issue
Block a user