commit
a65b2013a1
|
|
@ -1,19 +1,26 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
{
|
{
|
||||||
'name': "System Notification",
|
'name': "System Notification",
|
||||||
'version': '18.0.1.0.0',
|
|
||||||
'summary': """""",
|
'summary': """""",
|
||||||
|
|
||||||
'description': """
|
'description': """
|
||||||
""",
|
""",
|
||||||
'category': 'Odex30-base', # تم تغيير الفئة
|
'category' : 'Odex30-base',
|
||||||
'depends': ['base_automation', 'mail'],
|
|
||||||
|
# Categories can be used to filter modules in modules listing
|
||||||
|
# Check https://github.com/odoo/odoo/blob/11.0/odoo/addons/base/module/module_data.xml
|
||||||
|
# for the full list
|
||||||
|
|
||||||
|
# any module necessary for this one to work correctly
|
||||||
|
'depends': ['base_automation','mail'],
|
||||||
|
|
||||||
|
# always loaded
|
||||||
'data': [
|
'data': [
|
||||||
'security/ir.model.access.csv',
|
'security/ir.model.access.csv',
|
||||||
'views/views.xml',
|
'views/views.xml',
|
||||||
'views/group_state_notification.xml',
|
'views/group_state_notification.xml',
|
||||||
'data/mail_data.xml',
|
'data/mail_data.xml',
|
||||||
],
|
],
|
||||||
'installable': True,
|
|
||||||
'application': False,
|
|
||||||
'auto_install': False,
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@
|
||||||
<table border="0" cellpadding="0" cellspacing="0" width="590"
|
<table border="0" cellpadding="0" cellspacing="0" width="590"
|
||||||
style="padding: 24px; background-color: white; color: #454748; border-collapse:separate;">
|
style="padding: 24px; background-color: white; color: #454748; border-collapse:separate;">
|
||||||
<tbody>
|
<tbody>
|
||||||
<!-- HEADER -->
|
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" style="min-width: 590px;">
|
<td align="center" style="min-width: 590px;">
|
||||||
<table border="0" cellpadding="0" cellspacing="0" width="100%"
|
<table border="0" cellpadding="0" cellspacing="0" width="100%"
|
||||||
|
|
@ -32,13 +31,11 @@
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- CONTENT -->
|
|
||||||
<tr>
|
<tr>
|
||||||
<td style="min-width: 590px;">
|
<td style="min-width: 590px;">
|
||||||
<t t-out="message.body"/>
|
<t t-out="message.body"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<!-- FOOTER -->
|
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center" style="min-width: 590px; padding: 0 8px 0 8px; font-size:11px;">
|
<td align="center" style="min-width: 590px; padding: 0 8px 0 8px; font-size:11px;">
|
||||||
<hr width="100%"
|
<hr width="100%"
|
||||||
|
|
@ -68,4 +65,4 @@
|
||||||
</table>
|
</table>
|
||||||
</template>
|
</template>
|
||||||
</data>
|
</data>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
@ -1,25 +1,16 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from odoo import models, fields, api
|
from odoo import models, fields
|
||||||
|
|
||||||
|
|
||||||
class BaseGroupAutomation(models.Model):
|
class BaseGroupAutomation(models.Model):
|
||||||
_name = 'automation.group'
|
_name = 'automation.group'
|
||||||
_rec_name = 'model_id'
|
_rec_name = 'model_id'
|
||||||
_description = 'Automation Group'
|
|
||||||
|
|
||||||
model_id = fields.Many2one('ir.model', string="Model", ondelete='cascade', required=True)
|
model_id = fields.Many2one('ir.model', string="Model", ondelete='cascade', required=True)
|
||||||
atuomation_ids = fields.Many2many(
|
atuomation_ids = fields.Many2many(comodel_name='base.automation', relation='automation_state_groups_rel',
|
||||||
comodel_name='base.automation',
|
string='Group States ')
|
||||||
relation='automation_state_groups_rel',
|
|
||||||
string='Group States'
|
|
||||||
)
|
|
||||||
|
|
||||||
def unlink(self):
|
def unlink(self):
|
||||||
"""
|
for recored in self.atuomation_ids:
|
||||||
Delete all record(s) from recordset
|
recored.unlink()
|
||||||
return True on success, False otherwise
|
|
||||||
"""
|
|
||||||
for record in self.atuomation_ids:
|
|
||||||
record.unlink()
|
|
||||||
result = super(BaseGroupAutomation, self).unlink()
|
result = super(BaseGroupAutomation, self).unlink()
|
||||||
return result
|
return result
|
||||||
|
|
|
||||||
|
|
@ -2,154 +2,170 @@
|
||||||
|
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class BaseAutomation(models.Model):
|
class BaseAutomation(models.Model):
|
||||||
_inherit = 'base.automation'
|
_inherit = 'base.automation'
|
||||||
|
|
||||||
# إضافة خيار الإشعار
|
|
||||||
send_notify = fields.Boolean(string='Send Notify', help="Send Notifications Within The System")
|
send_notify = fields.Boolean(string='Send Notify', help="Send Notifications Within The System")
|
||||||
notify_title = fields.Char(string='Notification Title', related='model_id.name')
|
notify_title = fields.Char(string='Notification Title', related='model_id.name')
|
||||||
notify_note = fields.Char(string='Notification Note')
|
notify_note = fields.Char(string='Notification Note')
|
||||||
notify_summary = fields.Char(string='Notification Message')
|
notify_summary = fields.Char(string='Notification Message')
|
||||||
|
|
||||||
notify_to_groups_ids = fields.Many2many(
|
notify_to_groups_ids = fields.Many2many(
|
||||||
comodel_name='res.groups',
|
comodel_name='res.groups',
|
||||||
relation='automation_notifications_to_groups_rel',
|
relation='automation_notifications_to_groups_rel',
|
||||||
string='TO Notify Groups'
|
string='TO Notify Groups'
|
||||||
)
|
)
|
||||||
|
|
||||||
notify_cc_groups_ids = fields.Many2many(
|
notify_cc_groups_ids = fields.Many2many(
|
||||||
comodel_name='res.groups',
|
comodel_name='res.groups',
|
||||||
relation='automation_notifications_cc_groups_rel',
|
relation='automation_notifications_cc_groups_rel',
|
||||||
string='CC Notify Groups'
|
string='CC Notify Groups'
|
||||||
)
|
)
|
||||||
|
hr_notifys = fields.Boolean(string='HR Notifys', help="Send Notifications HR Modules Depend on (Employee Id) only")
|
||||||
hr_notifys = fields.Boolean(
|
direct_manager_notify = fields.Boolean(string='Direct Manager Notify',
|
||||||
string='HR Notifys',
|
help="Send Notification To The Employee's Direct Manager Only")
|
||||||
help="Send Notifications HR Modules Depend on (Employee Id) only"
|
department_manager_notify = fields.Boolean(string='Department Manager Notify',
|
||||||
)
|
help="Send Notification To The Department Manager For The Employee Only")
|
||||||
direct_manager_notify = fields.Boolean(string='Direct Manager Notify', help="Notify direct manager")
|
employee_notify = fields.Boolean(string='Employee Notify',
|
||||||
department_manager_notify = fields.Boolean(string='Department Manager Notify', help="Notify department manager")
|
help="Send Notification To The Employee Only")
|
||||||
employee_notify = fields.Boolean(string='Employee Notify', help="Notify employee")
|
ceo_notify = fields.Boolean(string='CEO Manager',
|
||||||
ceo_notify = fields.Boolean(string='CEO Manager', help="Notify CEO")
|
help="Send Notification To The CEO Manager Only")
|
||||||
hr_manager_notify = fields.Boolean(string='HR Manager', help="Notify HR manager")
|
hr_manager_notify = fields.Boolean(string='HR Manager',
|
||||||
hr_email_notify = fields.Boolean(string='HR E-Mail', help="Notify HR email")
|
help="Send Notification To The HR Manager Only")
|
||||||
services_manager_id = fields.Boolean(string='Services Manager', help="Notify services manager")
|
hr_email_notify = fields.Boolean(string='HR E-Mail',
|
||||||
it_manager_id = fields.Boolean(string='IT Manager', help="Notify IT manager")
|
help="Send Notification To The HR E-Mail Only")
|
||||||
admin_manager_id = fields.Boolean(string='Admin Affairs Manager', help="Notify admin manager")
|
services_manager_id = fields.Boolean(string='Services Manager',
|
||||||
financial_manager_id = fields.Boolean(string='Financial Manager', help="Notify financial manager")
|
help="Send Notification To The Services Manager Only")
|
||||||
cyber_security_id = fields.Boolean(string='Cyber Security', help="Notify cyber security")
|
it_manager_id = fields.Boolean(string='IT Manager',
|
||||||
|
help="Send Notification To The IT Manager Only")
|
||||||
def check_record_access(self, user_id, record, mode='read'):
|
admin_manager_id = fields.Boolean(string='Admin Affairs Manager',
|
||||||
|
help="Send Notification To The Admin Affairs Manager Only")
|
||||||
|
financial_manager_id = fields.Boolean(string='Financial Manager',
|
||||||
|
help="Send Notification To The Financial Manager Only")
|
||||||
|
cyber_security_id = fields.Boolean(string='Cyber Security',
|
||||||
|
help="Send Notification To The Cyber Security Only")
|
||||||
|
def check_user_access(self, user_id, record, mode='read'):
|
||||||
try:
|
try:
|
||||||
record.with_user(user_id).check_access_rule(mode)
|
return record.with_user(user_id).has_access(mode)
|
||||||
return True
|
except Exception:
|
||||||
except:
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def access_users(self, groups, record):
|
def access_users(self, groups, record):
|
||||||
users = []
|
users = []
|
||||||
for group in groups:
|
for group in groups:
|
||||||
for user in group.users:
|
for user in group.users:
|
||||||
if user.partner_id.email not in users and \
|
if user.partner_id.email not in users and self.check_user_access(user_id=user.id, record=record,
|
||||||
self.check_record_access(user_id=user.id, record=record, mode='read') and \
|
mode='read') and user.partner_id.email:
|
||||||
user.partner_id.email:
|
|
||||||
if self.hr_notifys:
|
if self.hr_notifys:
|
||||||
if hasattr(record, 'employee_id') and record.employee_id:
|
if hasattr(record, 'employee_id') and record.employee_id:
|
||||||
emp = record.employee_id.sudo()
|
hr_mail = record.employee_id.sudo().company_id.hr_email
|
||||||
if self.direct_manager_notify and user.id == emp.parent_id.user_id.id:
|
if self.direct_manager_notify:
|
||||||
users.append(user.partner_id.email)
|
if user.id == record.employee_id.sudo().parent_id.user_id.id:
|
||||||
elif self.department_manager_notify and user.id == emp.coach_id.user_id.id:
|
users.append(user.partner_id.email)
|
||||||
users.append(user.partner_id.email)
|
if self.department_manager_notify:
|
||||||
elif self.employee_notify and user.id == emp.user_id.id:
|
if user.id == record.employee_id.sudo().coach_id.user_id.id:
|
||||||
users.append(user.partner_id.email)
|
users.append(user.partner_id.email)
|
||||||
elif self.ceo_notify and user.id == emp.company_id.general_supervisor_id.user_id.id:
|
if self.employee_notify:
|
||||||
users.append(user.partner_id.email)
|
if user.id == record.employee_id.sudo().user_id.id:
|
||||||
elif self.hr_manager_notify and user.id == emp.company_id.hr_manager_id.user_id.id:
|
users.append(user.partner_id.email)
|
||||||
users.append(user.partner_id.email)
|
if self.ceo_notify:
|
||||||
elif self.services_manager_id and user.id == emp.company_id.services_manager_id.user_id.id:
|
if user.id == record.employee_id.sudo().company_id.general_supervisor_id.user_id.id:
|
||||||
users.append(user.partner_id.email)
|
users.append(user.partner_id.email)
|
||||||
elif self.it_manager_id and user.id == emp.company_id.it_manager_id.user_id.id:
|
if self.hr_manager_notify:
|
||||||
users.append(user.partner_id.email)
|
if user.id == record.employee_id.sudo().company_id.hr_manager_id.user_id.id:
|
||||||
elif self.admin_manager_id and user.id == emp.company_id.admin_manager_id.user_id.id:
|
users.append(user.partner_id.email)
|
||||||
users.append(user.partner_id.email)
|
if self.services_manager_id:
|
||||||
elif self.financial_manager_id and user.id == emp.company_id.financial_manager_id.user_id.id:
|
if user.id == record.employee_id.sudo().company_id.services_manager_id.user_id.id:
|
||||||
users.append(user.partner_id.email)
|
users.append(user.partner_id.email)
|
||||||
elif self.cyber_security_id and user.id == emp.company_id.cyber_security_id.user_id.id:
|
if self.it_manager_id:
|
||||||
users.append(user.partner_id.email)
|
if user.id == record.employee_id.sudo().company_id.it_manager_id.user_id.id:
|
||||||
elif self.hr_email_notify and emp.company_id.hr_email and emp.company_id.hr_email not in users:
|
users.append(user.partner_id.email)
|
||||||
users.append(emp.company_id.hr_email)
|
if self.admin_manager_id:
|
||||||
|
if user.id == record.employee_id.sudo().company_id.admin_manager_id.user_id.id:
|
||||||
|
users.append(user.partner_id.email)
|
||||||
|
if self.financial_manager_id:
|
||||||
|
if user.id == record.employee_id.sudo().company_id.financial_manager_id.user_id.id:
|
||||||
|
users.append(user.partner_id.email)
|
||||||
|
if self.cyber_security_id:
|
||||||
|
if user.id == record.employee_id.sudo().company_id.cyber_security_id.user_id.id:
|
||||||
|
users.append(user.partner_id.email)
|
||||||
|
if self.hr_email_notify and hr_mail not in users:
|
||||||
|
users.append(hr_mail)
|
||||||
else:
|
else:
|
||||||
users.append(user.partner_id.email)
|
users.append(user.partner_id.email)
|
||||||
else:
|
else:
|
||||||
users.append(user.partner_id.email)
|
users.append(user.partner_id.email)
|
||||||
return ",".join(users)
|
return ",".join(users)
|
||||||
|
|
||||||
def access_users_ids(self, groups, record):
|
def access_users_ids(self, groups, record):
|
||||||
processed_users = set()
|
processed_users = set()
|
||||||
for group in groups:
|
for group in groups:
|
||||||
for user in group.users:
|
for user in group.users:
|
||||||
if user.id not in processed_users and \
|
if user.id not in processed_users and self.check_user_access(user_id=user.id, record=record,mode='read'):
|
||||||
self.check_record_access(user_id=user.id, record=record, mode='read'):
|
|
||||||
if self.hr_notifys:
|
if self.hr_notifys:
|
||||||
if hasattr(record, 'employee_id') and record.employee_id:
|
if hasattr(record, 'employee_id') and record.employee_id:
|
||||||
emp = record.employee_id.sudo()
|
if self.direct_manager_notify:
|
||||||
if self.direct_manager_notify and user.id == emp.parent_id.user_id.id:
|
if user.id == record.employee_id.sudo().parent_id.user_id.id:
|
||||||
processed_users.add(user.id)
|
processed_users.add(user.id)
|
||||||
elif self.department_manager_notify and user.id == emp.coach_id.user_id.id:
|
if self.department_manager_notify:
|
||||||
processed_users.add(user.id)
|
if user.id == record.employee_id.sudo().coach_id.user_id.id:
|
||||||
elif self.employee_notify and user.id == emp.user_id.id:
|
processed_users.add(user.id)
|
||||||
processed_users.add(user.id)
|
if self.employee_notify:
|
||||||
elif self.ceo_notify and user.id == emp.company_id.general_supervisor_id.user_id.id:
|
if user.id == record.employee_id.sudo().user_id.id:
|
||||||
processed_users.add(user.id)
|
processed_users.add(user.id)
|
||||||
elif self.hr_manager_notify and user.id == emp.company_id.hr_manager_id.user_id.id:
|
if self.ceo_notify:
|
||||||
processed_users.add(user.id)
|
if user.id == record.employee_id.sudo().company_id.general_supervisor_id.user_id.id:
|
||||||
elif self.services_manager_id and user.id == emp.company_id.services_manager_id.user_id.id:
|
processed_users.add(user.id)
|
||||||
processed_users.add(user.id)
|
if self.hr_manager_notify:
|
||||||
elif self.it_manager_id and user.id == emp.company_id.it_manager_id.user_id.id:
|
if user.id == record.employee_id.sudo().company_id.hr_manager_id.user_id.id:
|
||||||
processed_users.add(user.id)
|
processed_users.add(user.id)
|
||||||
elif self.admin_manager_id and user.id == emp.company_id.admin_manager_id.user_id.id:
|
if self.services_manager_id:
|
||||||
processed_users.add(user.id)
|
if user.id == record.employee_id.sudo().company_id.services_manager_id.user_id.id:
|
||||||
elif self.financial_manager_id and user.id == emp.company_id.financial_manager_id.user_id.id:
|
processed_users.add(user.id)
|
||||||
processed_users.add(user.id)
|
if self.it_manager_id:
|
||||||
elif self.cyber_security_id and user.id == emp.company_id.cyber_security_id.user_id.id:
|
if user.id == record.employee_id.sudo().company_id.it_manager_id.user_id.id:
|
||||||
processed_users.add(user.id)
|
processed_users.add(user.id)
|
||||||
|
if self.admin_manager_id:
|
||||||
|
if user.id == record.employee_id.sudo().company_id.admin_manager_id.user_id.id:
|
||||||
|
processed_users.add(user.id)
|
||||||
|
if self.financial_manager_id:
|
||||||
|
if user.id == record.employee_id.sudo().company_id.financial_manager_id.user_id.id:
|
||||||
|
processed_users.add(user.id)
|
||||||
|
if self.cyber_security_id:
|
||||||
|
if user.id == record.employee_id.sudo().company_id.cyber_security_id.user_id.id:
|
||||||
|
processed_users.add(user.id)
|
||||||
else:
|
else:
|
||||||
processed_users.add(user.id)
|
processed_users.add(user.id)
|
||||||
else:
|
else:
|
||||||
processed_users.add(user.id)
|
processed_users.add(user.id)
|
||||||
return list(processed_users)
|
return list(processed_users)
|
||||||
|
|
||||||
def get_notify_message(self, record):
|
def get_notify_message(self, record):
|
||||||
user_ids = self.access_users_ids(self.notify_to_groups_ids, record)
|
user_ids = self.access_users_ids(self.notify_to_groups_ids, record)
|
||||||
today = datetime.today()
|
today = datetime.today()
|
||||||
|
|
||||||
for user in user_ids:
|
for user in user_ids:
|
||||||
|
summary = (self.name or
|
||||||
|
(self.template_id.name if hasattr(self, 'template_id') and self.template_id else None) or
|
||||||
|
'Notification')
|
||||||
data = {
|
data = {
|
||||||
'res_id': record.id,
|
'res_id': record.id,
|
||||||
'res_model_id': self.env['ir.model'].search([('model', '=', record._name)]).id,
|
'res_model_id': self.env['ir.model'].search([('model', '=', record._name)]).id,
|
||||||
'user_id': user,
|
'user_id': user,
|
||||||
'summary': _(self.name or 'Notification'),
|
'summary': _(summary),
|
||||||
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
|
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
|
||||||
'date_deadline': today
|
'date_deadline': today
|
||||||
}
|
}
|
||||||
self.env['mail.activity'].create(data)
|
self.env['mail.activity'].create(data)
|
||||||
|
|
||||||
if self.hr_notifys:
|
if self.hr_notifys:
|
||||||
if not user_ids and self.notify_to_groups_ids:
|
if not user_ids and self.notify_to_groups_ids:
|
||||||
if hasattr(record, 'employee_id') and record.employee_id:
|
if hasattr(record, 'employee_id') and record.employee_id:
|
||||||
hr_manager_user = record.employee_id.sudo().company_id.hr_manager_id.user_id.id
|
hr_manager_user = record.employee_id.sudo().company_id.hr_manager_id.user_id.id
|
||||||
|
summary = (self.name or
|
||||||
|
(self.template_id.name if hasattr(self, 'template_id') and self.template_id else None) or
|
||||||
|
'Notification')
|
||||||
data = {
|
data = {
|
||||||
'res_id': record.id,
|
'res_id': record.id,
|
||||||
'res_model_id': self.env['ir.model'].search([('model', '=', record._name)]).id,
|
'res_model_id': self.env['ir.model'].search([('model', '=', record._name)]).id,
|
||||||
'user_id': hr_manager_user,
|
'user_id': hr_manager_user,
|
||||||
'summary': _(self.name or 'Notification'),
|
'summary': _(summary),
|
||||||
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
|
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
|
||||||
'date_deadline': today
|
'date_deadline': today
|
||||||
}
|
}
|
||||||
self.env['mail.activity'].create(data)
|
self.env['mail.activity'].create(data)
|
||||||
|
|
||||||
def get_mail_to(self, record):
|
def get_mail_to(self, record):
|
||||||
users = self.access_users(self.notify_to_groups_ids, record)
|
users = self.access_users(self.notify_to_groups_ids, record)
|
||||||
if self.hr_notifys:
|
if self.hr_notifys:
|
||||||
|
|
@ -158,7 +174,6 @@ class BaseAutomation(models.Model):
|
||||||
hr_manager_mail = record.employee_id.sudo().company_id.hr_manager_id.user_id.partner_id.email
|
hr_manager_mail = record.employee_id.sudo().company_id.hr_manager_id.user_id.partner_id.email
|
||||||
users = hr_manager_mail
|
users = hr_manager_mail
|
||||||
return users
|
return users
|
||||||
|
|
||||||
def get_mail_cc(self, record):
|
def get_mail_cc(self, record):
|
||||||
users = self.access_users(self.notify_cc_groups_ids, record)
|
users = self.access_users(self.notify_cc_groups_ids, record)
|
||||||
if self.hr_notifys:
|
if self.hr_notifys:
|
||||||
|
|
@ -167,59 +182,88 @@ class BaseAutomation(models.Model):
|
||||||
hr_mail = record.employee_id.sudo().company_id.hr_email
|
hr_mail = record.employee_id.sudo().company_id.hr_email
|
||||||
users = hr_mail
|
users = hr_mail
|
||||||
return users
|
return users
|
||||||
|
|
||||||
def _process(self, records, domain_post=None):
|
def _process(self, records, domain_post=None):
|
||||||
result = super()._process(records, domain_post)
|
result = super()._process(records, domain_post)
|
||||||
if self.send_notify:
|
if self.send_notify:
|
||||||
for record in records:
|
for record in records:
|
||||||
self.get_notify_message(record)
|
self.get_notify_message(record)
|
||||||
return result
|
return result
|
||||||
|
class ServerActions(models.Model):
|
||||||
|
_inherit = 'ir.actions.server'
|
||||||
|
@api.model
|
||||||
|
def _run_action_email(self, eval_context=None):
|
||||||
|
if self._context.get('__action_done'):
|
||||||
|
automations = self._context.get('__action_done')
|
||||||
|
automation = list(automations.keys())[0]
|
||||||
|
record = automations[automation]
|
||||||
|
action = automation.action_server_id
|
||||||
|
old_email_to = action.template_id.email_to if action.template_id else ''
|
||||||
|
old_email_cc = action.template_id.email_cc if action.template_id else ''
|
||||||
|
if action.template_id:
|
||||||
|
template_values = {
|
||||||
|
'email_to': automation.get_mail_to(record),
|
||||||
|
'email_cc': automation.get_mail_cc(record),
|
||||||
|
}
|
||||||
|
action.template_id.write(template_values)
|
||||||
|
cleaned_ctx = dict(self.env.context)
|
||||||
|
cleaned_ctx.pop('default_type', None)
|
||||||
|
cleaned_ctx.pop('default_parent_id', None)
|
||||||
|
action.template_id.with_context(cleaned_ctx).send_mail(record.id, force_send=True,
|
||||||
|
notif_layout="system_notification.mail_notification_odex",
|
||||||
|
raise_exception=False)
|
||||||
|
old_template_values = {
|
||||||
|
'email_to': old_email_to,
|
||||||
|
'email_cc': old_email_cc,
|
||||||
|
}
|
||||||
|
action.template_id.write(old_template_values)
|
||||||
|
if automation.send_notify:
|
||||||
|
automation.get_notify_message(record)
|
||||||
|
return False
|
||||||
|
return super()._run_action_email(eval_context=eval_context)
|
||||||
class MailActivity(models.Model):
|
class MailActivity(models.Model):
|
||||||
_inherit = 'mail.activity'
|
_inherit = 'mail.activity'
|
||||||
|
|
||||||
def action_notify(self):
|
def action_notify(self):
|
||||||
if not self:
|
if not self:
|
||||||
return
|
return
|
||||||
|
|
||||||
original_context = self.env.context
|
original_context = self.env.context
|
||||||
body_template = self.env.ref('mail.message_activity_assigned')
|
body_template = self.env.ref('mail.message_activity_assigned')
|
||||||
|
|
||||||
for activity in self:
|
for activity in self:
|
||||||
if activity.user_id.lang:
|
if activity.user_id.lang:
|
||||||
self = self.with_context(lang=activity.user_id.lang)
|
self = self.with_context(lang=activity.user_id.lang)
|
||||||
body_template = body_template.with_context(lang=activity.user_id.lang)
|
body_template = body_template.with_context(lang=activity.user_id.lang)
|
||||||
activity = activity.with_context(lang=activity.user_id.lang)
|
activity = activity.with_context(lang=activity.user_id.lang)
|
||||||
|
|
||||||
model_description = self.env['ir.model']._get(activity.res_model).display_name
|
model_description = self.env['ir.model']._get(activity.res_model).display_name
|
||||||
|
|
||||||
body = body_template._render(
|
body = body_template._render(
|
||||||
{
|
{
|
||||||
'activity': activity,
|
'activity': activity,
|
||||||
'model_description': model_description,
|
'model_description': model_description,
|
||||||
'access_link': self.env['mail.thread']._notify_get_action_link(
|
'access_link': self.env['mail.thread']._notify_get_action_link('view', model=activity.res_model,
|
||||||
'view',
|
res_id=activity.res_id),
|
||||||
model=activity.res_model,
|
|
||||||
res_id=activity.res_id
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
engine='ir.qweb',
|
engine='ir.qweb',
|
||||||
minimal_qcontext=True
|
minimal_qcontext=True
|
||||||
)
|
)
|
||||||
|
|
||||||
record = self.env[activity.res_model].browse(activity.res_id)
|
record = self.env[activity.res_model].browse(activity.res_id)
|
||||||
if activity.user_id:
|
if activity.user_id:
|
||||||
record.message_post(
|
record.message_post(
|
||||||
body=body,
|
body=body,
|
||||||
subject=_('%(activity_name)s: %(summary)s assigned to you',
|
subject=_('%(activity_name)s: %(summary)s assigned to you',
|
||||||
activity_name=activity.res_name,
|
activity_name=activity.res_name,
|
||||||
summary=activity.summary or activity.activity_type_id.name
|
summary=activity.summary or activity.activity_type_id.name),
|
||||||
),
|
|
||||||
partner_ids=activity.user_id.partner_id.ids,
|
partner_ids=activity.user_id.partner_id.ids,
|
||||||
email_layout_xmlid='system_notification.mail_notification_odex',
|
email_layout_xmlid='system_notification.mail_notification_odex',
|
||||||
message_type='notification'
|
message_type='notification'
|
||||||
)
|
)
|
||||||
|
|
||||||
body_template = body_template.with_context(original_context)
|
body_template = body_template.with_context(original_context)
|
||||||
self = self.with_context(original_context)
|
self = self.with_context(original_context)
|
||||||
|
class BaseGroupAutomation(models.Model):
|
||||||
|
_name = 'automation.group'
|
||||||
|
_rec_name = 'model_id'
|
||||||
|
model_id = fields.Many2one('ir.model', string="Model", ondelete='cascade', required=True)
|
||||||
|
atuomation_ids = fields.Many2many(comodel_name='base.automation', relation='automation_state_groups_rel',
|
||||||
|
string='Group States ')
|
||||||
|
def unlink(self):
|
||||||
|
for record in self.atuomation_ids:
|
||||||
|
record.unlink()
|
||||||
|
result = super().unlink()
|
||||||
|
return result
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
|
|
||||||
|
|
@ -1,63 +1,75 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<odoo>
|
<odoo>
|
||||||
<data>
|
<!-- Automation Form View -->
|
||||||
<!-- base.automation inherit form view -->
|
<record id="view_base_group_automation_form" model="ir.ui.view">
|
||||||
<record id="view_base_automation_form" model="ir.ui.view">
|
<field name="name">Automations</field>
|
||||||
<field name="name">base.automation.inherit.view.form</field>
|
<field name="model">automation.group</field>
|
||||||
<field name="model">base.automation</field>
|
<field name="arch" type="xml">
|
||||||
<field name="inherit_id" ref="base_automation.view_base_automation_form"/>
|
<form>
|
||||||
<field name="arch" type="xml">
|
<sheet>
|
||||||
<!-- إضافة الحقول بعد model_id -->
|
<group>
|
||||||
<xpath expr="//field[@name='model_id']" position="after">
|
<field name="model_id"/>
|
||||||
<field name="send_notify"/>
|
</group>
|
||||||
<field name="hr_notifys"/>
|
<notebook>
|
||||||
</xpath>
|
<page string="Automated Actions">
|
||||||
|
<field name="atuomation_ids" context="{'default_model_id': model_id}">
|
||||||
|
<list>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="model_id"/>
|
||||||
|
<field name="trigger"/>
|
||||||
|
<field name="active"/>
|
||||||
|
</list>
|
||||||
|
<form>
|
||||||
|
<sheet>
|
||||||
|
<group>
|
||||||
|
<field name="name"/>
|
||||||
|
<field name="model_id"/>
|
||||||
|
<field name="trigger"/>
|
||||||
|
<field name="active"/>
|
||||||
|
</group>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</page>
|
||||||
|
</notebook>
|
||||||
|
</sheet>
|
||||||
|
</form>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<!-- إضافة التبويبات في النوت بوك -->
|
<!-- Automation List View -->
|
||||||
<xpath expr="//notebook" position="inside">
|
<record id="view_base_group_automation_list" model="ir.ui.view">
|
||||||
<page string="System Notification" name="system_notification">
|
<field name="name">base.automation.list</field>
|
||||||
<group>
|
<field name="model">automation.group</field>
|
||||||
<group string="Notification Settings">
|
<field name="arch" type="xml">
|
||||||
<field name="send_notify"/>
|
<list string="Automation Groups">
|
||||||
<field name="hr_notifys"/>
|
<field name="model_id"/>
|
||||||
<field name="notify_to_groups_ids" widget="many2many_tags"/>
|
</list>
|
||||||
<field name="notify_cc_groups_ids" widget="many2many_tags"/>
|
</field>
|
||||||
<field name="notify_title"/>
|
</record>
|
||||||
<field name="notify_summary"/>
|
|
||||||
<field name="notify_note"/>
|
|
||||||
</group>
|
|
||||||
</group>
|
|
||||||
</page>
|
|
||||||
|
|
||||||
<page string="HR Notification Data" name="hr_notifications">
|
<!-- Automation Action -->
|
||||||
<group>
|
<record id="base_automation_act" model="ir.actions.act_window">
|
||||||
<group>
|
<field name="name">Automated Actions</field>
|
||||||
<field name="department_manager_notify"/>
|
<field name="res_model">automation.group</field>
|
||||||
<field name="direct_manager_notify"/>
|
<field name="view_mode">list,form</field>
|
||||||
<field name="employee_notify"/>
|
<field name="view_id" ref="view_base_group_automation_list"/>
|
||||||
<field name="ceo_notify"/>
|
<field name="help" type="html">
|
||||||
</group>
|
<p class="o_view_nocontent_create">
|
||||||
<group>
|
Click to setup a new automated automation.
|
||||||
<field name="services_manager_id"/>
|
</p>
|
||||||
<field name="hr_manager_notify"/>
|
<p>
|
||||||
<field name="hr_email_notify"/>
|
Use automated actions to automatically trigger actions for
|
||||||
<field name="financial_manager_id"/>
|
various screens. Example: a lead created by a specific user may
|
||||||
</group>
|
be automatically set to a specific sales channel, or an
|
||||||
<group>
|
opportunity which still has status pending after 14 days might
|
||||||
<field name="it_manager_id"/>
|
trigger an automatic reminder email.
|
||||||
<field name="cyber_security_id"/>
|
</p>
|
||||||
<field name="admin_manager_id"/>
|
</field>
|
||||||
</group>
|
</record>
|
||||||
</group>
|
|
||||||
</page>
|
|
||||||
</xpath>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<menuitem name="System Notification" id="system_notification.menu_root"/>
|
<menuitem id="menu_base_group_automation_form"
|
||||||
|
parent="base_automation.menu_base_automation_form"
|
||||||
<record id="base_automation.menu_base_automation_form" model="ir.ui.menu">
|
name="states notification"
|
||||||
<field name="name">System Notifications</field>
|
action="base_automation_act"/>
|
||||||
<field name="parent_id" ref="system_notification.menu_root"/>
|
</odoo>
|
||||||
</record>
|
|
||||||
</data>
|
|
||||||
</odoo>
|
|
||||||
|
|
@ -1,77 +1,60 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- Automation Form View -->
|
<data>
|
||||||
<record id="view_base_group_automation_form" model="ir.ui.view">
|
<record id="view_base_automation_form" model="ir.ui.view">
|
||||||
<field name="name">Automations</field>
|
<field name="name">base.automation.inherit.view.form</field>
|
||||||
<field name="model">automation.group</field>
|
<field name="model">base.automation</field>
|
||||||
<field name="arch" type="xml">
|
<field name="inherit_id" ref="base_automation.view_base_automation_form"/>
|
||||||
<form>
|
<field name="arch" type="xml">
|
||||||
<sheet>
|
|
||||||
<group>
|
|
||||||
<field name="model_id"/>
|
|
||||||
</group>
|
|
||||||
<notebook>
|
|
||||||
<page string="Automated Actions">
|
|
||||||
<field name="atuomation_ids" context="{'default_model_id': model_id}">
|
|
||||||
<list>
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="model_id"/>
|
|
||||||
<!-- <field name="state"/>-->
|
|
||||||
<field name="trigger"/>
|
|
||||||
<field name="active"/>
|
|
||||||
</list>
|
|
||||||
<form>
|
|
||||||
<sheet>
|
|
||||||
<group>
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="model_id"/>
|
|
||||||
<!-- <field name="state"/>-->
|
|
||||||
<field name="trigger"/>
|
|
||||||
<field name="active"/>
|
|
||||||
</group>
|
|
||||||
</sheet>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</page>
|
|
||||||
</notebook>
|
|
||||||
</sheet>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<!-- Automation List View -->
|
<xpath expr="//field[@name='model_id']" position="after">
|
||||||
<record id="view_base_group_automation_list" model="ir.ui.view">
|
<field name="send_notify"/>
|
||||||
<field name="name">base.automation.list</field>
|
<field name="hr_notifys"/>
|
||||||
<field name="model">automation.group</field>
|
</xpath>
|
||||||
<field name="arch" type="xml">
|
<xpath expr="//notebook" position="inside">
|
||||||
<list string="Automation Groups">
|
<page string="System Notification" name="system_notification">
|
||||||
<field name="model_id"/>
|
<group>
|
||||||
</list>
|
<group string="Notification Settings">
|
||||||
</field>
|
<field name="send_notify"/>
|
||||||
</record>
|
<field name="hr_notifys"/>
|
||||||
|
<field name="notify_to_groups_ids" widget="many2many_tags"/>
|
||||||
|
<field name="notify_cc_groups_ids" widget="many2many_tags"/>
|
||||||
|
<field name="notify_title"/>
|
||||||
|
<field name="notify_summary"/>
|
||||||
|
<field name="notify_note"/>
|
||||||
|
</group>
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
|
||||||
<!-- Automation Action -->
|
<page string="HR Notification Data" name="hr_notifications">
|
||||||
<record id="base_automation_act" model="ir.actions.act_window">
|
<group>
|
||||||
<field name="name">Automated Actions</field>
|
<group>
|
||||||
<field name="res_model">automation.group</field>
|
<field name="department_manager_notify"/>
|
||||||
<field name="view_mode">list,form</field>
|
<field name="direct_manager_notify"/>
|
||||||
<field name="view_id" ref="view_base_group_automation_list"/>
|
<field name="employee_notify"/>
|
||||||
<field name="help" type="html">
|
<field name="ceo_notify"/>
|
||||||
<p class="o_view_nocontent_create">
|
</group>
|
||||||
Click to setup a new automated automation.
|
<group>
|
||||||
</p>
|
<field name="services_manager_id"/>
|
||||||
<p>
|
<field name="hr_manager_notify"/>
|
||||||
Use automated actions to automatically trigger actions for
|
<field name="hr_email_notify"/>
|
||||||
various screens. Example: a lead created by a specific user may
|
<field name="financial_manager_id"/>
|
||||||
be automatically set to a specific sales channel, or an
|
</group>
|
||||||
opportunity which still has status pending after 14 days might
|
<group>
|
||||||
trigger an automatic reminder email.
|
<field name="it_manager_id"/>
|
||||||
</p>
|
<field name="cyber_security_id"/>
|
||||||
</field>
|
<field name="admin_manager_id"/>
|
||||||
</record>
|
</group>
|
||||||
|
</group>
|
||||||
|
</page>
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
<menuitem id="menu_base_group_automation_form"
|
<menuitem name="System Notification" id="system_notification.menu_root"/>
|
||||||
parent="base_automation.menu_base_automation_form"
|
|
||||||
name="states notification"
|
<record id="base_automation.menu_base_automation_form" model="ir.ui.menu">
|
||||||
action="base_automation_act"/>
|
<field name="name">System Notifications</field>
|
||||||
</odoo>
|
<field name="parent_id" ref="system_notification.menu_root"/>
|
||||||
|
</record>
|
||||||
|
</data>
|
||||||
|
</odoo>
|
||||||
Loading…
Reference in New Issue