From fedfa93715a9f3c624644b3f1d32866ac1c706d8 Mon Sep 17 00:00:00 2001 From: braisab Date: Thu, 8 Apr 2021 19:34:45 +0200 Subject: [PATCH 01/15] [IMP] add pms_automated_mails model and views --- pms/__manifest__.py | 1 + pms/models/__init__.py | 1 + pms/models/pms_automated_mails.py | 74 +++++++++++++++++++++++++ pms/security/ir.model.access.csv | 1 + pms/views/pms_automated_mails_views.xml | 58 +++++++++++++++++++ 5 files changed, 135 insertions(+) create mode 100644 pms/models/pms_automated_mails.py create mode 100644 pms/views/pms_automated_mails_views.xml diff --git a/pms/__manifest__.py b/pms/__manifest__.py index efb579def..097a9f7a1 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -77,6 +77,7 @@ "views/res_company_views.xml", "views/traveller_report_template.xml", "wizards/wizard_split_join_swap_reservation.xml", + "views/pms_automated_mails_views.xml", "wizards/wizard_massive_changes.xml", "wizards/wizard_advanced_filters.xml", ], diff --git a/pms/models/__init__.py b/pms/models/__init__.py index 5bcb034f5..518a2ba19 100644 --- a/pms/models/__init__.py +++ b/pms/models/__init__.py @@ -46,3 +46,4 @@ from . import account_bank_statement from . import account_journal from . import pms_availability from . import res_partner_id_number +from . import pms_automated_mails diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py new file mode 100644 index 000000000..3c12d0099 --- /dev/null +++ b/pms/models/pms_automated_mails.py @@ -0,0 +1,74 @@ +from odoo import fields, models, api + + +class PmsAutomatedMails(models.Model): + _name = 'pms.automated.mails' + _description = 'Automatic Mails' + + name = fields.Char( + string="Name" + ) + + pms_property_id = fields.Many2one( + string="Property", + comodel_name="pms.property" + ) + + automated_actions_id = fields.Many2one( + string="Automated Actions", + comodel_name="base.automation" + ) + + time = fields.Integer( + string="Time", + required=True + ) + + time_type = fields.Selection( + string="Time Range", + selection=[ + ("minutes", "Minutes"), + ("hour", "Hour"), + ("day", "Days"), + ("month", "Months") + ], + default="day", + required=True + ) + template_id = fields.Many2one( + string="Template", + comodel_name="mail.template", + required=True + ) + + reservation_date_fields_id = fields.Many2one( + string="Action", + comodel_name="ir.model.fields", + domain="[('model', '=', 'pms.reservation'),('ttype', 'in', ('date', 'datetime'))]" + ) + @api.model + def create(self, vals): + name = vals.get("name") + model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) + action_server_vals = { + "name": name, + "state": "email", + "usage": "ir_cron", + "model_id": model_id.id, + } + action_server = self.env["ir.actions.server"].create(action_server_vals) + model_field = vals.get("reservation_date_fields_id") + time = vals.get("time") + date_range_type = vals.get("time_type") + template_id = vals.get("template_id") + automated_actions_vals = { + "action_server_id": action_server.id, + "trigger": "on_time", + "filter_domain": [("checkin", "<", "2021-12-31")], + "trg_date_id": model_field.id, + "trg_date_range": time, + "trg_date_range_type": date_range_type, + "template_id": template_id + } + self.env["base.automation"].create(automated_actions_vals) + return super(PmsAutomatedMails, self).create(vals) diff --git a/pms/security/ir.model.access.csv b/pms/security/ir.model.access.csv index 544f75411..f536bb9a2 100644 --- a/pms/security/ir.model.access.csv +++ b/pms/security/ir.model.access.csv @@ -60,3 +60,4 @@ user_access_wizard_payment_folio,user_access_wizard_payment_folio,model_wizard_p user_access_wizard_folio_changes,user_access_wizard_folio_changes,model_wizard_folio_changes,pms.group_pms_user,1,1,1,1 user_access_pms_folio_portal,user_access_pms_folio_portal,model_pms_folio,base.group_portal,1,0,0,0 user_access_pms_reservation_portal,user_access_pms_reservation_portal,model_pms_reservation,base.group_portal,1,0,0,0 +user_access_pms_automated_mails,user_access_pms_automated_mails,model_pms_automated_mails,pms.group_pms_user,1,1,1,1 diff --git a/pms/views/pms_automated_mails_views.xml b/pms/views/pms_automated_mails_views.xml new file mode 100644 index 000000000..9740a9f21 --- /dev/null +++ b/pms/views/pms_automated_mails_views.xml @@ -0,0 +1,58 @@ + + + + pms.automated_mails_view_form + pms.automated.mails + +
+ +
+
+
+
+ + + + +
+
+ + + + +
+
+
+
+
+
+ + pms.automated.mails.tree + pms.automated.mails + + + + + + + + + + + Automated Mails + pms.automated.mails + + tree,form + + +
From 6f33cb3c3adf4067ea97049ea7862045b2437af1 Mon Sep 17 00:00:00 2001 From: braisab Date: Mon, 12 Apr 2021 18:59:56 +0200 Subject: [PATCH 02/15] [WIP] action: send mail after x min create reservation --- pms/models/pms_automated_mails.py | 111 +++++++++++++++++------- pms/views/pms_automated_mails_views.xml | 32 ++++--- 2 files changed, 99 insertions(+), 44 deletions(-) diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py index 3c12d0099..df9dacef0 100644 --- a/pms/models/pms_automated_mails.py +++ b/pms/models/pms_automated_mails.py @@ -1,28 +1,24 @@ -from odoo import fields, models, api +from odoo import _, api, fields, models +from odoo.exceptions import UserError class PmsAutomatedMails(models.Model): - _name = 'pms.automated.mails' - _description = 'Automatic Mails' + _name = "pms.automated.mails" + _description = "Automatic Mails" - name = fields.Char( - string="Name" + name = fields.Char(string="Name") + + pms_property_id = fields.Many2one(string="Property", comodel_name="pms.property") + + reservation_id = fields.Many2one( + string="Reservations", + comodel_name="pms.reservation", ) - - pms_property_id = fields.Many2one( - string="Property", - comodel_name="pms.property" - ) - automated_actions_id = fields.Many2one( - string="Automated Actions", - comodel_name="base.automation" + string="Automated Actions", comodel_name="base.automation", ondelete="cascade" ) - time = fields.Integer( - string="Time", - required=True - ) + time = fields.Integer(string="Time") time_type = fields.Selection( string="Time Range", @@ -30,26 +26,78 @@ class PmsAutomatedMails(models.Model): ("minutes", "Minutes"), ("hour", "Hour"), ("day", "Days"), - ("month", "Months") + ("month", "Months"), ], default="day", - required=True ) template_id = fields.Many2one( - string="Template", - comodel_name="mail.template", - required=True + string="Template", comodel_name="mail.template", required=True + ) + + model_id = fields.Many2one( + string="Model", comodel_name="ir.model", compute="_compute_model_id", store=True ) reservation_date_fields_id = fields.Many2one( string="Action", comodel_name="ir.model.fields", - domain="[('model', '=', 'pms.reservation'),('ttype', 'in', ('date', 'datetime'))]" ) + + action = fields.Selection( + string="Action", + selection=[ + ("creation", "Reservation creation"), + ("write", "Reservation modification"), + ("cancel", "Reservation cancellation"), + ("checkin", "Checkin"), + ("checkout", "Checkout"), + ("payment", "Payment"), + ("invoice", "Invoice"), + ], + default="creation", + required=True, + ) + + trigger = fields.Char( + string="Trigger", + ) + + moment = fields.Selection( + string="Moment", + selection=[ + ("before", "Before"), + ("after", "After"), + ("in_act", "In the act"), + ], + default="before", + ) + + active = fields.Boolean(string="Active", default=True) + @api.model def create(self, vals): name = vals.get("name") - model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) + action = vals.get("action") + model_field = vals.get("reservation_date_fields_id") + time = vals.get("time") + moment = vals.get("moment") + date_range_type = vals.get("time_type") + template_id = vals.get("template_id") + active = vals.get("active") + model_id = False + trigger = "on_time" + filter_domain = False + if action == "creation": + if moment == "before": + raise UserError(_("The moment for this action cannot be 'Before'")) + model_field = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "date_order")] + ) + filter_domain = [("date_order", "=", fields.Date.today())] + if action in ("creation", "write", "cancellation", "checkin", "checkout"): + model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) + elif action == "payment": + model_id = self.env["ir.model"].search([("name", "=", "Payments")]) action_server_vals = { "name": name, "state": "email", @@ -57,18 +105,17 @@ class PmsAutomatedMails(models.Model): "model_id": model_id.id, } action_server = self.env["ir.actions.server"].create(action_server_vals) - model_field = vals.get("reservation_date_fields_id") - time = vals.get("time") - date_range_type = vals.get("time_type") - template_id = vals.get("template_id") + automated_actions_vals = { + "active": active, "action_server_id": action_server.id, - "trigger": "on_time", - "filter_domain": [("checkin", "<", "2021-12-31")], + "trigger": trigger, "trg_date_id": model_field.id, + "filter_domain": filter_domain, "trg_date_range": time, "trg_date_range_type": date_range_type, - "template_id": template_id + "template_id": template_id, } - self.env["base.automation"].create(automated_actions_vals) + automated_action = self.env["base.automation"].create(automated_actions_vals) + self.automated_actions_id = automated_action.id return super(PmsAutomatedMails, self).create(vals) diff --git a/pms/views/pms_automated_mails_views.xml b/pms/views/pms_automated_mails_views.xml index 9740a9f21..98f000fe3 100644 --- a/pms/views/pms_automated_mails_views.xml +++ b/pms/views/pms_automated_mails_views.xml @@ -1,4 +1,4 @@ - + pms.automated_mails_view_form @@ -7,22 +7,30 @@
-
- - + + +
- - + + +
@@ -35,17 +43,17 @@ pms.automated.mails - - - - + + + + Automated Mails pms.automated.mails - + tree,form Date: Tue, 13 Apr 2021 19:37:14 +0200 Subject: [PATCH 03/15] [WIP]added creation of auto actions when actions are: write reservation, cancel reservation, checkin and checkout --- pms/models/pms_automated_mails.py | 111 +++++++++++++++++------- pms/views/pms_automated_mails_views.xml | 3 +- 2 files changed, 82 insertions(+), 32 deletions(-) diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py index df9dacef0..1b2468162 100644 --- a/pms/models/pms_automated_mails.py +++ b/pms/models/pms_automated_mails.py @@ -10,10 +10,6 @@ class PmsAutomatedMails(models.Model): pms_property_id = fields.Many2one(string="Property", comodel_name="pms.property") - reservation_id = fields.Many2one( - string="Reservations", - comodel_name="pms.reservation", - ) automated_actions_id = fields.Many2one( string="Automated Actions", comodel_name="base.automation", ondelete="cascade" ) @@ -38,11 +34,6 @@ class PmsAutomatedMails(models.Model): string="Model", comodel_name="ir.model", compute="_compute_model_id", store=True ) - reservation_date_fields_id = fields.Many2one( - string="Action", - comodel_name="ir.model.fields", - ) - action = fields.Selection( string="Action", selection=[ @@ -78,23 +69,17 @@ class PmsAutomatedMails(models.Model): def create(self, vals): name = vals.get("name") action = vals.get("action") - model_field = vals.get("reservation_date_fields_id") time = vals.get("time") - moment = vals.get("moment") date_range_type = vals.get("time_type") template_id = vals.get("template_id") active = vals.get("active") + moment = vals.get("moment") model_id = False - trigger = "on_time" - filter_domain = False - if action == "creation": + model_field = False + if action in ("creation", "write", "cancel"): if moment == "before": raise UserError(_("The moment for this action cannot be 'Before'")) - model_field = self.env["ir.model.fields"].search( - [("model", "=", "pms.reservation"), ("name", "=", "date_order")] - ) - filter_domain = [("date_order", "=", fields.Date.today())] - if action in ("creation", "write", "cancellation", "checkin", "checkout"): + if action in ("creation", "write", "cancel", "checkin", "checkout"): model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) elif action == "payment": model_id = self.env["ir.model"].search([("name", "=", "Payments")]) @@ -105,17 +90,83 @@ class PmsAutomatedMails(models.Model): "model_id": model_id.id, } action_server = self.env["ir.actions.server"].create(action_server_vals) - - automated_actions_vals = { - "active": active, - "action_server_id": action_server.id, - "trigger": trigger, - "trg_date_id": model_field.id, - "filter_domain": filter_domain, - "trg_date_range": time, - "trg_date_range_type": date_range_type, - "template_id": template_id, - } + dict_val = self._prepare_creation_write(action, time, moment) + if not model_field: + automated_actions_vals = { + "active": active, + "action_server_id": action_server.id, + "trigger": dict_val["trigger"], + "filter_domain": dict_val["filter_domain"], + "trg_date_range": dict_val["time"], + "trg_date_range_type": date_range_type, + "template_id": template_id, + } + else: + automated_actions_vals = { + "active": active, + "action_server_id": action_server.id, + "trigger": dict_val["trigger"], + "trg_date_id": dict_val["model_field"].id, + "filter_domain": dict_val["filter_domain"], + "trg_date_range": dict_val["time"], + "trg_date_range_type": date_range_type, + "template_id": template_id, + } automated_action = self.env["base.automation"].create(automated_actions_vals) self.automated_actions_id = automated_action.id return super(PmsAutomatedMails, self).create(vals) + + def _prepare_creation_write(self, action, time, moment): + trigger = False + model_field = False + filter_domain = False + # action: create reservation + if action == "creation": + if moment == "in_act": + trigger = "on_create" + else: + trigger = "on_time" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "date_order")] + ) + + # action: write and cancel reservation + if action == "write" or action == "cancel": + if action == "cancel": + filter_domain = [("state", "=", "cancelled")] + if moment == "in_act": + trigger = "on_write" + else: + trigger = "on_time" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "write_date")] + ) + + # action: checkin + if action == "checkin": + trigger = "on_time" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "checkin")] + ) + if moment == "in_act": + filter_domain = [("checkin", "=", fields.Date.today())] + elif moment == "before": + time = time * (-1) + + # action: checkout + if action == "checkout": + trigger = "on_time" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "checkout")] + ) + if moment == "in_act": + filter_domain = [("checkout", "=", fields.Date.today())] + elif moment == "before": + time = time * (-1) + result = { + "trigger": trigger, + "model_field": model_field, + "filter_domain": filter_domain, + "time": time, + } + return result diff --git a/pms/views/pms_automated_mails_views.xml b/pms/views/pms_automated_mails_views.xml index 98f000fe3..8ac801d87 100644 --- a/pms/views/pms_automated_mails_views.xml +++ b/pms/views/pms_automated_mails_views.xml @@ -44,8 +44,7 @@ - - + From b8665f83aad47472ebad4f351c00e6f112f1458f Mon Sep 17 00:00:00 2001 From: braisab Date: Wed, 14 Apr 2021 21:43:32 +0200 Subject: [PATCH 04/15] [IMP] added write method and payment action --- pms/__manifest__.py | 1 + pms/models/pms_automated_mails.py | 119 ++++++++++++++++++++++-------- 2 files changed, 90 insertions(+), 30 deletions(-) diff --git a/pms/__manifest__.py b/pms/__manifest__.py index 097a9f7a1..817de0650 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -14,6 +14,7 @@ "installable": True, "depends": [ "base", + "base_automation", "mail", # "account_payment_return", # "email_template_qweb", diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py index 1b2468162..8d4246bf9 100644 --- a/pms/models/pms_automated_mails.py +++ b/pms/models/pms_automated_mails.py @@ -6,12 +6,16 @@ class PmsAutomatedMails(models.Model): _name = "pms.automated.mails" _description = "Automatic Mails" - name = fields.Char(string="Name") + name = fields.Char(string="Name", required=True) pms_property_id = fields.Many2one(string="Property", comodel_name="pms.property") automated_actions_id = fields.Many2one( - string="Automated Actions", comodel_name="base.automation", ondelete="cascade" + string="Automated Actions", + comodel_name="base.automation", + ondelete="cascade", + store=True, + readonly=False, ) time = fields.Integer(string="Time") @@ -49,10 +53,6 @@ class PmsAutomatedMails(models.Model): required=True, ) - trigger = fields.Char( - string="Trigger", - ) - moment = fields.Selection( string="Moment", selection=[ @@ -74,23 +74,15 @@ class PmsAutomatedMails(models.Model): template_id = vals.get("template_id") active = vals.get("active") moment = vals.get("moment") - model_id = False - model_field = False - if action in ("creation", "write", "cancel"): - if moment == "before": - raise UserError(_("The moment for this action cannot be 'Before'")) - if action in ("creation", "write", "cancel", "checkin", "checkout"): - model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) - elif action == "payment": - model_id = self.env["ir.model"].search([("name", "=", "Payments")]) + dict_val = self._prepare_automated_actions_id(action, time, moment) action_server_vals = { "name": name, "state": "email", "usage": "ir_cron", - "model_id": model_id.id, + "model_id": dict_val["model_id"].id, } action_server = self.env["ir.actions.server"].create(action_server_vals) - dict_val = self._prepare_creation_write(action, time, moment) + model_field = dict_val["model_field"] if not model_field: automated_actions_vals = { "active": active, @@ -113,35 +105,85 @@ class PmsAutomatedMails(models.Model): "template_id": template_id, } automated_action = self.env["base.automation"].create(automated_actions_vals) - self.automated_actions_id = automated_action.id + vals.update({"automated_actions_id": automated_action.id}) return super(PmsAutomatedMails, self).create(vals) - def _prepare_creation_write(self, action, time, moment): + def write(self, vals): + result = super(PmsAutomatedMails, self).write(vals) + dict_val = self._prepare_automated_actions_id( + self.action, self.time, self.moment + ) + automated_actions_id = self.automated_actions_id + action_server = automated_actions_id.action_server_id + action_server_vals = { + "name": self.name, + "state": "email", + "usage": "ir_cron", + "model_id": dict_val["model_id"].id, + } + action_server.write(action_server_vals) + model_field = dict_val["model_field"] + if not model_field: + automated_actions_vals = { + "active": self.active, + "action_server_id": action_server.id, + "trigger": dict_val["trigger"], + "filter_domain": dict_val["filter_domain"], + "trg_date_range": dict_val["time"], + "trg_date_range_type": self.time_type, + "template_id": self.template_id, + } + else: + automated_actions_vals = { + "active": self.active, + "action_server_id": action_server.id, + "trigger": dict_val["trigger"], + "trg_date_id": dict_val["model_field"].id, + "filter_domain": dict_val["filter_domain"], + "trg_date_range": dict_val["time"], + "trg_date_range_type": self.time_type, + "template_id": self.template_id, + } + automated_actions_id.write(automated_actions_vals) + vals.update({"automated_actions_id": automated_actions_id.id}) + return result + + def _prepare_automated_actions_id(self, action, time, moment): trigger = False model_field = False filter_domain = False + model_id = False + today = fields.Date.today() + if action in ("creation", "write", "cancel") and moment == "before": + raise UserError(_("The moment for this action cannot be 'Before'")) + if action in ("creation", "write", "cancel", "checkin", "checkout"): + model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) + elif action == "payment": + model_id = self.env["ir.model"].search( + [("name", "=", "Payments"), ("transient", "=", False)] + ) # action: create reservation if action == "creation": 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", "=", "date_order")] + [("model", "=", "pms.reservation"), ("name", "=", "create_date")] ) - # action: write and cancel reservation if action == "write" or action == "cancel": if action == "cancel": filter_domain = [("state", "=", "cancelled")] if moment == "in_act": trigger = "on_write" + time = 0 else: trigger = "on_time" model_field = self.env["ir.model.fields"].search( [("model", "=", "pms.reservation"), ("name", "=", "write_date")] ) - # action: checkin if action == "checkin": trigger = "on_time" @@ -149,24 +191,41 @@ class PmsAutomatedMails(models.Model): [("model", "=", "pms.reservation"), ("name", "=", "checkin")] ) if moment == "in_act": - filter_domain = [("checkin", "=", fields.Date.today())] + time = 0 + filter_domain = [("checkin", "=", str(today))] elif moment == "before": time = time * (-1) - - # action: checkout - if action == "checkout": + # action: checkout + if action == "checkout": + trigger = "on_time" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "checkout")] + ) + if moment == "in_act": + time = 0 + filter_domain = [("checkout", "=", str(today))] + elif moment == "before": + time = time * (-1) + # action: payments + if action == "payment": + if moment == "in_act": + trigger = "on_creation" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "account.payment"), ("name", "=", "create_date")] + ) + time = 0 + else: trigger = "on_time" model_field = self.env["ir.model.fields"].search( - [("model", "=", "pms.reservation"), ("name", "=", "checkout")] + [("model", "=", "account.payment"), ("name", "=", "date")] ) - if moment == "in_act": - filter_domain = [("checkout", "=", fields.Date.today())] - elif moment == "before": + if moment == "before": time = time * (-1) result = { "trigger": trigger, "model_field": model_field, "filter_domain": filter_domain, "time": time, + "model_id": model_id, } return result From a4e533038d4d848074bf536d03d8c454ac6a8626 Mon Sep 17 00:00:00 2001 From: braisab Date: Thu, 15 Apr 2021 10:11:53 +0200 Subject: [PATCH 05/15] [IMP]added unlink method to delete automated action when auto mail is delete --- pms/models/pms_automated_mails.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py index 8d4246bf9..c89ec9585 100644 --- a/pms/models/pms_automated_mails.py +++ b/pms/models/pms_automated_mails.py @@ -148,6 +148,13 @@ class PmsAutomatedMails(models.Model): vals.update({"automated_actions_id": automated_actions_id.id}) return result + def unlink(self): + automated_actions_id = self.automated_actions_id + action_server = automated_actions_id.action_server_id + automated_actions_id.unlink() + action_server.unlink() + return super(PmsAutomatedMails, self).unlink() + def _prepare_automated_actions_id(self, action, time, moment): trigger = False model_field = False @@ -156,14 +163,9 @@ class PmsAutomatedMails(models.Model): today = fields.Date.today() if action in ("creation", "write", "cancel") and moment == "before": raise UserError(_("The moment for this action cannot be 'Before'")) - if action in ("creation", "write", "cancel", "checkin", "checkout"): - model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) - elif action == "payment": - model_id = self.env["ir.model"].search( - [("name", "=", "Payments"), ("transient", "=", False)] - ) # action: create reservation if action == "creation": + model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) if moment == "in_act": trigger = "on_create" time = 0 @@ -174,6 +176,7 @@ class PmsAutomatedMails(models.Model): ) # action: write and cancel reservation if action == "write" or action == "cancel": + model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) if action == "cancel": filter_domain = [("state", "=", "cancelled")] if moment == "in_act": @@ -186,6 +189,7 @@ class PmsAutomatedMails(models.Model): ) # action: checkin if action == "checkin": + model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) trigger = "on_time" model_field = self.env["ir.model.fields"].search( [("model", "=", "pms.reservation"), ("name", "=", "checkin")] @@ -197,6 +201,7 @@ class PmsAutomatedMails(models.Model): time = time * (-1) # action: checkout if action == "checkout": + model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) trigger = "on_time" model_field = self.env["ir.model.fields"].search( [("model", "=", "pms.reservation"), ("name", "=", "checkout")] @@ -208,6 +213,9 @@ class PmsAutomatedMails(models.Model): time = time * (-1) # action: payments if action == "payment": + model_id = self.env["ir.model"].search( + [("name", "=", "Payments"), ("transient", "=", False)] + ) if moment == "in_act": trigger = "on_creation" model_field = self.env["ir.model.fields"].search( From 05a566c525663c2140ebab304e1b46f7e4f5c805 Mon Sep 17 00:00:00 2001 From: braisab Date: Fri, 16 Apr 2021 13:21:35 +0200 Subject: [PATCH 06/15] [IMP] added properties in the creation of automated emails --- pms/models/pms_automated_mails.py | 103 +++++++++++++++++++----- pms/views/pms_automated_mails_views.xml | 5 ++ 2 files changed, 88 insertions(+), 20 deletions(-) diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py index c89ec9585..df8591084 100644 --- a/pms/models/pms_automated_mails.py +++ b/pms/models/pms_automated_mails.py @@ -6,22 +6,26 @@ class PmsAutomatedMails(models.Model): _name = "pms.automated.mails" _description = "Automatic Mails" - name = fields.Char(string="Name", required=True) + name = fields.Char(string="Name", help="Name of the automated mail.", required=True) - pms_property_id = fields.Many2one(string="Property", comodel_name="pms.property") + pms_property_ids = fields.Many2many( + string="Property", + help="Properties with access to the element;" + " if not set, all properties can access", + comodel_name="pms.property", + ) automated_actions_id = fields.Many2one( string="Automated Actions", + help="automated action that is created when creating automated emails ", comodel_name="base.automation", - ondelete="cascade", - store=True, - readonly=False, ) - time = fields.Integer(string="Time") + time = fields.Integer(string="Time", help="Amount of time") time_type = fields.Selection( string="Time Range", + help="Type of date range", selection=[ ("minutes", "Minutes"), ("hour", "Hour"), @@ -31,15 +35,15 @@ class PmsAutomatedMails(models.Model): default="day", ) template_id = fields.Many2one( - string="Template", comodel_name="mail.template", required=True - ) - - model_id = fields.Many2one( - string="Model", comodel_name="ir.model", compute="_compute_model_id", store=True + string="Template", + help="The template that will be sent by email", + comodel_name="mail.template", + required=True, ) action = fields.Selection( string="Action", + help="The action that will cause the email to be sent ", selection=[ ("creation", "Reservation creation"), ("write", "Reservation modification"), @@ -55,6 +59,7 @@ class PmsAutomatedMails(models.Model): moment = fields.Selection( string="Moment", + help="Moment in relation to the action in which the email will be sent", selection=[ ("before", "Before"), ("after", "After"), @@ -63,7 +68,9 @@ class PmsAutomatedMails(models.Model): default="before", ) - active = fields.Boolean(string="Active", default=True) + active = fields.Boolean( + string="Active", help="Indicates if the automated mail is active", default=True + ) @api.model def create(self, vals): @@ -74,7 +81,20 @@ class PmsAutomatedMails(models.Model): template_id = vals.get("template_id") active = vals.get("active") moment = vals.get("moment") - dict_val = self._prepare_automated_actions_id(action, time, moment) + properties = vals.get("pms_property_ids") + is_create = True + dict_val = self._prepare_automated_actions_id( + action, time, moment, properties, is_create + ) + property_vals = vals.get("pms_property_ids") + property_vals_ids = property_vals[0][2] + pms_properties = [] + pms_property_ids = self.env["pms.property"].search([]) + for pms_property in pms_property_ids: + pms_properties.append(pms_property.id) + if pms_properties == property_vals_ids: + vals.update({"pms_property_ids": False}) + action_server_vals = { "name": name, "state": "email", @@ -110,8 +130,9 @@ class PmsAutomatedMails(models.Model): def write(self, vals): result = super(PmsAutomatedMails, self).write(vals) + is_create = False dict_val = self._prepare_automated_actions_id( - self.action, self.time, self.moment + self.action, self.time, self.moment, self.pms_property_ids, is_create ) automated_actions_id = self.automated_actions_id action_server = automated_actions_id.action_server_id @@ -155,13 +176,16 @@ class PmsAutomatedMails(models.Model): action_server.unlink() return super(PmsAutomatedMails, self).unlink() - def _prepare_automated_actions_id(self, action, time, moment): + def _prepare_automated_actions_id( + self, action, time, moment, properties, is_create + ): trigger = False model_field = False - filter_domain = False model_id = False today = fields.Date.today() - if action in ("creation", "write", "cancel") and moment == "before": + pms_property_ids = self._get_pms_property_ids(properties, is_create) + filter_domain = [("pms_property_id", "in", pms_property_ids)] + if action in ("creation", "write", "cancel", "invoice") and moment == "before": raise UserError(_("The moment for this action cannot be 'Before'")) # action: create reservation if action == "creation": @@ -178,7 +202,10 @@ class PmsAutomatedMails(models.Model): if action == "write" or action == "cancel": model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) if action == "cancel": - filter_domain = [("state", "=", "cancelled")] + filter_domain = [ + ("state", "=", "cancelled"), + ("pms_property_id", "in", pms_property_ids), + ] if moment == "in_act": trigger = "on_write" time = 0 @@ -196,7 +223,10 @@ class PmsAutomatedMails(models.Model): ) if moment == "in_act": time = 0 - filter_domain = [("checkin", "=", str(today))] + filter_domain = [ + ("checkin", "=", str(today)), + ("pms_property_id", "in", pms_property_ids), + ] elif moment == "before": time = time * (-1) # action: checkout @@ -208,7 +238,10 @@ class PmsAutomatedMails(models.Model): ) if moment == "in_act": time = 0 - filter_domain = [("checkout", "=", str(today))] + filter_domain = [ + ("checkout", "=", str(today)), + ("pms_property_id", "in", pms_property_ids), + ] elif moment == "before": time = time * (-1) # action: payments @@ -229,6 +262,17 @@ class PmsAutomatedMails(models.Model): ) if moment == "before": time = time * (-1) + # TODO: create automated action when the act be 'invoice' + # action: invoices + # if action == "invoice": + # model_id = self.env["ir.model"].search([("name", "=", "Journal Entry")]) + # filter_domain = [ + # ("folio_ids", "!=", False), + # ("pms_property_id", "in", pms_property_ids), + # ] + # if moment == "in_act": + # trigger = "on_create" + # time = 0 result = { "trigger": trigger, "model_field": model_field, @@ -237,3 +281,22 @@ class PmsAutomatedMails(models.Model): "model_id": model_id, } return result + + def _get_pms_property_ids(self, properties, is_create): + pms_property_ids = [] + if is_create: + pms_property_ids = properties[0][2] + if not pms_property_ids: + self.pms_property_ids = False + properties = self.env["pms.property"].search([]) + for pms_property in properties: + pms_property_ids.append(pms_property.id) + else: + if not properties: + properties = self.env["pms.property"].search([]) + for pms_property in properties: + pms_property_ids.append(pms_property.id) + else: + for pms_property in properties: + pms_property_ids.append(pms_property.id) + return pms_property_ids diff --git a/pms/views/pms_automated_mails_views.xml b/pms/views/pms_automated_mails_views.xml index 8ac801d87..1dd6f30ff 100644 --- a/pms/views/pms_automated_mails_views.xml +++ b/pms/views/pms_automated_mails_views.xml @@ -18,6 +18,11 @@ +
From 20cee4302f83d6f2bf50a3a149fc714498f3ee96 Mon Sep 17 00:00:00 2001 From: braisab Date: Tue, 20 Apr 2021 12:34:29 +0200 Subject: [PATCH 07/15] [REF] refactor pms_property and model_id --- pms/models/pms_automated_mails.py | 81 +++++++++++++++---------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py index df8591084..3f5fb8db0 100644 --- a/pms/models/pms_automated_mails.py +++ b/pms/models/pms_automated_mails.py @@ -83,23 +83,17 @@ class PmsAutomatedMails(models.Model): moment = vals.get("moment") properties = vals.get("pms_property_ids") is_create = True + if action in ("creation", "write", "cancel", "invoice") and moment == "before": + raise UserError(_("The moment for this action cannot be 'Before'")) dict_val = self._prepare_automated_actions_id( action, time, moment, properties, is_create ) - property_vals = vals.get("pms_property_ids") - property_vals_ids = property_vals[0][2] - pms_properties = [] - pms_property_ids = self.env["pms.property"].search([]) - for pms_property in pms_property_ids: - pms_properties.append(pms_property.id) - if pms_properties == property_vals_ids: - vals.update({"pms_property_ids": False}) action_server_vals = { "name": name, "state": "email", "usage": "ir_cron", - "model_id": dict_val["model_id"].id, + "model_id": dict_val["model_id"], } action_server = self.env["ir.actions.server"].create(action_server_vals) model_field = dict_val["model_field"] @@ -131,6 +125,11 @@ class PmsAutomatedMails(models.Model): def write(self, vals): result = super(PmsAutomatedMails, self).write(vals) is_create = False + if ( + self.action in ("creation", "write", "cancel", "invoice") + and self.moment == "before" + ): + raise UserError(_("The moment for this action cannot be 'Before'")) dict_val = self._prepare_automated_actions_id( self.action, self.time, self.moment, self.pms_property_ids, is_create ) @@ -140,7 +139,7 @@ class PmsAutomatedMails(models.Model): "name": self.name, "state": "email", "usage": "ir_cron", - "model_id": dict_val["model_id"].id, + "model_id": dict_val["model_id"], } action_server.write(action_server_vals) model_field = dict_val["model_field"] @@ -182,14 +181,13 @@ class PmsAutomatedMails(models.Model): trigger = False model_field = False model_id = False + filter_domain = [] today = fields.Date.today() - pms_property_ids = self._get_pms_property_ids(properties, is_create) - filter_domain = [("pms_property_id", "in", pms_property_ids)] - if action in ("creation", "write", "cancel", "invoice") and moment == "before": - raise UserError(_("The moment for this action cannot be 'Before'")) # action: create reservation if action == "creation": - model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) + model_id = ( + self.env["ir.model"].search([("model", "=", "pms.reservation")]).id + ) if moment == "in_act": trigger = "on_create" time = 0 @@ -200,12 +198,9 @@ class PmsAutomatedMails(models.Model): ) # action: write and cancel reservation if action == "write" or action == "cancel": - model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) - if action == "cancel": - filter_domain = [ - ("state", "=", "cancelled"), - ("pms_property_id", "in", pms_property_ids), - ] + model_id = ( + self.env["ir.model"].search([("model", "=", "pms.reservation")]).id + ) if moment == "in_act": trigger = "on_write" time = 0 @@ -214,9 +209,15 @@ class PmsAutomatedMails(models.Model): model_field = self.env["ir.model.fields"].search( [("model", "=", "pms.reservation"), ("name", "=", "write_date")] ) + if action == "cancel": + filter_domain = [ + ("state", "=", "cancelled"), + ] # action: checkin if action == "checkin": - model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) + 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", "=", "checkin")] @@ -225,13 +226,14 @@ class PmsAutomatedMails(models.Model): time = 0 filter_domain = [ ("checkin", "=", str(today)), - ("pms_property_id", "in", pms_property_ids), ] elif moment == "before": time = time * (-1) # action: checkout if action == "checkout": - model_id = self.env["ir.model"].search([("name", "=", "Reservation")]) + 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")] @@ -240,14 +242,15 @@ class PmsAutomatedMails(models.Model): time = 0 filter_domain = [ ("checkout", "=", str(today)), - ("pms_property_id", "in", pms_property_ids), ] elif moment == "before": time = time * (-1) # action: payments if action == "payment": - model_id = self.env["ir.model"].search( - [("name", "=", "Payments"), ("transient", "=", False)] + model_id = ( + self.env["ir.model"] + .search([("model", "=", "account.payment"), ("transient", "=", False)]) + .id ) if moment == "in_act": trigger = "on_creation" @@ -262,17 +265,21 @@ class PmsAutomatedMails(models.Model): ) if moment == "before": time = time * (-1) - # TODO: create automated action when the act be 'invoice' + # TODO: create automated action when the act is 'invoice' # action: invoices # if action == "invoice": - # model_id = self.env["ir.model"].search([("name", "=", "Journal Entry")]) + # model_id = self.env["ir.model"].search( + # [("model", "=", "account.move")] + # ).id # filter_domain = [ # ("folio_ids", "!=", False), - # ("pms_property_id", "in", pms_property_ids), # ] # if moment == "in_act": # trigger = "on_create" # time = 0 + pms_property_ids = self._get_pms_property_ids(properties, is_create) + if pms_property_ids: + filter_domain.append(("pms_property_id", "in", pms_property_ids)) result = { "trigger": trigger, "model_field": model_field, @@ -286,17 +293,7 @@ class PmsAutomatedMails(models.Model): pms_property_ids = [] if is_create: pms_property_ids = properties[0][2] - if not pms_property_ids: - self.pms_property_ids = False - properties = self.env["pms.property"].search([]) - for pms_property in properties: - pms_property_ids.append(pms_property.id) else: - if not properties: - properties = self.env["pms.property"].search([]) - for pms_property in properties: - pms_property_ids.append(pms_property.id) - else: - for pms_property in properties: - pms_property_ids.append(pms_property.id) + for pms_property in properties: + pms_property_ids.append(pms_property.id) return pms_property_ids From 2d021bb17390ca9aa7340d79d8dccc24f31d2af5 Mon Sep 17 00:00:00 2001 From: braisab Date: Wed, 21 Apr 2021 20:33:55 +0200 Subject: [PATCH 08/15] [REF] refactor _prepare_automated_actions_id(), ceate() and write() --- pms/models/pms_automated_mails.py | 340 ++++++++++++++++++------------ 1 file changed, 204 insertions(+), 136 deletions(-) diff --git a/pms/models/pms_automated_mails.py b/pms/models/pms_automated_mails.py index 3f5fb8db0..175a8b661 100644 --- a/pms/models/pms_automated_mails.py +++ b/pms/models/pms_automated_mails.py @@ -88,7 +88,6 @@ class PmsAutomatedMails(models.Model): dict_val = self._prepare_automated_actions_id( action, time, moment, properties, is_create ) - action_server_vals = { "name": name, "state": "email", @@ -96,28 +95,30 @@ class PmsAutomatedMails(models.Model): "model_id": dict_val["model_id"], } action_server = self.env["ir.actions.server"].create(action_server_vals) + automated_actions_vals = { + "active": active, + "action_server_id": action_server.id, + "trigger": dict_val["trigger"], + "filter_domain": dict_val["filter_domain"], + "filter_pre_domain": dict_val["filter_pre_domain"], + "trg_date_range": dict_val["time"], + "trg_date_range_type": date_range_type, + "template_id": template_id, + } model_field = dict_val["model_field"] - if not model_field: - automated_actions_vals = { - "active": active, - "action_server_id": action_server.id, - "trigger": dict_val["trigger"], - "filter_domain": dict_val["filter_domain"], - "trg_date_range": dict_val["time"], - "trg_date_range_type": date_range_type, - "template_id": template_id, - } - else: - automated_actions_vals = { - "active": active, - "action_server_id": action_server.id, - "trigger": dict_val["trigger"], - "trg_date_id": dict_val["model_field"].id, - "filter_domain": dict_val["filter_domain"], - "trg_date_range": dict_val["time"], - "trg_date_range_type": date_range_type, - "template_id": template_id, - } + if model_field: + automated_actions_vals.update( + { + "trg_date_id": dict_val["model_field"].id, + } + ) + trigger_field = dict_val["trigger_fields"] + if trigger_field: + automated_actions_vals.update( + { + "trigger_field_ids": dict_val["trigger_fields"].ids, + } + ) automated_action = self.env["base.automation"].create(automated_actions_vals) vals.update({"automated_actions_id": automated_action.id}) return super(PmsAutomatedMails, self).create(vals) @@ -142,28 +143,30 @@ class PmsAutomatedMails(models.Model): "model_id": dict_val["model_id"], } action_server.write(action_server_vals) + automated_actions_vals = { + "active": self.active, + "action_server_id": action_server.id, + "trigger": dict_val["trigger"], + "filter_domain": dict_val["filter_domain"], + "filter_pre_domain": dict_val["filter_pre_domain"], + "trg_date_range": dict_val["time"], + "trg_date_range_type": self.time_type, + "template_id": self.template_id, + } model_field = dict_val["model_field"] - if not model_field: - automated_actions_vals = { - "active": self.active, - "action_server_id": action_server.id, - "trigger": dict_val["trigger"], - "filter_domain": dict_val["filter_domain"], - "trg_date_range": dict_val["time"], - "trg_date_range_type": self.time_type, - "template_id": self.template_id, - } - else: - automated_actions_vals = { - "active": self.active, - "action_server_id": action_server.id, - "trigger": dict_val["trigger"], - "trg_date_id": dict_val["model_field"].id, - "filter_domain": dict_val["filter_domain"], - "trg_date_range": dict_val["time"], - "trg_date_range_type": self.time_type, - "template_id": self.template_id, - } + if model_field: + automated_actions_vals.update( + { + "trg_date_id": dict_val["model_field"].id, + } + ) + trigger_field = dict_val["trigger_fields"] + if trigger_field: + automated_actions_vals.update( + { + "trigger_field_ids": dict_val["trigger_fields"].ids, + } + ) automated_actions_id.write(automated_actions_vals) vals.update({"automated_actions_id": automated_actions_id.id}) return result @@ -175,117 +178,182 @@ class PmsAutomatedMails(models.Model): action_server.unlink() return super(PmsAutomatedMails, self).unlink() + @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 + 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")] + ) + result = { + "model_id": model_id, + "trigger": trigger, + "model_field": model_field, + "time": time, + } + return result + + @api.model + def _get_auto_action_fields_in_write_or_cancel_action(self, moment, time): + model_field = False + model_id = self.env["ir.model"].search([("model", "=", "pms.reservation")]).id + if moment == "in_act": + trigger = "on_write" + time = 0 + else: + trigger = "on_time" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "write_date")] + ) + result = { + "model_id": model_id, + "trigger": trigger, + "model_field": model_field, + "time": time, + } + return result + + @api.model + def _get_auto_action_fields_in_checkin_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", "=", "checkin")] + ) + if moment == "before": + time = time * (-1) + if moment == "in_act": + trigger = "on_write" + time = 0 + result = { + "model_id": model_id, + "trigger": trigger, + "model_field": model_field, + "time": time, + } + return result + + @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")] + ) + if moment == "before": + time = time * (-1) + if moment == "in_act": + trigger = "on_write" + time = 0 + result = { + "model_id": model_id, + "trigger": trigger, + "model_field": model_field, + "time": time, + } + return result + + @api.model + def _get_auto_action_fields_in_payment_action(self, moment, time): + model_field = False + model_id = ( + self.env["ir.model"] + .search([("model", "=", "account.payment"), ("transient", "=", False)]) + .id + ) + if moment == "in_act": + trigger = "on_create" + time = 0 + else: + trigger = "on_time" + model_field = self.env["ir.model.fields"].search( + [("model", "=", "account.payment"), ("name", "=", "date")] + ) + if moment == "before": + time = time * (-1) + result = { + "model_id": model_id, + "trigger": trigger, + "model_field": model_field, + "time": time, + } + return result + + @api.model + def _get_auto_action_fields_in_invoice_action(self, moment, time): + trigger = False + model_id = self.env["ir.model"].search([("model", "=", "account.move")]).id + if moment == "in_act": + trigger = "on_create" + time = 0 + result = { + "model_id": model_id, + "time": time, + "trigger": trigger, + "model_field": False, + } + return result + def _prepare_automated_actions_id( self, action, time, moment, properties, is_create ): - trigger = False - model_field = False - model_id = False filter_domain = [] - today = fields.Date.today() - # action: create reservation + filter_pre_domain = [] + trigger_fields = False + dict_val = {} if action == "creation": - model_id = ( - self.env["ir.model"].search([("model", "=", "pms.reservation")]).id + dict_val = self._get_auto_action_fields_in_creation_action(moment, time) + elif action == "write" or action == "cancel": + dict_val = self._get_auto_action_fields_in_write_or_cancel_action( + moment, time ) - 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")] - ) - # action: write and cancel reservation - if action == "write" or action == "cancel": - model_id = ( - self.env["ir.model"].search([("model", "=", "pms.reservation")]).id - ) - if moment == "in_act": - trigger = "on_write" - time = 0 - else: - trigger = "on_time" - model_field = self.env["ir.model.fields"].search( - [("model", "=", "pms.reservation"), ("name", "=", "write_date")] - ) if action == "cancel": filter_domain = [ ("state", "=", "cancelled"), ] - # action: checkin - if action == "checkin": - 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", "=", "checkin")] - ) + elif action == "checkin": + dict_val = self._get_auto_action_fields_in_checkin_action(moment, time) if moment == "in_act": - time = 0 - filter_domain = [ - ("checkin", "=", str(today)), - ] - elif moment == "before": - time = time * (-1) - # action: checkout - if action == "checkout": - 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")] - ) - if moment == "in_act": - time = 0 - filter_domain = [ - ("checkout", "=", str(today)), - ] - elif moment == "before": - time = time * (-1) - # action: payments - if action == "payment": - model_id = ( - self.env["ir.model"] - .search([("model", "=", "account.payment"), ("transient", "=", False)]) - .id - ) - if moment == "in_act": - trigger = "on_creation" - model_field = self.env["ir.model.fields"].search( - [("model", "=", "account.payment"), ("name", "=", "create_date")] + trigger_fields = self.env["ir.model.fields"].search( + [("model", "=", "pms.reservation"), ("name", "=", "state")] ) - time = 0 - else: - trigger = "on_time" - model_field = self.env["ir.model.fields"].search( - [("model", "=", "account.payment"), ("name", "=", "date")] + filter_pre_domain = [("state", "=", "confirm")] + filter_domain = [ + ("state", "=", "onboard"), + ] + elif action == "checkout": + 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")] ) - if moment == "before": - time = time * (-1) - # TODO: create automated action when the act is 'invoice' - # action: invoices - # if action == "invoice": - # model_id = self.env["ir.model"].search( - # [("model", "=", "account.move")] - # ).id - # filter_domain = [ - # ("folio_ids", "!=", False), - # ] - # if moment == "in_act": - # trigger = "on_create" - # time = 0 + filter_pre_domain = [("state", "=", "onboard")] + filter_domain = [ + ("state", "=", "out"), + ] + elif action == "payment": + dict_val = self._get_auto_action_fields_in_payment_action(moment, time) + elif action == "invoice": + dict_val = self._get_auto_action_fields_in_invoice_action(moment, time) + filter_domain = [ + ("folio_ids", "!=", False), + ] pms_property_ids = self._get_pms_property_ids(properties, is_create) if pms_property_ids: filter_domain.append(("pms_property_id", "in", pms_property_ids)) result = { - "trigger": trigger, - "model_field": model_field, + "trigger": dict_val["trigger"], + "model_field": dict_val["model_field"], + "trigger_fields": trigger_fields, + "filter_pre_domain": filter_pre_domain, "filter_domain": filter_domain, - "time": time, - "model_id": model_id, + "time": dict_val["time"], + "model_id": dict_val["model_id"], } return result From 68b85031132a4486e3c6e96c6e5c066748abca32 Mon Sep 17 00:00:00 2001 From: braisab Date: Tue, 24 Aug 2021 19:52:53 +0200 Subject: [PATCH 09/15] [IMP]: Added email_information and privacy_policy fields in pms.property --- pms/models/pms_property.py | 8 ++++++++ pms/views/pms_property_views.xml | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index 2656f4239..a15e283c8 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -115,6 +115,14 @@ class PmsProperty(models.Model): compute="_compute_availability", ) + mail_information = fields.Char( + string="Mail Information", + ) + + privacy_policy = fields.Char( + string="Privacy Policy" + ) + @api.depends_context( "checkin", "checkout", diff --git a/pms/views/pms_property_views.xml b/pms/views/pms_property_views.xml index 4ac88fb28..f2177a632 100644 --- a/pms/views/pms_property_views.xml +++ b/pms/views/pms_property_views.xml @@ -85,6 +85,12 @@ + + + + + + From eaeb86eb8f447f3487c682a85422a5b6648ff33f Mon Sep 17 00:00:00 2001 From: braisab Date: Wed, 1 Sep 2021 22:19:23 +0200 Subject: [PATCH 10/15] [IMP]: Added automated mails in data and confirmed, modified and cancelled mail templates --- pms/__manifest__.py | 3 + ...s_cancelled_reservation_email_template.xml | 96 +++++++++++ ...s_confirmed_reservation_email_template.xml | 151 +++++++++++++++++ pms/data/pms_data.xml | 35 +++- ...ms_modified_reservation_email_template.xml | 152 ++++++++++++++++++ 5 files changed, 436 insertions(+), 1 deletion(-) create mode 100644 pms/data/pms_cancelled_reservation_email_template.xml create mode 100644 pms/data/pms_confirmed_reservation_email_template.xml create mode 100644 pms/data/pms_modified_reservation_email_template.xml diff --git a/pms/__manifest__.py b/pms/__manifest__.py index 817de0650..5534d5e71 100644 --- a/pms/__manifest__.py +++ b/pms/__manifest__.py @@ -33,6 +33,9 @@ "security/ir.model.access.csv", "data/cron_jobs.xml", "data/pms_sequence.xml", + "data/pms_confirmed_reservation_email_template.xml", + "data/pms_modified_reservation_email_template.xml", + "data/pms_cancelled_reservation_email_template.xml", "data/pms_data.xml", "data/traveller_report_paperformat.xml", "report/pms_folio.xml", diff --git a/pms/data/pms_cancelled_reservation_email_template.xml b/pms/data/pms_cancelled_reservation_email_template.xml new file mode 100644 index 000000000..e9b264eae --- /dev/null +++ b/pms/data/pms_cancelled_reservation_email_template.xml @@ -0,0 +1,96 @@ + + + + + Cancelled Reservation + + Your reservation in ${object.pms_property_id.name} has been cancelled + ${object.pms_property_id.partner_id.email | safe} + ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} + + + + + +
+ + + + + + + + + + + + +
+ + + +
+
+ % if object.pms_property_id.partner_id.street +

