Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
19339 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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.

Autor

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)

Autor

Thanks Niyas and Ramsad, Its working fine now.

Najlepsza odpowiedź
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.
Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lip 25
427
0
gru 24
1070
2
paź 24
1161
1
sie 24
2315
2
lip 24
1557