fix System Notification new function HR

This commit is contained in:
Bakry 2025-02-17 17:10:30 +03:00
parent 9e93129065
commit a46db18fef
7 changed files with 459 additions and 20 deletions

View File

@ -20,6 +20,7 @@
'security/ir.model.access.csv',
'views/views.xml',
'views/group_state_notification.xml',
'data/mail_data.xml',
],
}

View File

@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="mail_notification_odex">
<table border="0" cellpadding="0" cellspacing="0" style="padding-top: 16px; background-color: #F1F1F1; font-family:Verdana, Arial,sans-serif; color: #454748; width: 100%; border-collapse:separate;"><tr><td align="center">
<table border="0" cellpadding="0" cellspacing="0" width="590" style="padding: 24px; background-color: white; color: #454748; border-collapse:separate;">
<tbody>
<!-- HEADER -->
<tr>
<td align="center" style="min-width: 590px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%" style="background-color: white; padding: 0; border-collapse:separate;">
<tr><td valign="middle">
</td><td valign="middle" align="right">
<img t-att-src="'/logo.png?company=%s' % (company.id or 0)" style="padding: 0px; margin: 0px; height: 48px;" t-att-alt="'%s' % company.name"/>
</td></tr>
<tr><td colspan="2" style="text-align:center;">
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin:4px 0px 32px 0px;"/>
</td></tr>
</table>
</td>
</tr>
<!-- CONTENT -->
<tr>
<td style="min-width: 590px;">
<t t-raw="message.body"/>
</td>
</tr>
<!-- FOOTER -->
<tr>
<td align="center" style="min-width: 590px; padding: 0 8px 0 8px; font-size:11px;">
<hr width="100%" style="background-color:rgb(204,204,204);border:medium none;clear:both;display:block;font-size:0px;min-height:1px;line-height:0; margin: 16px 0px 4px 0px;"/>
<b t-esc="company.name"/><br/>
<div style="color: #999999;">
<t t-esc="company.phone"/>
<t t-if="company.email"> |
<a t-att-href="'mailto:%s' % company.email" style="text-decoration:none; color: #999999;"><t t-esc="company.email"/></a>
</t>
<t t-if="company.website"> |
<a t-att-href="'%s' % company.website" style="text-decoration:none; color: #999999;">
<t t-esc="company.website"/>
</a>
</t>
</div>
</td>
</tr>
</tbody>
</table>
</td></tr>
<!-- POWERED BY -->
</table>
</template>
</data>
</odoo>

View File

