commit
ee2a9359ef
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
'description': """
|
||||
""",
|
||||
|
||||
'category' : 'Odex25-base',
|
||||
|
||||
# Categories can be used to filter modules in modules listing
|
||||
|
|
@ -14,7 +13,7 @@
|
|||
# for the full list
|
||||
|
||||
# any module necessary for this one to work correctly
|
||||
'depends': ['base_automation'],
|
||||
'depends': ['base_automation','mail'],
|
||||
|
||||
# always loaded
|
||||
'data': [
|
||||
|
|
|
|||
|
|
@ -5,7 +5,15 @@ from odoo import models, fields, api
|
|||
|
||||
class BaseAutomation(models.Model):
|
||||
_inherit = 'base.automation'
|
||||
|
||||
# add new optine send notify
|
||||
send_notify = fields.Boolean(string='Send Notify')
|
||||
notify_title = fields.Char(
|
||||
string='Notification Title',related='model_id.name')
|
||||
notify_note = fields.Char(
|
||||
string='Notification Note')
|
||||
notify_summary = fields.Char(
|
||||
string='Notification Message')
|
||||
# end option
|
||||
notify_to_groups_ids = fields.Many2many(comodel_name='res.groups',
|
||||
relation='automation_notifications_to_groups_rel',
|
||||
string='TO Notify Groups')
|
||||
|
|
@ -29,6 +37,41 @@ class BaseAutomation(models.Model):
|
|||
if self.has_access(user_id=user.id, record=record, mode='read') and user.partner_id.email:
|
||||
users.append(user.partner_id.email)
|
||||
return ",".join(users)
|
||||
# todo start to add method return access users ids list
|
||||
def access_users_ids(self, groups, record):
|
||||
# partner_ids = set()
|
||||
processed_users = set()
|
||||
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'):
|
||||
# partner_ids.add(user.partner_id.id)
|
||||
processed_users.add(user.id)
|
||||
return list(processed_users)
|
||||
|
||||
# def access_partner_ids(self, groups, record):
|
||||
# partner_ids = []
|
||||
# for group in groups:
|
||||
# for user in group.users:
|
||||
# if self.has_access(user_id = user.id, record=record, mode='read'):
|
||||
# partner_ids.append(user.partner_id.id)
|
||||
# return partner_ids
|
||||
# todo end
|
||||
def get_notify_message(self,record):
|
||||
user_ids = self.access_users_ids(self.notify_to_groups_ids, record)
|
||||
for user in user_ids:
|
||||
record.activity_schedule('mail.mail_activity_todo', user_id=user,)
|
||||
|
||||
# notification_ids = [(0, 0, {'res_partner_id': p,'notification_type': 'inbox'})]
|
||||
# self.env['mail.message'].sudo().create({
|
||||
# 'message_type': 'notification',
|
||||
# 'body': self.notify_note,
|
||||
# 'subject':self.notify_summary,
|
||||
# 'model': record._name,
|
||||
# 'res_id': record.id,
|
||||
# 'partner_ids': partner_ids,
|
||||
# 'notification_ids': notification_ids,
|
||||
# })
|
||||
# end notify method
|
||||
|
||||
def get_mail_to(self, record):
|
||||
users = self.access_users(self.notify_to_groups_ids, record)
|
||||
|
|
@ -93,5 +136,8 @@ class ServerActions(models.Model):
|
|||
'email_cc': old_email_cc,
|
||||
}
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -8,11 +8,31 @@
|
|||
<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="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')],'required': [('state', '=', 'email')]}"/>
|
||||
</xpath>
|
||||
<!-- add notify fields -->
|
||||
<xpath expr="//notebook" position="inside">
|
||||
<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>
|
||||
<field name="notify_summary" attrs="{'required': [('send_notify', '=', True)]}"/>
|
||||
<field name="notify_note" attrs="{'required': [('send_notify', '=', True)]}"/>
|
||||
</group>
|
||||
</group>
|
||||
|
||||
</page>
|
||||
</xpath>
|
||||
<!-- end -->
|
||||
</field>
|
||||
</record>
|
||||
<menuitem name="System Notification" id="system_notification.menu_root"/>
|
||||
|
|
@ -22,4 +42,4 @@
|
|||
<field name="parent_id" ref="system_notification.menu_root"/>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
|
|
|||
Loading…
Reference in New Issue