${object.pms_property_id.partner_id.street}

+ % endif + % if object.pms_property_id.partner_id.street2 +

${object.pms_property_id.partner_id.street2}

+ % endif +

${object.pms_property_id.partner_id.zip}

+

${object.pms_property_id.partner_id.city}

+

${object.pms_property_id.partner_id.country_id.name}

+
+
+
+
+ Hello ${object.partner_id.name or ''},
+ Your reservation at ${object.pms_property_id.name} has been successfully canceled. +
+
+
+ + +
+
+ +
+
If you have questions please contact with us:
+
    +
  • ${object.pms_property_id.name}
  • + % if object.pms_property_id.partner_id.email +
  • Mail: ${object.pms_property_id.partner_id.email}
  • + % endif + % if object.pms_property_id.partner_id.phone +
  • Phone: ${object.pms_property_id.partner_id.phone}
  • + % endif + % if object.pms_property_id.partner_id.mobile +
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • + % endif +
+
+
+
+
+ % if object.pms_property_id.privacy_policy + + +
+ ${object.pms_property_id.privacy_policy} +
+ % endif +
+ % if object.company_id + + +
+ Sent by ${object.company_id.name} +
+
+ % endif +
+
+ ${object.partner_id.lang} +
+
+
diff --git a/pms/data/pms_confirmed_reservation_email_template.xml b/pms/data/pms_confirmed_reservation_email_template.xml new file mode 100644 index 000000000..fd29b76aa --- /dev/null +++ b/pms/data/pms_confirmed_reservation_email_template.xml @@ -0,0 +1,151 @@ + + + + + Confirmed Reservation + + ${object.company_id.name} has confirmed your reservation in ${object.pms_property_id.name} + ${object.pms_property_id.partner_id.email | safe} + ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} + + + + + +
+ + + + + + + + + + + + + + +
+ + + +
+
+ % if object.pms_property_id.partner_id.street +

