Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2598 Lượt xem

I want to notify all Maintenance Team members when a new request is created inside that particular team.

At the moment I have this functionality handled by an automated action like this:
https://i.imgur.com/ZbDstba.png

Python code:

body_html = """
...
""" + record.name + """
...
"""

num_of_members = len(record.maintenance_team_id.member_ids)

if num_of_members:
members_emails = []

for i in range(num_of_members):
members_emails.append(record.maintenance_team_id.member_ids[i].email)

email_to = ",".join(members_emails)

mail_pool = env['mail.mail']
values={}
values.update({'subject': 'New maintenance request - ' + record.company_id.name})
values.update({'email_to': email_to})
values.update({'body_html': body_html})
msg_id = mail_pool.create(values)

if msg_id:
mail_pool.send([msg_id])

But now I would like to convert this solution to a custom module. What is the correct way to do this? 

Should I inherit `maintenance.request`, override the create method and send my email somehow (how exactly?) with my hardcoded email body? 

class MaintenanceRequest(models.Model):
_inherit = 'maintenance.request'

@api.model
def create(self, vals):
req = super(MaintenanceRequest, self).create(vals)

body_html = """
...
""" + req.name + """
...
"""
# ...
if msg_id:
mail_pool.send([msg_id])

return req

Or there is a way to hook myself to a premade function for sending notification and just tell it to run also for the team members?  I don't want to add all of them as followers (because they would get spammed with unnecessary updates about the request) - only to notify them about the new request and then they can follow it if they needed to.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
6415
1
thg 6 22
8390
1
thg 9 21
3263
0
thg 8 21
95
0
thg 7 21
172