Skip to Content
Menu
This question has been flagged
3 Replies
3397 Views

Hi Everyone, I need help to understand and help to create Automation rules. 

How to create automation rule when User create an opportunity or quotation, create message in the Discuss Channel?

Avatar
Discard
Author

Could you create me little video or screenshot pls? I am not technical.

Author

Thank you Jainesh. I have this error. Also sent you automation page screenshot

https://drive.google.com/file/d/1z9kxuMrqkA7_VIgs-5_BnJtq6wia5I6y/view?usp=sharing

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/16E/odoo/tools/safe_eval.py", line 339, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "ir.actions.server(1215,)", line 14, in <module>
File "/home/odoo/16E/odoo/models.py", line 1536, in search
res = self._search(domain, offset=offset, limit=limit, order=order, count=count)
File "/home/odoo/16E/odoo/models.py", line 4628, in _search
query = self._where_calc(domain)
File "/home/odoo/16E/odoo/models.py", line 4396, in _where_calc
return expression.expression(domain, self).query
File "/home/odoo/16E/odoo/osv/expression.py", line 447, in __init__
self.parse()
File "/home/odoo/16E/odoo/osv/expression.py", line 672, in parse
raise ValueError("Invalid field %s.%s in leaf %s" % (model._name, path[0], str(leaf)))
ValueError: Invalid field mail.channel.Sales in leaf ('Sales', '=', 'general')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/odoo/16E/odoo/http.py", line 1579, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/home/odoo/16E/odoo/service/model.py", line 134, in retrying
result = func()
File "/home/odoo/16E/odoo/http.py", line 1608, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/home/odoo/16E/odoo/http.py", line 1805, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/home/odoo/16E/odoo/addons/website/models/ir_http.py", line 235, in _dispatch
response = super()._dispatch(endpoint)
File "/home/odoo/16E/odoo/addons/base/models/ir_http.py", line 144, in _dispatch
result = endpoint(**request.params)
File "/home/odoo/16E/odoo/http.py", line 698, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/16E/odoo/addons/web/controllers/dataset.py", line 42, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/odoo/16E/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/odoo/16E/odoo/api.py", line 461, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/odoo/16E/odoo/api.py", line 448, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/odoo/16E/odoo/addons/base_automation/models/base_automation.py", line 415, in write
action._process(records, domain_post=domain_post)
File "/home/odoo/16E/odoo/addons/base_automation/models/base_automation.py", line 340, in _process
raise e
File "/home/odoo/16E/odoo/addons/base_automation/models/base_automation.py", line 337, in _process
action_server.sudo().with_context(**ctx).run()
File "/home/odoo/16E/odoo/addons/base/models/ir_actions.py", line 668, in run
res = runner(run_self, eval_context=eval_context)
File "/home/odoo/16E/odoo/addons/website/models/ir_actions_server.py", line 61, in _run_action_code_multi
res = super(ServerAction, self)._run_action_code_multi(eval_context)
File "/home/odoo/16E/odoo/addons/base/models/ir_actions.py", line 538, in _run_action_code_multi
safe_eval(self.code.strip(), eval_context, mode="exec", nocopy=True, filename=str(self)) # nocopy allows to return 'action'
File "/home/odoo/16E/odoo/tools/safe_eval.py", line 353, in safe_eval
raise ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr))
ValueError: <class 'ValueError'>: "Invalid field mail.channel.Sales in leaf ('Sales', '=', 'general')" while evaluating
"# Available variables:\n# - env: Odoo Environment on which the action is triggered\n# - model: Odoo 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: Odoo function to compare floats based on specific precisions\n# - log: log(message, level='info'): logging function to record debug information in ir.logging table\n# - UserError: Warning Exception to use with raise\n# - Command: x2Many commands namespace\n# To return an action, assign: action = {...}\n\nmessage = 'Hello Demo Message'\nenv['mail.channel'].search([('Sales', '=', 'general')]).message_post(body=message)"

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
at makeErrorFromResponse (https://netroneats.com/web/assets/1021-f3ff506/web.assets_backend.min.js:974:163)
at XMLHttpRequest.<anonymous> (https://netroneats.com/web/assets/1021-f3ff506/web.assets_backend.min.js:981:13)

Best Answer

Hello Nihat Demir,

You Can Create Message in the Discussion Channel using Automated Action.

Find Example in comment.

I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari


Avatar
Discard

For Example -

- Create an Automated action by adding name, model, trigger (creation as per your requirement), filter domain (if required) and Action to do ( Execute Python Code as per your need )

- In the Python Code Below Paste this code:-
message = 'Hello Demo Message'
env['mail.channel'].search([('name', '=', 'general')]).message_post(body=message)
- Note :- For searching channel you have to give the name in the search condition.

Best Answer

In order to automate the creation of a message in an Odoo Discuss channel, you will need to use the Odoo's ORM (Object-Relational Mapping) API.


Here is an example of how you might automate the creation of a message in an Odoo Discuss channel using Python:


Copy code

from odoo import api, models


class MyAutomatedMessage(models.Model):

    _name = 'my.automated.message'


    @api.model

    def create_message(self):

        # Replace with the ID of the channel you want to post to

        channel_id = 1


        # The message you want to post

        message = "Hello, this is an automated message."


        # Create the message

        self.env['mail.channel'].browse(channel_id).message_post(body=message, message_type='comment', subtype='mail.mt_comment')

This code creates a new Odoo model called MyAutomatedMessage with a method create_message(). Inside the method, it uses the browse() method of the mail.channel model to get the specific channel by its ID. Then it uses the message_post() method to create the message in the channel with the specified message text, message type, and subtype.


This is a simple example, you can use odoo's scheduler to schedule the creation of the message, or you could use the Odoo's API to create a custom endpoint that can be used to trigger the message creation from an external source.


You should also make sure that you have the necessary access rights to create messages in the channel.


Please note that you need to get your Odoo Discuss 

Avatar
Discard
Best Answer

Hi Nihat: You can do this by creating an automated action (Action to Do: Execute Python Code ) and call the message_post method on the channel.

Avatar
Discard
Related Posts Replies Views Activity
3
Nov 24
2945
5
Nov 24
7445
2
Oct 24
2881
4
Oct 24
1860
2
Oct 24
3996