Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
3931 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

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?

Penulis

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.

Penulis

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 Terkait Replies Tampilan Aktivitas
0
Sep 24
1378
0
Mei 24
26
1
Apr 24
4762
0
Mar 24
1682
0
Mar 24
1710