Skip to Content
Menu
This question has been flagged
2 Replies
4726 Views

Hello All

i have create an action in server action to open whatsapp API and send a message with share link here is my code:

if not record.partner_id.mobile:
raise UserError('No mobile number found for the selected partner.')
else:
# create message
message = "Hello %s,Your quotation %s amounting in %s %s is ready for review. Here's the link to view it: https://erp.gyc.com/mail/view?model=sale.order&res_id=%s&access_token=%s Regards," % (record.partner_id.name, record.name, record.amount_total, record.currency_id.name, record.id, record.access_token)

# create action
action = {
'name': "WhatsApp",
'type': 'ir.actions.act_url',
'url': "https://api.whatsapp.com/send?phone=%s&text=%s" % (record.partner_id.mobile, message),
'target': 'new',
}

everything is working but in the share link in two places we have "&" and the link will trime from & and result is like bellow:

Hello Kamranlpr,Your quotation S02317 amounting in 1050.0 is ready for review. Here's the link to view it: https://erp.gyc.com/mail/view?model=sale.order

so ID and token will trime.

i was wondering if anyone can help me to solve the problem.

Avatar
Discard
Best Answer
Hello, I'm trying to create that action in Odoo and I can't get it to work. Would you send me the complete code?


Avatar
Discard
Author

Hi this is the full code for sale order
if not record.partner_id.mobile:
raise UserError('No mobile number found for the selected partner.')
else:
# create link
target_url = "https://erp.gyeongcc.com" + record.get_portal_url()
link_tracker = env['link.tracker'].search([('url', '=', target_url)], limit=1)
if not link_tracker:
link_tracker = env['link.tracker'].create({
'title': record.name,
'url': target_url,
})

if record.state == 'sale':
# create message for WhatsApp (specific to sales order)
message_whatsapp = "Hello %s%%0AYour order *%s* amounting in *%s* *%s* is has been confirmed.%%0AThank you for your trust!%%0Alink to view: %s%%0ADo not hesitate to contact us if you have any questions." % (record.partner_id.name, record.name, record.amount_total, record.currency_id.name, link_tracker.short_url)

# create message for chatter (specific to sales order)
message_chatter = "Hello %s<br> Your order <b>%s</b> amounting in <b>%s %s</b> has been confirmed.<br>Thank you for your trust!<br>link to view: %s<br>Do not hesitate to contact us if you have any questions." % (record.partner_id.name, record.name, record.amount_total, record.currency_id.name, link_tracker.short_url)
else:
# create message for WhatsApp (specific to quotation)
message_whatsapp = "Hello %s%%0AYour quotation *%s* amounting in *%s* *%s* is ready for review.%%0AHere's the link to view it: %s%%0ADo not hesitate to contact us if you have any questions." % (record.partner_id.name, record.name, record.amount_total, record.currency_id.name, link_tracker.short_url)

# create message for chatter (specific to quotation)
message_chatter = "Hello %s<br> Your quotation <b>%s</b> amounting in <b>%s %s</b> is ready for review.<br> Here's the link to view it: %s<br>Do not hesitate to contact us if you have any questions." % (record.partner_id.name, record.name, record.amount_total, record.currency_id.name, link_tracker.short_url)

# create action for WhatsApp
action = {
'name': "WhatsApp",
'type': 'ir.actions.act_url',
'url': "https://api.whatsapp.com/send?phone=%s&text=%s" % (record.partner_id.mobile, message_whatsapp),
'target': 'new',
}

# create message for chatter
body = "<div style='background-color:#EAF4E8; padding: 10px;'><b>WhatsApp message sent:</b><br/>" + message_chatter + "</div>"
record.message_post(body=body)

Thank you very much, I have a problem with the link created. This link returns me:

http://ariano.com.ar/r/p1Z

Could it be that I'm missing the record.get_portal_url() action somewhere else?

As requested, the URL parameter of my site was wrong.
Goes perfectly!

Thank you so much!

Best Answer

Hello Kamran Lalehparvar,

You can parse the link in URL form with python library "urllib" to solve this issue.
Update your message as below

Please find code in comments. 

Hope it will be helpful to you.

Thanks & Regards,
Email:  odoo@aktivsoftware.com

Skype: kalpeshmaheshwari 

Avatar
Discard

Please find code here :-

# Header
import urllib.parse

# create message
url = "https://erp.gyc.com/mail/view?" + urllib.parse.quote("model=sale.order&res_id=%s&access_token=%s" %(record.id, record.access_token))

message = "Hello %s,
Your quotation %s amounting in %s %s is ready for review.
Here's the link to view it: %s
Regards," % (record.partner_id.name, record.name, record.amount_total, record.currency_id.name, url)

Related Posts Replies Views Activity
0
Apr 24
431
1
Nov 23
1864
1
Apr 25
2186
1
Apr 25
2916
1
Apr 25
632