${object.pms_property_id.partner_id.street}

+ % endif + % if object.pms_property_id.partner_id.street2 +

${object.pms_property_id.partner_id.street2}

+ % endif +

${object.pms_property_id.partner_id.zip}

+

${object.pms_property_id.partner_id.city}

+

${object.pms_property_id.partner_id.country_id.name}

+
+
+
+
+ Hello ${object.partner_id.name or ''},
+ We are happy to confirm your reservation in ${object.pms_property_id.name} +
+
+ See you soon,
+ +
+ ${object.company_id.name} +
+
+
+
+
+
Reservation Details
+ + + + +
+ + + + + + + + + + + + + +
+
+
+
From ${object.checkin} At ${object.arrival_hour}
+
To ${object.checkout} At ${object.departure_hour}
+
TZ ${object.pms_property_id.tz}
+
+
+
+
+
+
Room: ${object.room_type_id.name}
+
+
+
+
+
+
Price: ${object.price_room_services_set} ${object.pms_property_id.country_id.currency_id.symbol}
+
+
+
+ % if object.pms_property_id.mail_information +
+
Additional Information
+ ${object.pms_property_id.mail_information|safe} + % endif +
+
+
+ +
+ Questions about the reservation? +
Please contact with us:
+
    +
  • ${object.pms_property_id.name}
  • + % if object.pms_property_id.partner_id.email +
  • Mail: ${object.pms_property_id.partner_id.email}
  • + % endif + % if object.pms_property_id.partner_id.phone +
  • Phone: ${object.pms_property_id.partner_id.phone}
  • + % endif + % if object.pms_property_id.partner_id.mobile +
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • + % endif +
+
+
+
+
+ % if object.pms_property_id.privacy_policy + + +
+ ${object.pms_property_id.privacy_policy|safe} +
+ % endif +
+ % if object.company_id + + +
+ Sent by ${object.company_id.name} +
+
+ % endif +
+
+ ${object.partner_id.lang} +
+
+
diff --git a/pms/data/pms_data.xml b/pms/data/pms_data.xml index edfae1c26..57bd9e782 100644 --- a/pms/data/pms_data.xml +++ b/pms/data/pms_data.xml @@ -135,7 +135,40 @@ if (permit_first_letter.upper() in ['X','Y']) and id_number.name[1:8].isdigit() else: failed = True
- + + + + Confirmed Reservation + False + + creation + + in_act + + + Modified Reservation + False + + write + + in_act + + + Cancelled Reservation + False + + cancel + + in_act diff --git a/pms/data/pms_modified_reservation_email_template.xml b/pms/data/pms_modified_reservation_email_template.xml new file mode 100644 index 000000000..a334916df --- /dev/null +++ b/pms/data/pms_modified_reservation_email_template.xml @@ -0,0 +1,152 @@ + + + + + Modified Reservation + + Your reservation in ${object.pms_property_id.name} has been modified + ${object.pms_property_id.partner_id.email | safe} + ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} + + + + + +
+ + + + + + + + + + + + + + + +
+ + + +
+
+ % if object.pms_property_id.partner_id.street +

