Automated Actions with Timing conditions don't seem to fire

Bug #629471 reported by Daniel Watkins (credativ)
16
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Odoo Addons (MOVED TO GITHUB)
Fix Released
Low
OpenERP R&D Addons Team 1

Bug Description

To reproduce:
  1) Create an Automated Action (Sales > Configuration > Automated Actions > Automated Actions) with Object set to crm.lead, Trigger Date set to Creation Date and Delay After Trigger Date set to 1 minute. Set "Set State To" in the Actions tab to Open.
  2) Create a new Lead.
  3) Wait for at least one minute.
  4) Manually run the 'Check Action Rules' scheduler action (Administration > Configuration > Scheduler > Scheduled Actions) by setting the 'Next Call Date' in the past and saving.

Expected result:
  The created Lead to be in the Open state.

Actual result:
  No change to the created Lead.

If you remove the Trigger Date settings, then the Lead will be set to the Open state as soon as it is created.

Related branches

Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

I'm not sure if this is a bug in crm.crm_action_rule or a bug in base_action_rule itself. I suspect the latter.

Revision history for this message
JMA(Open ERP) (jma-openerp) wrote :

Hello Daniel Watkins,

I have thoroughly tested the above scenario.

Well, please go with the help text provided on the field " Delay After Trigger Date ".
It says you specify a negative delay.

Also, specify the "Condition on State" : draft on automated Action form view.
A new "Lead" has initial state 'draft.'

Setting it to "-1" and then running the 'Scheduled Actions' -> Check Action Rules
Change the:
                   interval number from '4 to 1'
                   interval unit to from 'hour to minutes'
Set the 'Next Call Date' to a past date.
Save the record.

Open A New 'Lead' enter details and then save the record the state changes to 'Open'.

I hope this makes things clear.

Let me know if I am missing out something.

Thanks.

Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

The documentation states that you _can_ set a negative delay if you want the event to happen _before_ the Trigger Date. This bug, however, is about the fact that events don't seem to happen _after_ the date, when a positive delay is set.

I'm setting the bug status to Incomplete, as I'm going to test whether or not a negative delay does what we want, despite what the documentation claims. I'll update the bug once that is done.

Changed in openobject-addons:
status: New → Incomplete
Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

Setting the Delay After Trigger Date to a negative number when Trigger Date is set to Creation Date causes it to fire immediately when an object is created.

This does not solve the problem that we are having, which is that actions that should trigger _after_ the Trigger Date do not do so.

Changed in openobject-addons:
status: Incomplete → New
Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

Having just re-read jma's comment, it's clear that there is a lack of understanding as to what the problem is.

We want an action to trigger a certain amount of time after an object is created. I was using 1 minute as an example. All that setting the delay negative was achieving was meaning that the action would occur when the Check Action Rules Scheduled Action next ran.

If we set the delay to 3 days, as we will in production use, this won't work.

Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

Right, I've done some looking at the code.

This is what happens when the scheduler runs:
  The scheduler calls base_action_rule._check.
  base_action_rule._check gets a list of all rules and calls base_action_rule._register_hook with the list.
  base_action_rule._register_hook overrides the create and write methods of the model referenced by each rule.

This is all that is done when the scheduler runs.

This is what happens in the overridden create method:
  The original create method is called.
  base_action_rule.pre_action is called with the id of the newly created object.
  base_action_rule.pre_action gets a list of rules which apply to the model of the object and calls base_action_rule._action with each rule and the object id.
  base_action_rule._action checks whether or not the time delay for this rule and object has expired and, if it has, executes the action.

With the current code, the only time that time delays for an object are checked are when the object is created or written. This means that it is unlikely that Automated Actions are likely to actually run when expected, as they depend on the object in question being written to after the action delay has expired. Furthermore, Automat Actions will run every time the object is saved after the action delay, rather than just once.

Revision history for this message
Daniel Watkins (credativ) (daniel-watkins-credativ) wrote :

Yet more looking, and it seems that _check is doing the wrong thing. See _check in crm_case for what it probably should be doing.

Changed in openobject-addons:
assignee: nobody → OpenERP R&D Addons Team 3 (openerp-dev-addons3)
importance: Undecided → Low
status: New → Confirmed
qdp (OpenERP) (qdp)
Changed in openobject-addons:
milestone: none → 6.0-rc2
Revision history for this message
Mustufa Rangwala (Open ERP) (mra-tinyerp) wrote :

i think its related to base action rule.

Changed in openobject-addons:
assignee: OpenERP R&D Addons Team 3 (openerp-dev-addons3) → OpenERP R&D Addons Team 1 (openerp-dev-addons1)
Revision history for this message
tfr (Openerp) (tfr) wrote :

I confirm the problem is in base_action_rule,
Right now, how works the scheduler ?
As Daniel says it call _check that override the create and write method, that means action defined in action rule are only trigger when create or write is call on an object

try this
  1) Create an Automated Action (Sales > Configuration > Automated Actions > Automated Actions) with Object set to crm.lead, Trigger Date set to Creation Date and Delay After Trigger Date set to 1 minute. Set "Set State To" in the Actions tab to Open.
  2) Create a new Lead.
  3) Wait for at least one minute.
  4) Manually run the 'Check Action Rules' scheduler action (Administration > Configuration > Scheduler > Scheduled Actions) by setting the 'Next Call Date' in the past and saving.

5) Change the sales team for the lead and save
6 ) State Draft => open

Of course this behavior is not the one we expected to fix this bug we should call the method _action
in the method check

But there is some issue, how avoid that the action is launch many time, what to do if the server crach when the action should be trigger. It's not a simple Issue

Changed in openobject-addons:
status: Confirmed → In Progress
Revision history for this message
Bhumika Shrimali (sbh-openerp) wrote :

Hello,

The fix has been committed to lp:~openerp-dev/openobject-addons/trunk-dev addons1 with revision 4619..

Soon it will be merged into main addons.

Thanks

Changed in openobject-addons:
status: In Progress → Fix Committed
status: Fix Committed → Fix Released
Revision history for this message
jiniya (ziamie18) wrote :

Is this problem already fixed? i am having the same problem in openerp v6.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.