Skip to Content
Menu
This question has been flagged
1 Reply
6241 Views

There's no documentation on creating an automated action.


The one there is, is about scheduled actions (ir.cron)

https://www.odoo.com/documentation/15.0/developer/reference/backend/actions.html#automated-actions-ir-cron


How does one create an automated action via XML?


It used to be something like this:

https://github.com/odoo/odoo/blob/12.0/addons/base_automation/data/base_automation_demo.xml


Bus this file doesn't exists after v12.


So the top entry gives this error in v15:


raise ParseError('while parsing %s:%s, somewhere inside\n%s' % (
odoo.tools.convert.ParseError: while parsing /home/odoo/src/user/module/views/automated_actions.xml:4, somewhere inside
<record id="test_rule_on_create" model="base.automation">
<field name="name">Base Automation: test rule on create</field>
<field name="model_id" ref="base_automation.model_base_automation_lead_test"/>
<field name="state">code</field>
<field name="code" eval="'records.write({\'user_id\': %s})' % ref('base.user_demo')"/>
<field name="trigger">on_create</field>
<field name="active" eval="True"/>
<field name="model_id" ref="base_automation.model_base_automation_lead_test"/>
<field name="filter_domain">[('state', '=', 'draft')]</field>
</record>





Any help would be appreciated.

Avatar
Discard

try changing model_id to some other models like purchase.purchase_order. I guess odoo15 don't have this model
Also remove duplicate model_id field.

Author

I did what you proposed, but to no avail.

I guess the problem is even before reading the contents, since it throws a parse error instead of complaining about the actual model.

It seems the XML isn't structured correctly or something.

Author

Ok, I got it working now.

It was indeed being problematic about the external ID of the model.

I got more feedback in the log when I scrolled up in the server log, which was out of view on default.

Thank you for your help  Mohammed Amal N


Best Answer

Hi,

Make sure the references used to other models/ data in xml is available.

here is an example:



  

id="test_rule_on_create" model="base.automation">
name="name">Base Automation: test rule on create
name="model_id" ref="purchase.model_purchase_order"/>
name="state">code
name="code" eval="'records.write({\'user_id\': %s})' % ref('base.user_demo')"/>
name="trigger">on_create
name="active" eval="True"/>
name="filter_domain">[('state', '=', 'draft')]





Make sure you have purchase and base_automation modules in your dependencies. And demo data activated for the database for this code to work.

Thank You

Avatar
Discard

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="test_rule_on_create" model="base.automation">
<field name="name">Base Automation: test rule on create</field>
<field name="model_id" ref="purchase.model_purchase_order"/>
<field name="state">code</field>
<field name="code" eval="'records.write({\'user_id\': %s})' % ref('base.user_demo')"/>
<field name="trigger">on_create</field>
<field name="active" eval="True"/>
<field name="filter_domain">[('state', '=', 'draft')]</field>
</record>
</odoo>

Added code in comments as there is some problem for me to copy paste in here. don't know why

Author

Even this throws a parse error:

<record id="test_rule_on_create" model="base.automation">
</record>

I think it bumps on the base.automation model. It probably doesn't work anymore to create records in this fashion.

I just tested this code myself in Odoo 15. Try the code in a new file. Your issue should be coming from some other place

Author

and base_automation is in the depends section of the manifest

Author

side question: do you happen to know how to populate the trigger_field_ids field?
I got so far as to provide something like this:
<field name="trigger_field_ids" eval="[(6, 0, [ ref('sale_subscription.date'), ref('module.x_studio_field')])]"/>

But it complains it can't find the external ID
ValueError: <class 'ValueError'>: "External ID not found in the system: sale_subscription.field_date" while evaluating

Author

I found it: View Metadata after viewing the field in the model, there's the external ID you need to provide

Related Posts Replies Views Activity
0
Mar 22
1553
2
May 24
535
1
Jan 23
717
1
Sep 22
2543
1
Jun 22
2407