@ -4,11 +4,11 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-08-11 07:39+0000\n"
"PO-Revision-Date: 2022-08-11 07:39+0000\n"
"Last-Translator: <>\n"
"POT-Creation-Date: 2024-12-05 11:54+0000\n"
"PO-Revision-Date: 2024-12-05 11:54+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
@ -115,3 +115,162 @@ msgstr "الحالات"
msgid "states notificatin"
msgstr "حالات الاشعار"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__notify_to_groups_ids
msgid "TO Notify Groups"
msgstr "إرسال للمجموعات"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__notify_cc_groups_ids
msgid "CC Notify Groups"
msgstr "نسخة للمجموعات"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__notify_note
msgid "Notification Note"
msgstr "ملاحظات الاشعار"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__send_notify
msgid "Send Notify"
msgstr "إشعار داخلي"
#. module: system_notification
#: model_terms:ir.ui.view,arch_db:system_notification.view_base_automation_form
msgid "Notification Data"
msgstr "بيانات الإشعار"
#. module: system_notification
#: model_terms:ir.ui.view,arch_db:system_notification.view_base_automation_form
msgid "HR Notification Data"
msgstr "بيانات إشعارات الموارد البشرية"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__send_notify
msgid "Send Notifications Within The System"
msgstr "إرسال إشعارات داخل النظام"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__notify_title
msgid "Notification Title"
msgstr "عنوان الإشعار"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__notify_summary
msgid "Notification Message"
msgstr "رسالة الإشعار"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__hr_notifys
msgid "HR Notifys"
msgstr "إشعار الموارد البشرية"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__services_manager_id
msgid "Services Manager"
msgstr "الخدمات المشتركة"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__ceo_notify
msgid "CEO Manager"
msgstr "الرئيس التنفيذي"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__hr_manager_notify
msgid "HR Manager"
msgstr "مدير الموارد البشرية"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__hr_email_notify
msgid "HR E-Mail"
msgstr "ايميل الموارد البشرية"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__department_manager_notify
msgid "Department Manager"
msgstr "مدير الإدارة"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__direct_manager_notify
msgid "Direct Manager"
msgstr "المدير المباشر"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__employee_notify
msgid "Employee Notify"
msgstr "إشعار الموظف"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__it_manager_id
msgid "IT Manager"
msgstr "مدير التقــنية"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__cyber_security_id
msgid "Cyber Security"
msgstr "الآمن السيبراني"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__admin_manager_id
msgid "Admin Affairs Manager"
msgstr "مدير الشئون الإدارية"
#. module: system_notification
#: model:ir.model.fields,field_description:system_notification.field_base_automation__financial_manager_id
msgid "Financial Manager"
msgstr "مدير المــالية"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__hr_notifys
msgid "Send Notifications HR Moduls Depend on (Employee Id) only"
msgstr "إرسال إشعار بخصوص منظومات الموارد البشرية إعتماداً على (إسم الموظف) فقط"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__direct_manager_notify
msgid "Send Notification To The Employee's Direct Manager Only"
msgstr "إرسال إشعار للمدير المباشر للموظف فقط حسب سجل الموظف"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__department_manager_notify
msgid "Send Notification To The Department Manager For The Employee Only"
msgstr "إرسال إشعار لمدير ادارة للموظف فقط حسب سجل الموظف"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__employee_notify
msgid "Send Notification To The Employee Only"
msgstr "إرسال إشعار للموظف فقط حسب سجل الموظف"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__ceo_notify
msgid "Send Notification To The CEO Manager Only"
msgstr "إرسال إشعار للرئيس التنفيذي فقط"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__hr_manager_notify
msgid "Send Notification To The HR Manager Only"
msgstr "إرسال إشعار لمدير الموارد البشرية فقط"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__hr_email_notify
msgid "Send Notification To The HR E-Mail Only"
msgstr "إرسال إشعار إيميل الموراد البشرية فقط"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__services_manager_id
msgid "Send Notification To The Services Manager Only"
msgstr "إرسال إشعار لمدير الخدمات المشتركة فقط"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__it_manager_id
msgid "Send Notification To The IT Manager Only"
msgstr "إرسال إشعار لمدير التقنية فقط"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__admin_manager_id
msgid "Send Notification To The Admin Affairs Manager Only"
msgstr "إرسال إشعار لمدير الشئون الإدارية فقط"
#. module: system_notification
#: model:ir.model.fields,help:system_notification.field_base_automation__financial_manager_id
msgid "Send Notification To The Financial Manager Only"
msgstr "إرسال إشعار لمدير المالية فقط"

View File