${object.pms_property_id.partner_id.street}

+ % endif + % if object.pms_property_id.partner_id.street2 +

${object.pms_property_id.partner_id.street2}

+ % endif +

${object.pms_property_id.partner_id.zip}

+

${object.pms_property_id.partner_id.city}

+

${object.pms_property_id.partner_id.country_id.name}

+
+
+
+
+ Hello ${object.partner_id.name or ''},
+ Your reservation in ${object.pms_property_id.name} has been modified +
+
+ See you soon,
+ +
+ ${object.company_id.name} +
+
+
+
+
+
Reservation Details
+ + + + +
+ + + + + + + + + + + + + +
+
+
+
From ${object.checkin} At ${object.arrival_hour}
+
To ${object.checkout} At ${object.departure_hour}
+
TZ ${object.pms_property_id.tz}
+
+
+
+
+
+
Room: ${object.room_type_id.name}
+
+
+
+
+
+
Price: ${object.price_total} ${object.pms_property_id.country_id.currency_id.symbol}
+
+
+
+ % if object.pms_property_id.mail_information +
+
Additional Information
+

${object.pms_property_id.mail_information|safe}

+ % endif +
+
+
+ +
+ Questions about the reservation? +
Please contact with us:
+
    +
  • ${object.pms_property_id.name}
  • + % if object.pms_property_id.partner_id.email +
  • Mail: ${object.pms_property_id.partner_id.email}
  • + % endif + % if object.pms_property_id.partner_id.phone +
  • Phone: ${object.pms_property_id.partner_id.phone}
  • + % endif + % if object.pms_property_id.partner_id.mobile +
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • + % endif +
+
+
+
+
+ % if object.pms_property_id.privacy_policy + + +
+ ${object.pms_property_id.privacy_policy|safe} +
+ % endif +
+ % if object.company_id + + +
+ Sent by ${object.company_id.name} +
+
+ % endif +
+
+ ${object.partner_id.lang} +
+
+
From 38ce8debb624b657f02dda5e85e632feb18c44cf Mon Sep 17 00:00:00 2001 From: braisab Date: Wed, 1 Sep 2021 22:22:16 +0200 Subject: [PATCH 11/15] [IMP]:change mail_information and privacy_policy fields from Text to Html type and added default property email templates --- pms/models/pms_property.py | 35 +++++++++++++++++++++++++++++--- pms/views/pms_property_views.xml | 14 ++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index a15e283c8..2bd052bc6 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -115,12 +115,41 @@ class PmsProperty(models.Model): compute="_compute_availability", ) - mail_information = fields.Char( + mail_information = fields.Html( string="Mail Information", + help="Additional information of the mail" ) - privacy_policy = fields.Char( - string="Privacy Policy" + privacy_policy = fields.Html( + string="Privacy Policy", + help="Mail privacy policy " + ) + + property_confirmed_template = fields.Many2one( + string="Confirmation Template", + help="Confirmation email template", + comodel_name="mail.template", + default=lambda self: self.env["mail.template"] + .search([("name", "=", "Confirmed Reservation")]) + .id, + ) + + property_modified_template = fields.Many2one( + string="Modification Template", + help="Modification email template", + comodel_name="mail.template", + default=lambda self: self.env["mail.template"] + .search([("name", "=", "Modified Reservation")]) + .id, + ) + + property_canceled_template = fields.Many2one( + string="Cancellation Template", + help="Cancellation email template", + comodel_name="mail.template", + default=lambda self: self.env["mail.template"] + .search([("name", "=", "Cancelled Reservation")]) + .id, ) @api.depends_context( diff --git a/pms/views/pms_property_views.xml b/pms/views/pms_property_views.xml index f2177a632..f62b968f8 100644 --- a/pms/views/pms_property_views.xml +++ b/pms/views/pms_property_views.xml @@ -86,9 +86,17 @@ - - - + + + + + + + + From 3915a8c439e9cea94d3491bb09797c5808245e91 Mon Sep 17 00:00:00 2001 From: braisab Date: Wed, 1 Sep 2021 22:23:08 +0200 Subject: [PATCH 12/15] [IMP]: added buttons from send email in pms.reservation --- ...s_cancelled_reservation_email_template.xml | 114 +++++++--- ...s_confirmed_reservation_email_template.xml | 207 +++++++++++++---- ...ms_modified_reservation_email_template.xml | 210 +++++++++++++----- pms/models/__init__.py | 2 +- pms/models/mail_compose_message.py | 49 ++-- pms/models/pms_property.py | 8 +- pms/models/pms_reservation.py | 81 +++++++ pms/views/pms_automated_mails_views.xml | 3 + pms/views/pms_reservation_views.xml | 49 ++++ 9 files changed, 577 insertions(+), 146 deletions(-) diff --git a/pms/data/pms_cancelled_reservation_email_template.xml b/pms/data/pms_cancelled_reservation_email_template.xml index e9b264eae..31ab04cc0 100644 --- a/pms/data/pms_cancelled_reservation_email_template.xml +++ b/pms/data/pms_cancelled_reservation_email_template.xml @@ -1,38 +1,70 @@ - + Cancelled Reservation - - Your reservation in ${object.pms_property_id.name} has been cancelled - ${object.pms_property_id.partner_id.email | safe} - ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} + + Your reservation in ${object.pms_property_id.name} has been cancelled + ${object.pms_property_id.partner_id.email | safe} + ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} -
- +
+
- +
@@ -42,22 +74,38 @@
% if object.pms_property_id.partner_id.street -

${object.pms_property_id.partner_id.street}

+

${object.pms_property_id.partner_id.street}

% endif % if object.pms_property_id.partner_id.street2 -

${object.pms_property_id.partner_id.street2}

+

${object.pms_property_id.partner_id.street2}

% endif -

${object.pms_property_id.partner_id.zip}

-

${object.pms_property_id.partner_id.city}

-

${object.pms_property_id.partner_id.country_id.name}

+

${object.pms_property_id.partner_id.zip}

+

${object.pms_property_id.partner_id.city}

+

${object.pms_property_id.partner_id.country_id.name}

-
+
- Hello ${object.partner_id.name or ''},
+ Hello ${object.partner_id.name or ''},
Your reservation at ${object.pms_property_id.name} has been successfully canceled.
- +
-
+
-
If you have questions please contact with us:
+
If you have questions please contact with us:
    -
  • ${object.pms_property_id.name}
  • +
  • ${object.pms_property_id.name}
  • % if object.pms_property_id.partner_id.email -
  • Mail: ${object.pms_property_id.partner_id.email}
  • +
  • Mail: ${object.pms_property_id.partner_id.email}
  • % endif % if object.pms_property_id.partner_id.phone -
  • Phone: ${object.pms_property_id.partner_id.phone}
  • +
  • Phone: ${object.pms_property_id.partner_id.phone}
  • % endif % if object.pms_property_id.partner_id.mobile -
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • +
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • % endif
@@ -71,7 +119,13 @@
% if object.pms_property_id.privacy_policy - +
@@ -80,9 +134,19 @@
${object.pms_property_id.privacy_policy}
% if object.company_id - +
- Sent by ${object.company_id.name} + Sent by ${object.company_id.name}
diff --git a/pms/data/pms_confirmed_reservation_email_template.xml b/pms/data/pms_confirmed_reservation_email_template.xml index fd29b76aa..aedc5d3fc 100644 --- a/pms/data/pms_confirmed_reservation_email_template.xml +++ b/pms/data/pms_confirmed_reservation_email_template.xml @@ -1,46 +1,83 @@ - + Confirmed Reservation - - ${object.company_id.name} has confirmed your reservation in ${object.pms_property_id.name} - ${object.pms_property_id.partner_id.email | safe} - ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} + + ${object.company_id.name} has confirmed your reservation in ${object.pms_property_id.name} + ${object.pms_property_id.partner_id.email | safe} + ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} -
- +
+ - +
- +
% if object.pms_property_id.partner_id.street -

