Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
2 Ответы
19366 Представления

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.

Аватар
Отменить
Лучший ответ

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

Аватар
Отменить
Автор

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.

Автор

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)

Автор

Thanks Niyas and Ramsad, Its working fine now.

Лучший ответ
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.
Аватар
Отменить
Related Posts Ответы Просмотры Активность
2
июл. 25
465
0
дек. 24
1091
2
окт. 24
1187
1
авг. 24
2345
2
июл. 24
1585