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 + + +