${object.pms_property_id.partner_id.street}

+

${object.pms_property_id.partner_id.street}

% endif % if object.pms_property_id.partner_id.street2 -

${object.pms_property_id.partner_id.street2}

+

${object.pms_property_id.partner_id.street2}

% endif -

${object.pms_property_id.partner_id.zip}

-

${object.pms_property_id.partner_id.city}

-

${object.pms_property_id.partner_id.country_id.name}

+

${object.pms_property_id.partner_id.zip}

+

${object.pms_property_id.partner_id.city}

+

${object.pms_property_id.partner_id.country_id.name}

-
+
- Hello ${object.partner_id.name or ''},
+ Hello ${object.partner_id.name or ''},
We are happy to confirm your reservation in ${object.pms_property_id.name}
- See you soon,
+ See you soon,
-
+
${object.company_id.name}
@@ -51,39 +88,77 @@
-
-
Reservation Details
- +
+
Reservation Details
+
- - - - -
-
+
-
From ${object.checkin} At ${object.arrival_hour}
-
To ${object.checkout} At ${object.departure_hour}
-
TZ ${object.pms_property_id.tz}
+
+
From ${object.checkin} At ${object.arrival_hour}
+
To ${object.checkout} At ${object.departure_hour}
+
TZ ${object.pms_property_id.tz}
-
-
+
+
+
-
-
Room: ${object.room_type_id.name}
+
+
+
Room: ${object.room_type_id.name}
-
-
+
+
+
-
-
Price: ${object.price_room_services_set} ${object.pms_property_id.country_id.currency_id.symbol}
+
+
+
Price: ${object.price_room_services_set} ${object.pms_property_id.country_id.currency_id.symbol}
@@ -91,28 +166,46 @@
% if object.pms_property_id.mail_information -
-
Additional Information
+
+
Additional Information
${object.pms_property_id.mail_information|safe} % endif
-
+
- Questions about the reservation? + Questions about the reservation?
Please contact with us:
    -
  • ${object.pms_property_id.name}
  • +
  • ${object.pms_property_id.name}
  • % if object.pms_property_id.partner_id.email -
  • Mail: ${object.pms_property_id.partner_id.email}
  • +
  • Mail: ${object.pms_property_id.partner_id.email}
  • % endif % if object.pms_property_id.partner_id.phone -
  • Phone: ${object.pms_property_id.partner_id.phone}
  • +
  • Phone: ${object.pms_property_id.partner_id.phone}
  • % endif % if object.pms_property_id.partner_id.mobile -
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • +
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • % endif
@@ -126,7 +219,13 @@
% if object.pms_property_id.privacy_policy - +
@@ -135,9 +234,19 @@
${object.pms_property_id.privacy_policy|safe}
% if object.company_id - +
- Sent by ${object.company_id.name} + Sent by ${object.company_id.name}
diff --git a/pms/data/pms_modified_reservation_email_template.xml b/pms/data/pms_modified_reservation_email_template.xml index a334916df..9ca3a0942 100644 --- a/pms/data/pms_modified_reservation_email_template.xml +++ b/pms/data/pms_modified_reservation_email_template.xml @@ -1,47 +1,84 @@ - + Modified Reservation - - Your reservation in ${object.pms_property_id.name} has been modified - ${object.pms_property_id.partner_id.email | safe} - ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} + + Your reservation in ${object.pms_property_id.name} has been modified + ${object.pms_property_id.partner_id.email | safe} + ${(object.email and '"%s" <%s>' % (object.name, object.email) or object.partner_id.email_formatted or '') | safe} -
- +
+ - +
- +
% if object.pms_property_id.partner_id.street -