@ -1,12 +1,13 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api
from odoo import models, fields, api, _
from datetime import datetime
class BaseAutomation(models.Model):
_inherit = 'base.automation'
# add new optine send notify
send_notify = fields.Boolean(string='Send Notify')
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_note = fields.Char(
@ -22,6 +23,38 @@ class BaseAutomation(models.Model):
relation='automation_notifications_cc_groups_rel',
string='CC Notify Groups')
""" TO HR Modules Notification Depend on (Employee Id) only"""
hr_notifys = fields.Boolean(string='HR Notifys',help="Send Notifications HR Moduls Depend on (Employee Id) only")
direct_manager_notify = fields.Boolean(string='Direct Manager Notify',
help="Send Notification To The Employee's Direct Manager Only")
department_manager_notify = fields.Boolean(string='Department Manager Notify',
help="Send Notification To The Department Manager For The Employee Only")
employee_notify = fields.Boolean(string='Employee Notify',
help="Send Notification To The Employee Only")
ceo_notify = fields.Boolean(string='CEO Manager',
help="Send Notification To The CEO Manager Only")
hr_manager_notify = fields.Boolean(string='HR Manager',
help="Send Notification To The HR Manager Only")
hr_email_notify = fields.Boolean(string='HR E-Mail',
help="Send Notification To The HR E-Mail Only")
services_manager_id = fields.Boolean(string='Services Manager',
help="Send Notification To The Services Manager Only")
it_manager_id = fields.Boolean(string='IT Manager',
help="Send Notification To The IT Manager Only")
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 has_access(self, user_id, record, mode='read'):
try:
record.with_user(user_id).check_access_rule(mode)
@ -34,7 +67,43 @@ class BaseAutomation(models.Model):
users = []
for group in groups:
for user in group.users:
if self.has_access(user_id=user.id, record=record, mode='read') and user.partner_id.email:
if user.partner_id.email not in users and self.has_access(user_id=user.id, record=record, mode='read') and user.partner_id.email:
if self.hr_notifys:
""" TO HR Modules Notification Depend on (Employee Id) only"""
hr_mail = record.employee_id.sudo().company_id.hr_email
if self.direct_manager_notify :
if user.id == record.employee_id.sudo().parent_id.user_id.id:
users.append(user.partner_id.email)
if self.department_manager_notify:
if user.id == record.employee_id.sudo().coach_id.user_id.id:
users.append(user.partner_id.email)
if self.employee_notify:
if user.id == record.employee_id.sudo().user_id.id:
users.append(user.partner_id.email)
if self.ceo_notify:
if user.id == record.employee_id.sudo().company_id.general_supervisor_id.user_id.id:
users.append(user.partner_id.email)
if self.hr_manager_notify:
if user.id == record.employee_id.sudo().company_id.hr_manager_id.user_id.id:
users.append(user.partner_id.email)
if self.services_manager_id:
if user.id == record.employee_id.sudo().company_id.services_manager_id.user_id.id:
users.append(user.partner_id.email)
if self.it_manager_id:
if user.id == record.employee_id.sudo().company_id.it_manager_id.user_id.id:
users.append(user.partner_id.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:
users.append(user.partner_id.email)
return ",".join(users)
# todo start to add method return access users ids list
@ -44,7 +113,40 @@ class BaseAutomation(models.Model):
for group in groups:
for user in group.users:
if user.id not in processed_users and self.has_access(user_id=user.id, record=record, mode='read'):
if self.hr_notifys:
""" TO HR Modules Notification Depend on (Employee Id) only"""
if self.direct_manager_notify :
if user.id == record.employee_id.sudo().parent_id.user_id.id:
processed_users.add(user.id)
if self.department_manager_notify:
if user.id == record.employee_id.sudo().coach_id.user_id.id:
processed_users.add(user.id)
if self.employee_notify:
if user.id == record.employee_id.sudo().user_id.id:
processed_users.add(user.id)
if self.ceo_notify:
if user.id == record.employee_id.sudo().company_id.general_supervisor_id.user_id.id:
processed_users.add(user.id)
if self.hr_manager_notify:
if user.id == record.employee_id.sudo().company_id.hr_manager_id.user_id.id:
processed_users.add(user.id)
if self.services_manager_id:
if user.id == record.employee_id.sudo().company_id.services_manager_id.user_id.id:
processed_users.add(user.id)
if self.it_manager_id:
if user.id == record.employee_id.sudo().company_id.it_manager_id.user_id.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)
# partner_ids.add(user.partner_id.id)
else:
processed_users.add(user.id)
return list(processed_users)
@ -58,8 +160,34 @@ class BaseAutomation(models.Model):
# todo end
def get_notify_message(self,record):
user_ids = self.access_users_ids(self.notify_to_groups_ids, record)
today = datetime.today()
for user in user_ids:
record.activity_schedule('mail.mail_activity_todo', user_id=user,)
#record.activity_schedule('mail.mail_activity_todo', user_id=user,)
data = {
'res_id': record.id,
'res_model_id': self.env['ir.model'].search([('model', '=', record._name)]).id,
'user_id': user,
'summary': _(self.template_id.name),
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
'date_deadline': today
}
self.env['mail.activity'].create(data)
""" TO HR Modules Notification Depend on (Employee Id) only,
if not email Send TO HR Manager Mail"""
if self.hr_notifys:
if not user_ids and self.notify_to_groups_ids:
hr_manager_user = record.employee_id.sudo().company_id.hr_manager_id.user_id.id
#record.activity_schedule('mail.mail_activity_todo', user_id=hr_manager_user,)
data = {
'res_id': record.id,
'res_model_id': self.env['ir.model'].search([('model', '=', record._name)]).id,
'user_id': hr_manager_user,
'summary': _(self.template_id.name),
'activity_type_id': self.env.ref('mail.mail_activity_data_todo').id,
'date_deadline': today
}
self.env['mail.activity'].create(data)
# notification_ids = [(0, 0, {'res_partner_id': p,'notification_type': 'inbox'})]
# self.env['mail.message'].sudo().create({
@ -71,14 +199,26 @@ class BaseAutomation(models.Model):
# 'partner_ids': partner_ids,
# 'notification_ids': notification_ids,
# })
# end notify method
#end notify method
def get_mail_to(self, record):
users = self.access_users(self.notify_to_groups_ids, record)
if self.hr_notifys:
""" TO HR Modules Notification Depend on (Employee Id) only,
if not email Send TO HR Manager Mail"""
if not users and self.notify_to_groups_ids:
hr_manager_mail = record.employee_id.sudo().company_id.hr_manager_id.user_id.partner_id.email
users = hr_manager_mail
return users
def get_mail_cc(self, record):
users = self.access_users(self.notify_cc_groups_ids, record)
if self.hr_notifys:
""" TO HR Modules Notification Depend on (Employee Id) only,
If not Email CC Send to HR Mail"""
if not users and self.notify_cc_groups_ids:
hr_mail = record.employee_id.sudo().company_id.hr_email
users = hr_mail
return users
@ -129,7 +269,7 @@ class ServerActions(models.Model):
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="mail.mail_notification_light",
notif_layout="system_notification.mail_notification_odex",
raise_exception=False)
old_template_values = {
'email_to': old_email_to,
@ -137,7 +277,47 @@ class ServerActions(models.Model):
}
action.template_id.write(old_template_values)
if automation.send_notify:
print('true send....')
automation.get_notify_message(record)
return False
return super(ServerActions, self)._run_action_email(eval_context=eval_context)
class MailActivity(models.Model):
_inherit = 'mail.activity'
# copy function form odoo same name send other template (email_layout_xmlid)
def action_notify(self):
if not self:
return
original_context = self.env.context
body_template = self.env.ref('mail.message_activity_assigned')
for activity in self:
if activity.user_id.lang:
# Send the notification in the assigned user's language
self = self.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)
model_description = self.env['ir.model']._get(activity.res_model).display_name
body = body_template._render(
dict(
activity=activity,
model_description=model_description,
access_link=self.env['mail.thread']._notify_get_action_link('view', model=activity.res_model, res_id=activity.res_id),
),
engine='ir.qweb',
minimal_qcontext=True
)
record = self.env[activity.res_model].browse(activity.res_id)
if activity.user_id:
record.message_notify(
partner_ids=activity.user_id.partner_id.ids,
body=body,
subject=_('%(activity_name)s: %(summary)s assigned to you',
activity_name=activity.res_name,
summary=activity.summary or activity.activity_type_id.name),
record_name=activity.res_name,
model_description=model_description,
email_layout_xmlid='system_notification.mail_notification_odex',# change
#email_layout_xmlid='mail.mail_notification_light',
)
body_template = body_template.with_context(original_context)
self = self.with_context(original_context)

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -0,0 +1,22 @@
@media (min-width: 768px){
.rtl .navbar-right{
float: left !important;
}
.rtl .navbar-right .dropdown .dropdown-menu{
right: auto !important;
left: 0 !important;
}
.rtl .navbar-left{
float: right !important;
}
.rtl .navbar-left .dropdown .dropdown-menu{
left: auto !important;
right: 0 !important;
}
.navbar-nav.navbar-right:last-child{
margin-left: auto;
}
.rtl .pull-left{
float: right !important;
}
}

