from odoo import api, fields, models
class EmailDemo(models.Model):
_name = 'practice.email.demo'
_inherit = ['mail.thread']
_description = "Email Demo"
res_partner_1 = fields.Boolean(string="Partner 1")
res_partner_2 = fields.Boolean(string="Partner 2")
res_partner_3 = fields.Boolean(string="Partner 3")
res_partner_4 = fields.Boolean(string="Partner 4")
@property
def receivers_selection_map(self):
# These partners are already in the system from demo data,
# You should check they exists in your system,
# Or you can replace them by others
return {'res_partner_1': self.env.ref('base.res_partner_1'),
'res_partner_2': self.env.ref('base.res_partner_2'),
'res_partner_3': self.env.ref('base.res_partner_3'),
'res_partner_4': self.env.ref('practice.practice_partner_1')}
def action_send_mail(self):
selected_partners = [p.id for k, p in self.receivers_selection_map.items() if self[k]]
self.message_post(body='Hello, From the email demo.
Email Demo body',
subject='email demo subject', partner_ids=selected_partners)
# To display the fields by partner names in the form
@api.model
def fields_get(self, allfields=None, attributes=None):
result = super().fields_get(allfields=allfields, attributes=attributes)
for k in self.receivers_selection_map:
result[k]['string'] = self.receivers_selection_map[k].display_name
return result
You can make your model inherit from 'mail.thread' and use its message_post method to send your emails to different partners. Those selectable names in your screen shot should be partners, so you can pass their ids to the message_post.
To call the message_post you need to have an action method in your model that connect to the form button by their names.
And make sure that your partners are receiving their notification by email.
I have been trying to understand odoo email workflow, and when encountered your question I use it as an exercise, you can check what I explained above here:
https://github.com/m-azzain/mz-addons/blob/master/practice/models/email_demo.py
https://github.com/m-azzain/mz-addons/blob/master/practice/views/email_demo_views.xml
I can't post an answer, do you have any idea why?
But I'm supposed to send an email outside of odoo, that is, odoo sends an email when I press the "Avançar" button, and that email it will be sent to the recipient's mail box as if it were a normal email, what you sent can do this?
I cant even convert your comment to answer, i don't know what i do wrong....
Yes It can do.
It will send an email to the email address of the partners; each partner in your odoo should have an email address. but you should have an outgoing email server that handle the process from odoo to the outside.
To configure an outgoing email server, there are a lot of ways. I've tried only one which I will show you below, but I think this isn't the perfect way to do it. when you figure better ways I hope you share it here.
First you need to have an outlook email, if you don't you can create one at outlook.com
Second change the setting in your aoutlook account to 'Let Devices and Apps Use POP'. You will find the option in Settings>Mail>Sync email
then update your account on odoo by setting this outlook email as your email; so that you will use it to send emails to the others
And Here is (on odoo) how I set the outgoing email server using outlook email
To configure an outgoing email server go to Settings>General Settings>Custom Email Servers>Outgoing Email Servers
create new and fill the form as:
Authenticate with: Username
Connection Encryption: TLS (STARTTLS)
SMTP Server: smtp.office365.com
SMTP Port: 587
Username: <Your outlook email>
Password: <Your outlook email password>
leave the rest as it's
Tried do to what you send me in github and keep giving me this error - > "TypeError: fields_get() takes 1 positional argument but 2 were give"
I think you missed the ** when you tried to call the super method
def fields_get(self, **kwargs):
result = super().fields_get(**kwargs)
by the way it allowed me to post an answer
It looks like, it prefer code more than text :)
If have find it convenient you can email me at m.alzain248@gmail.com
If you find it convenient you can email me at m.alzain248@gmail.com
hello, I am working into something and just stumbled on the same error as the one you mentioned, it is possible we are working into different versions of odoo. so I did minor change to the code, and also don't hesitate to post whatever error you may get, I already tested the code.