${object.pms_property_id.partner_id.street}

+

${object.pms_property_id.partner_id.street}

% endif % if object.pms_property_id.partner_id.street2 -

${object.pms_property_id.partner_id.street2}

+

${object.pms_property_id.partner_id.street2}

% endif -

${object.pms_property_id.partner_id.zip}

-

${object.pms_property_id.partner_id.city}

-

${object.pms_property_id.partner_id.country_id.name}

+

${object.pms_property_id.partner_id.zip}

+

${object.pms_property_id.partner_id.city}

+

${object.pms_property_id.partner_id.country_id.name}

-
+
- Hello ${object.partner_id.name or ''},
+ Hello ${object.partner_id.name or ''},
Your reservation in ${object.pms_property_id.name} has been modified
- See you soon,
+ See you soon,
-
+
${object.company_id.name}
@@ -52,39 +89,77 @@
-
-
Reservation Details
- +
+
Reservation Details
+
- - - - -
-
+
-
From ${object.checkin} At ${object.arrival_hour}
-
To ${object.checkout} At ${object.departure_hour}
-
TZ ${object.pms_property_id.tz}
+
+
From ${object.checkin} At ${object.arrival_hour}
+
To ${object.checkout} At ${object.departure_hour}
+
TZ ${object.pms_property_id.tz}
-
-
+
+
+
-
-
Room: ${object.room_type_id.name}
+
+
+
Room: ${object.room_type_id.name}
-
-
+
+
+
-
-
Price: ${object.price_total} ${object.pms_property_id.country_id.currency_id.symbol}
+
+
+
Price: ${object.price_total} ${object.pms_property_id.country_id.currency_id.symbol}
@@ -92,28 +167,47 @@
% if object.pms_property_id.mail_information -
-
Additional Information
-