View File

@ -6,22 +6,42 @@
<field name="model">base.automation</field>
<field name="inherit_id" ref="base_automation.view_base_automation_form"/>
<field name="arch" type="xml">
<!-- Add your xpath here -->
<xpath expr="//field[@name='template_id']" position="after">
<!-- add notify option -->
<field name="send_notify"/>
<!-- end -->
<field name="hr_notifys"/>
<field name="notify_to_groups_ids" widget="many2many_tags"
attrs="{'invisible': [('state', '!=', 'email')],'required': [('state', '=', 'email')]}"/>
<field name="notify_cc_groups_ids" widget="many2many_tags"
attrs="{'invisible': [('state', '!=', 'email')]}"/>
</xpath>
<!-- add notify fields -->
<xpath expr="//notebook" position="inside">
<page string="HR Notification Data" attrs="{'invisible': [('hr_notifys', '!=', True)]}">
<group>
<group>
<field name="department_manager_notify" />
<field name="direct_manager_notify" />
<field name="employee_notify" />
</group>
<group>
<field name="ceo_notify"/>
<field name="services_manager_id" />
<field name="hr_manager_notify"/>
<field name="hr_email_notify"/>
</group>
<group>
<field name="financial_manager_id"/>
<field name="it_manager_id"/>
<field name="cyber_security_id"/>
<field name="admin_manager_id"/>
</group>
</group>
</page>
<page string="Notification Data" attrs="{'invisible': [('send_notify', '!=', True)]}">
<group>
<group>
<!-- <field name="notify_to_users" attrs="{'required': [('state', 'in', ['code'])]}" widget="many2many_tags"/>-->
<field name="notify_title" attrs="{'required': [('send_notify', '=', True)]}"/>
</group>
<group>
@ -32,7 +52,6 @@
</page>
</xpath>
<!-- end -->
</field>
</record>
<menuitem name="System Notification" id="system_notification.menu_root"/>