I found out the reason. The '_check' function in 'Check Action Rules' scheduler checking a condition before executing the process. That condition checks whether the action date greater than last automated action run datetime and less than of current datetime. Whenever the '_check' function executes it saves that time as last run date. So that's why when we run the scheduler manually by putting back date, it is not executing process.
/addons/base_action_rule/base_action_rule.py line: 334
##For testing you can modify the code as
if action_dt <= now:
def _check(self, cr, uid, automatic=False, use_new_cursor=False, context=None):
""" This Function is called by scheduler. """
context = context or {}
# retrieve all the action rules to run based on a timed condition
action_dom = [('kind', '=', 'on_time')]
action_ids = self.search(cr, uid, action_dom, context=context)
for action in self.browse(cr, uid, action_ids, context=context):
now = datetime.now()
if action.last_run:
last_run = get_datetime(action.last_run)
else:
last_run = datetime.utcfromtimestamp(0)
# retrieve all the records that satisfy the action's condition
model = self.pool[action.model_id.model]
domain = []
ctx = dict(context)
if action.filter_id:
domain = eval(action.filter_id.domain)
ctx.update(eval(action.filter_id.context))
if 'lang' not in ctx:
# Filters might be language-sensitive, attempt to reuse creator lang
# as we are usually running this as super-user in background
[filter_meta] = action.filter_id.get_metadata()
user_id = filter_meta['write_uid'] and filter_meta['write_uid'][0] or \
filter_meta['create_uid'][0]
ctx['lang'] = self.pool['res.users'].browse(cr, uid, user_id).lang
record_ids = model.search(cr, uid, domain, context=ctx)
# determine when action should occur for the records
date_field = action.trg_date_id.name
if date_field == 'date_action_last' and 'create_date' in model._fields:
get_record_dt = lambda record: record[date_field] or record.create_date
else:
get_record_dt = lambda record: record[date_field]
# process action on the records that should be executed
for record in model.browse(cr, uid, record_ids, context=context):
record_dt = get_record_dt(record)
if not record_dt:
continue
action_dt = self._check_delay(cr, uid, action, record, record_dt, context=context)
if last_run <= action_dt < now:
try:
context = dict(context or {}, action=True)
self._process(cr, uid, action, [record.id], context=context)
except Exception:
import traceback
_logger.error(traceback.format_exc())
action.write({'last_run': now.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})
if automatic:
# auto-commit for batch processing
cr.commit()
Can we have your xml code to create this automated action ? And the python code of the automated action... Without it, not easy to understand your error/problem...
This is not done by code.. It is done by configuration. ie Settings -> Technical -> Automation -> Automated Action. Created an automated action and server action in this to send email. 'Trigger date' as one date field and 'Delay after trigger date' is -1 minutes. Means 1 minute before the trigger date. But it is working only one time. Even if i run the scheduler, it is not working.
What is your use case exactly ? Do you know the difference between Automated action and scheduled action ?