${object.pms_property_id.mail_information|safe}

+
+
Additional Information
+

${object.pms_property_id.mail_information|safe}

% endif
-
+
- Questions about the reservation? + Questions about the reservation?
Please contact with us:
    -
  • ${object.pms_property_id.name}
  • +
  • ${object.pms_property_id.name}
  • % if object.pms_property_id.partner_id.email -
  • Mail: ${object.pms_property_id.partner_id.email}
  • +
  • Mail: ${object.pms_property_id.partner_id.email}
  • % endif % if object.pms_property_id.partner_id.phone -
  • Phone: ${object.pms_property_id.partner_id.phone}
  • +
  • Phone: ${object.pms_property_id.partner_id.phone}
  • % endif % if object.pms_property_id.partner_id.mobile -
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • +
  • Mobile: ${object.pms_property_id.partner_id.mobile}
  • % endif
@@ -127,7 +221,13 @@
% if object.pms_property_id.privacy_policy - +
@@ -136,9 +236,19 @@
${object.pms_property_id.privacy_policy|safe}
% if object.company_id - +
- Sent by ${object.company_id.name} + Sent by ${object.company_id.name}
diff --git a/pms/models/__init__.py b/pms/models/__init__.py index 518a2ba19..8b246ec75 100644 --- a/pms/models/__init__.py +++ b/pms/models/__init__.py @@ -31,7 +31,7 @@ from . import product_pricelist_item from . import res_partner from . import pms_sale_channel -# from . import mail_compose_message +from . import mail_compose_message from . import pms_room_type_class from . import pms_room_closure_reason from . import pms_service_line diff --git a/pms/models/mail_compose_message.py b/pms/models/mail_compose_message.py index 62bbaad3b..e76de0ec6 100644 --- a/pms/models/mail_compose_message.py +++ b/pms/models/mail_compose_message.py @@ -1,24 +1,43 @@ # Copyright 2017 Alexandre Díaz # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import api, models class MailComposeMessage(models.TransientModel): _inherit = "mail.compose.message" + @api.model + def default_get(self, fields): + res = super(MailComposeMessage, self).default_get(fields) + template = self.env["mail.template"].browse(self._context.get("template_id")) + res.update( + { + "composition_mode": "comment", + "attachment_ids": False, + "template_id": template.id, + } + ) + 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 - return super(MailComposeMessage, self).send_mail(auto_commit=auto_commit) + # 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"): + reservation = self.env["pms.reservation"].search( + [("id", "=", self._context.get("record_id"))] + ) + reservation.is_mail_send = True + return res diff --git a/pms/models/pms_property.py b/pms/models/pms_property.py index 2bd052bc6..a524ed083 100644 --- a/pms/models/pms_property.py +++ b/pms/models/pms_property.py @@ -116,14 +116,10 @@ class PmsProperty(models.Model): ) mail_information = fields.Html( - string="Mail Information", - help="Additional information of the mail" + string="Mail Information", help="Additional information of the mail" ) - privacy_policy = fields.Html( - string="Privacy Policy", - help="Mail privacy policy " - ) + privacy_policy = fields.Html(string="Privacy Policy", help="Mail privacy policy ") property_confirmed_template = fields.Many2one( string="Confirmation Template", diff --git a/pms/models/pms_reservation.py b/pms/models/pms_reservation.py index c2b3c2b63..3e0715b33 100644 --- a/pms/models/pms_reservation.py +++ b/pms/models/pms_reservation.py @@ -644,6 +644,19 @@ class PmsReservation(models.Model): add_possible_customer = fields.Boolean(string="Add possible Customer") + is_mail_send = fields.Boolean(string="Mail Sent", default=False) + + is_modified_reservation = fields.Boolean( + string="Is A Modified Reservation", + compute="_compute_is_modified_reservation", + readonly=False, + store=True, + ) + + lang = fields.Many2one( + string="Language", comodel_name="res.lang", compute="_compute_lang" + ) + def _compute_date_order(self): for record in self: record.date_order = datetime.datetime.today() @@ -1428,6 +1441,25 @@ class PmsReservation(models.Model): for record in self: self.env["pms.folio"]._apply_is_possible_existing_customer_id(record) + @api.depends("checkin", "checkout") + def _compute_is_modified_reservation(self): + 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: + record.is_modified_reservation = True + record.is_mail_send = False + else: + record.is_modified_reservation = False + + @api.depends("partner_id") + def _compute_lang(self): + for record in self: + if record.partner_id: + record.lang = record.partner_id.lang + else: + record.lang = self.env["res.lang"].get_installed() + def _search_allowed_checkin(self, operator, value): if operator not in ("=",): raise UserError( @@ -1666,6 +1698,54 @@ class PmsReservation(models.Model): }, } + def action_open_mail_composer(self): + self.ensure_one() + template = False + if ( + not self.is_mail_send + and not self.is_modified_reservation + and self.state not in "cancel" + ): + template = self.env.ref( + "pms.confirmed_reservation_email", raise_if_not_found=False + ) + elif ( + not self.is_mail_send + and self.is_modified_reservation + and self.state not in "cancel" + ): + template = self.env.ref( + "pms.modified_reservation_email", raise_if_not_found=False + ) + elif not self.is_mail_send and self.state in "cancel": + template = self.env.ref( + "pms.cancelled_reservation_email", raise_if_not_found=False + ) + compose_form = self.env.ref( + "mail.email_compose_message_wizard_form", raise_if_not_found=False + ) + ctx = dict( + model="pms.reservation", + default_res_model="pms.reservation", + 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 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, + } + @api.model def name_search(self, name="", args=None, operator="ilike", limit=100): if args is None: @@ -1811,6 +1891,7 @@ class PmsReservation(models.Model): else: record.state = "cancel" record.folio_id._compute_amount() + record.is_mail_send = False def action_assign(self): for record in self: diff --git a/pms/views/pms_automated_mails_views.xml b/pms/views/pms_automated_mails_views.xml index 1dd6f30ff..4f49aa5d9 100644 --- a/pms/views/pms_automated_mails_views.xml +++ b/pms/views/pms_automated_mails_views.xml @@ -51,6 +51,9 @@ + + + diff --git a/pms/views/pms_reservation_views.xml b/pms/views/pms_reservation_views.xml index d9c3169ef..7c7e0bed1 100644 --- a/pms/views/pms_reservation_views.xml +++ b/pms/views/pms_reservation_views.xml @@ -43,7 +43,27 @@ states="onboard,departure_delayed" type="object" /> +