Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3950 Visualizzazioni

Hello, so I've been trying to create an automated actions wherein i will receive a message if there is a new lead available. I'm still new to Odoo so its really hard for me to understand the concept. I don't know what should I write in python code because i don't know what should I call.



Is there any possible way I can send a message to my channel?

Avatar
Abbandona
Risposta migliore

Below is the python code which you can use in order to post message on a channel whenever lead is created



1. First you would need to have the database ID of the channel you want to post message to. You can get it by going to Settings > Technical > Email > Channels, search for the channel name, open it's form view and you can get the ID from the url as #id=22 in this case,

2. Update your automated action with the above code. You can customize the message accordingly. Currently it posts message with the lead name.


Regards,

Karan BK

Avatar
Abbandona
Autore

Thank you, can I ask you where did you get env['mail.channel'].browse(22)?

I'm still newbie and learning it, can you recommend any youtube/tutorial to watch? or docs?

Autore

Hello, I get this error

This is my url

https://motorcycle5.odoo.com/web#id=3&menu_id=77&cids=1&action=115&model=discuss.channel&view_type=form

'# Available variables:\n# - env: environment on which the action is triggered\n# - model: model of the record on which the action is triggered; is a void recordset\n# - record: record on which the action is triggered; may be void\n# - records: recordset of all records on which the action is triggered in multi-mode; may be void\n# - time, datetime, dateutil, timezone: useful Python libraries\n# - float_compare: utility function to compare floats based on specific precision\n# - log: log(message, level=\'info\'): logging function to record debug information in ir.logging table\n# - _logger: _logger.info(message): logger to emit messages in server logs\n# - UserError: exception class for raising user-facing warning messages\n# - Command: x2many commands namespace\n# To return an action, assign: action = {...}\n\nchannel_to_message = env["mail.channel"].browse(3)\n\nfor lead in records:\n message = "Lead %s is created" % lead.name\n channel_to_message.message_post(body= message, message_type="comment", subtype_xmlid="mail.mt_comment")'

Seems like model name is different in the odoo version you're using. So,

instead of using
channel_to_message = env["mail.channel"].browse(3)

replace that line with
channel_to_message = env["discuss.channel"].browse(3)

This change should work.

Autore

Thank you Karan, it works, can I ask final question? Where can I learn these kind of things where you can manipulate the data like the python code you put? Where does env came from?

You can search for online tutorials for particular topics. However there is not a single tutorial to follow. Also, you can learn things from Odoo's developer documentation itself.

https://www.odoo.com/documentation/16.0/developer.html

Post correlati Risposte Visualizzazioni Attività
0
set 24
1382
0
mag 24
26
1
apr 24
4786
0
mar 24
1692
0
mar 24
1713