Search 1.9 billion lines of Odoo code on GitHub

base_action_agent

Author: Daniel Reis, Odoo Community Association (OCA)
License: AGPL-3
Branch: 8.0-agent-bot
Repository: dreispt/server-tools
Dependencies: base_action_rule
Languages: Python (260, 52.1%), XML (116, 23.2%), and reStructuredText (123, 24.6%)

<img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.svg"> <a name="action-rules-extensions"></a> <h2>Action Rules Extensions</h2> <p>Summary of features provided:</p> <blockquote> <ul class="simple"> <li>Rule Sets organize Automated Rules in logical sets</li> <li>Run Automated Actions using a specific user.</li> <li>Define Rule filters composed of several combined Python snippets</li> </ul> </blockquote> <p>Rule sets are capable to provide an alternative workflow system:</p> <blockquote> <ul class="simple"> <li>A Workflow is defined using a Rule Set</li> <li>Nodes, or States, are represented by Facts</li> <li>Signals, or transition conditions, are represented by Facts using changed / old vs new values</li> <li>Transitions are represented by Action Rules</li> </ul> </blockquote> <p>With the &quot;Run As&quot; feature we have basic support for Bots or Agents:</p> <blockquote> <ul class="simple"> <li>Create a User for the Bot. Make sure it has the necessary security permissions.</li> <li>Create a new Ruleset and set the Bot as its User.</li> <li>Create the Automated Action to be ran by the Bot.</li> <li>Check the Bot's ruleset &quot;Enabled&quot; flag to active the Rules.</li> </ul> </blockquote> <p>Make your OdooBot the best worker in the company!</p> <a name="rule-sets"></a> <h3>Rule Sets</h3> <p>As the number of Action Rules increases it may get confusing. Rulesets allow to organize the rules per topic.</p> <p>Additionally you can assign a default User to a ruleset. Assign that to a bot User, and the ruleset becomes a bot playbook. You also have a &quot;Enabled&quot; flag to enable/disable the rules.</p> <p>The &quot;Silence Error?&quot; option allows for exceptions, other than <code>raise Warning()</code>, to be logged only and not propagated to the user. This is useful for some helper Bot use cases, where we don't want any Bot malfunction (missing security access, for example) to disturb the end user.</p> <a name="facts"></a> <h3>Facts</h3> <p>Facts are logic expressions to be evaluated. They can express state (ex: &quot;Is Open&quot;) or events (ex: &quot;Changed to Open&quot;).</p> <p>These are Python expressions, and their evaluation context has available:</p> <blockquote> <ul class="simple"> <li><code>self</code>, <code>obj</code>: is the record object, after the create/write operation</li> <li><code>env</code>, <code>context</code>, and <code>user</code></li> <li><code>creating</code>, <code>inserting</code>: True if triggered by a create operation</li> <li><code>writing</code>, <code>updating</code>: True if triggered by a write operation</li> <li><code>vals</code>: a dictionary with the original create/write values</li> <li><code>old('&lt;field&gt;')</code>: gets the old value before the write operation</li> <li><code>new('&lt;field&gt;')</code>: gets the new value after the create/write operation</li> <li><code>changed('&lt;fld1&gt;'[,...])</code>: checks if the any of the fields changed value</li> <li><code>changed_to('&lt;field&gt;')</code>: checks if the field changed and returns the new value</li> <li><code>datetime</code>, <code>timedelta</code>, <code>dateutil</code> modules</li> <li><code>Date</code> and <code>Datetime</code> references to the Odoo field classes</li> </ul> </blockquote> <p>Values are retrieved from a ORM record browse, so dot notation is available. <code>old</code> and <code>new</code> also accept a seconf parameter with a default value to use. These expressions are more powerful and succint than the standard domain filters.</p> <p>Examples:</p> <blockquote> <ul class="simple"> <li><code>old('user_id').login='brian' and new('user_id').login=='eric'</code>: changed from brian to eric</li> <li><code>changed('user_id') and self.user_id.login=='brian'</code>: responsible changed to 'brian'</li> <li><code>changed('project_id') and not changed('user_id')</code>: project changed but responsible user didn't</li> </ul> </blockquote> <a name="action-rules"></a> <h3>Action Rules</h3> <p>To support rulesets and bot operators, Automated Actions now have a Ruleset they belong to, and a &quot;Run As User&quot; field for the user under which the actions to execute will be performed. If not set, the Rule will try to use the User of the parent Rule Set.</p> <p>A new &quot;Condition Facts&quot; field is available to list the Facts that should trigger the rule. It complements and runs after any existing domain filters.</p> <a name="configuration"></a> <h2 class="with-subtitle">Configuration</h2> <h2 class="section-subtitle" id="workflows"><span class="section-subtitle">Workflows</span></h2> <dl class="docutils"> <dt>It also intends to provide an alternative workflow system:</dt> <dd><ul class="first last simple"> <li>A Workflow is defined using a Rule Set</li> <li>Nodes, or States, are represented by Facts</li> <li>Signals, or transition conditions, are represented by Facts using changed / old vs new values</li> <li>Transitions are represented by Action Rules</li> </ul> </dd> </dl> <p>For example, part of a customer service workflow we want an Issue to change to Open only after the Sales Rep. approves the new Issue.</p> <dl class="docutils"> <dt>Rules:</dt> <dd><ul class="first last simple"> <li>If &quot;Is New Unapproved&quot;, &quot;Is Not Customer Manager&quot;, &quot;Changed to Ready&quot; Then raise Warning.</li> <li>If &quot;Is New Approved Issue&quot; Then set Stage to Open</li> </ul> </dd> <dt>Facts:</dt> <dd><ul class="first last simple"> <li>&quot;Is Not Customer Manager&quot;, current User is different from the Issue's Customer Manager: <code>user != self.partner_id.user_id</code></li> <li>&quot;Changed to Ready&quot;, Kanban State changed to Ready: <code>changed_to('kanban_state')=='ready'</code></li> <li>&quot;New Unapproved Issue&quot;, in the New Stage with a Kanban State different from Ready: <code>self.stage_id.name=='New' and self.kanban_state!='ready'</code></li> <li>&quot;New Approved Issue&quot;, in the New Stage with a Kanban State equal to Ready: <code>self.stage_id.name=='New' and self.kanban_state=='ready'</code></li> </ul> </dd> </dl> <a name="usage"></a> <h2>Usage</h2> <p>The new feature can be configured at Settings &gt; Technical &gt; Automation:</p> <blockquote> <ul class="simple"> <li>Rule Sets and Rule Facts are available in new menu options.</li> <li>Automated Actions have new fields available.</li> </ul> </blockquote> <a class="reference external image-reference" href="https://runbot.odoo-community.org/runbot/149/8.0"><img alt="Try me on Runbot" src="https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas" /></a> <a name="known-issues-roadmap"></a> <h2>Known issues / Roadmap</h2> <blockquote> <ul class="simple"> <li>Implement the &quot;Run As&quot; for scheduler run actions.</li> <li>Add optional logging / tracking for Ruleset actions.</li> <li>Setting up workflow conditions can be tricky. How to aid the user?</li> <li>The Bot support can be greatly expanded. It could be plugged to Artificial Intelligence techniques, starting with rule based expert systems up to machine learning techniques. Adding better Production Rule System would be interesting.</li> </ul> </blockquote> <p>Also some TODO marker have been left in the source code, signaling some very specific improvements that could be made-</p> <a name="bug-tracker"></a> <h2>Bug Tracker</h2> <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed feedback <a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20base_rule_agent%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">here</a>.</p> <a name="credits"></a> <h2>Credits</h2> <a name="contributors"></a> <h3>Contributors</h3> <ul class="simple"> <li>Daniel Reis</li> </ul> <p>Partly based on the 6.1 module <cite>base_Action_rule_triggers</cite>: <a class="reference external" href="https://github.com/dreispt/odoo-addons/tree/6.1/base_action_rule_triggers">https://github.com/dreispt/odoo-addons/tree/6.1/base_action_rule_triggers</a></p> <a name="maintainer"></a> <h3>Maintainer</h3> <a class="reference external image-reference" href="http://odoo-community.org"><img alt="Odoo Community Association" src="http://odoo-community.org/logo.png" /></a> <p>This module is maintained by the OCA.</p> <p>OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.</p> <p>To contribute to this module, please visit <a class="reference external" href="http://odoo-community.org">http://odoo-community.org</a>.</p>