Skip to Content
Menu
This question has been flagged
2 Replies
19501 Rodiniai

Hi,

Suppose I have created a button on the header on customer invoice.  If I click that button I want to send an email to that customer which contains a link to that customer invoice. 

Let say my button name is send_email

def send_email(self):
subject = 'Commercial Invoice'
recipients = self.customer.email
message_body = "Here I want to send the link"
template_obj = self.env['mail.mail']
template_data = {
'subject': subject,
'body_html': message_body,
'email_to': recipients
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)
template_id.send() 

Please suggest any solution to send the link of that document which is currently open in an email.

Portretas
Atmesti
Best Answer

Hi,

if you are looking to get the link to the current record, you can generate using the below code,


base_url = request.env['ir.config_parameter'].get_param('web.base.url')
base_url += '/web#id=%d&view_type=form&model=%s' % (self.id, self._name)


Using this code you can update your code,

def send_email(self):
subject = 'Commercial Invoice'
recipients = self.customer.email


base_url = request.env['ir.config_parameter'].get_param('web.base.url')
base_url += '/web#id=%d&view_type=form&model=%s' % (self.id, self._name)


message_body =
base_url
template_obj = self.env['mail.mail']
template_data = {
'subject': subject,
'body_html': message_body,
'email_to': recipients
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)
template_id.send()



The end user who access the email should have backend access to Odoo, such a way that he can see the view.

Else it will be nice to send the portal link.

base_url = request.env['ir.config_parameter'].get_param('web.base.url')
base_url += '/my/invoices/%s' % self.id

Thanks

Portretas
Atmesti
Autorius

hi niyas,

Thanx for the replay but it is throwing following error:

RuntimeError: Working outside of request context.

This typically means that you attempted to use functionality that

needed an active HTTP request. Consult the documentation on testing

for information about how to avoid this problem.

Autorius

Any update Niyas

from odoo.http import request

import request from odoo.http. it is working. make sure to set DB filter . or specify the database name in url section like

web/login?db=databasename#id=%d&view_type=form&model=%s' % (self.id, self._name)

Autorius

Thanks Niyas and Ramsad, Its working fine now.

Best Answer
Hi Mian,

Please find the sample code below

def signup_get_auth_param(self):

""" Get a signup token related to the partner if signup is enabled.

If the partner already has a user, get the login parameter.

"""

res = defaultdict(dict)


allow_signup = self.env['ir.config_parameter'].sudo().get_param('auth_signup.allow_uninvited', 'False').lower() == 'true'

for partner in self:

if allow_signup and not partner.user_ids:

partner.signup_prepare()

res[partner.id]['auth_signup_token'] = partner.signup_token

elif partner.user_ids:

res[partner.id]['auth_login'] = partner.user_ids[0].login

return res.

In addons/auth_signup/models/res_partner.py have all functions. please have a look.
Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
2
liep. 25
568
0
gruod. 24
1174
2
spal. 24
1297
1
rugp. 24
2449
2
liep. 24
1677