2010-02-10 09:54:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2010-07-09 12:14:44 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from datetime import timedelta
|
2012-10-04 12:07:19 +00:00
|
|
|
import time
|
2012-11-26 11:22:48 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2012-10-04 12:07:19 +00:00
|
|
|
|
2012-12-19 14:22:35 +00:00
|
|
|
from openerp.osv import fields, osv
|
2012-12-06 14:56:32 +00:00
|
|
|
from openerp.tools.translate import _
|
2010-02-02 13:47:02 +00:00
|
|
|
|
2010-09-09 14:13:28 +00:00
|
|
|
|
|
|
|
def get_datetime(date_field):
|
2011-12-27 09:27:00 +00:00
|
|
|
'''Return a datetime from a date string or a datetime string'''
|
|
|
|
#complete date time if date_field contains only a date
|
|
|
|
date_split = date_field.split(' ')
|
|
|
|
if len(date_split) == 1:
|
|
|
|
date_field = date_split[0] + " 00:00:00"
|
2012-08-06 16:28:17 +00:00
|
|
|
|
2010-09-09 14:13:28 +00:00
|
|
|
return datetime.strptime(date_field[:19], '%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
|
|
|
2010-02-02 13:47:02 +00:00
|
|
|
class base_action_rule(osv.osv):
|
2010-03-25 13:43:25 +00:00
|
|
|
""" Base Action Rules """
|
|
|
|
|
2010-02-02 13:47:02 +00:00
|
|
|
_name = 'base.action.rule'
|
2010-03-25 13:43:25 +00:00
|
|
|
_description = 'Action Rules'
|
2011-02-09 09:18:48 +00:00
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
def _state_get(self, cr, uid, context=None):
|
2012-10-04 12:07:19 +00:00
|
|
|
""" Get State """
|
2010-04-26 13:45:17 +00:00
|
|
|
return self.state_get(cr, uid, context=context)
|
|
|
|
|
2010-11-19 13:48:01 +00:00
|
|
|
def state_get(self, cr, uid, context=None):
|
2012-10-04 12:07:19 +00:00
|
|
|
""" Get State """
|
2012-11-26 11:22:48 +00:00
|
|
|
return [('', ''), ('na','N/A (No previous state)')]
|
2011-02-09 09:18:48 +00:00
|
|
|
|
2010-02-02 13:47:02 +00:00
|
|
|
_columns = {
|
2011-02-09 09:18:48 +00:00
|
|
|
'name': fields.char('Rule Name', size=64, required=True),
|
2012-10-04 12:07:19 +00:00
|
|
|
'model_id': fields.many2one('ir.model', 'Related Document Model', required=True, domain=[('osv_memory','=', False)]),
|
2012-10-09 07:53:40 +00:00
|
|
|
'model': fields.related('model_id', 'model', type="char", size=256, string='Model'),
|
2011-02-09 09:18:48 +00:00
|
|
|
'create_date': fields.datetime('Create Date', readonly=1),
|
2010-07-06 11:46:25 +00:00
|
|
|
'active': fields.boolean('Active', help="If the active field is set to False,\
|
2011-02-09 09:18:48 +00:00
|
|
|
it will allow you to hide the rule without removing it."),
|
2010-05-10 13:07:29 +00:00
|
|
|
'sequence': fields.integer('Sequence', help="Gives the sequence order \
|
2011-02-09 09:18:48 +00:00
|
|
|
when displaying a list of rules."),
|
2010-04-26 13:45:17 +00:00
|
|
|
'trg_date_type': fields.selection([
|
2011-02-09 09:18:48 +00:00
|
|
|
('none', 'None'),
|
|
|
|
('create', 'Creation Date'),
|
2012-10-09 07:53:40 +00:00
|
|
|
('write', 'Last Modified Date'),
|
2011-02-09 09:18:48 +00:00
|
|
|
('action_last', 'Last Action Date'),
|
|
|
|
('date', 'Date'),
|
|
|
|
('deadline', 'Deadline'),
|
|
|
|
], 'Trigger Date', size=16),
|
2010-05-10 13:07:29 +00:00
|
|
|
'trg_date_range': fields.integer('Delay after trigger date', \
|
|
|
|
help="Delay After Trigger Date,\
|
|
|
|
specifies you can put a negative number. If you need a delay before the \
|
2011-02-09 09:18:48 +00:00
|
|
|
trigger date, like sending a reminder 15 minutes before a meeting."),
|
2010-05-10 13:07:29 +00:00
|
|
|
'trg_date_range_type': fields.selection([('minutes', 'Minutes'), ('hour', 'Hours'), \
|
2011-02-09 09:18:48 +00:00
|
|
|
('day', 'Days'), ('month', 'Months')], 'Delay type'),
|
|
|
|
'act_user_id': fields.many2one('res.users', 'Set Responsible to'),
|
|
|
|
'act_state': fields.selection(_state_get, 'Set State to', size=16),
|
2012-10-04 12:07:19 +00:00
|
|
|
'act_followers': fields.many2many("res.partner", string="Set Followers"),
|
2012-10-09 07:53:40 +00:00
|
|
|
'server_action_ids': fields.one2many('ir.actions.server', 'action_rule_id', 'Server Action', help="Define Server actions.\neg:Email Reminders, Call Object Service, etc.."), #TODO: set domain [('model_id','=',model_id)]
|
2012-11-28 12:01:00 +00:00
|
|
|
'filter_id':fields.many2one('ir.filters', 'Postcondition Filter', required=False), #TODO: set domain [('model_id','=',model_id.model)]
|
|
|
|
'filter_pre_id': fields.many2one('ir.filters', 'Precondition Filter', required=False),
|
2010-09-09 13:17:50 +00:00
|
|
|
'last_run': fields.datetime('Last Run', readonly=1),
|
2010-02-08 10:34:14 +00:00
|
|
|
}
|
2010-03-25 13:43:25 +00:00
|
|
|
|
2010-02-08 10:34:14 +00:00
|
|
|
_defaults = {
|
2012-10-09 07:53:40 +00:00
|
|
|
'active': True,
|
|
|
|
'trg_date_type': 'none',
|
|
|
|
'trg_date_range_type': 'day',
|
2010-02-02 13:47:02 +00:00
|
|
|
}
|
2011-02-09 09:18:48 +00:00
|
|
|
|
2010-05-11 08:59:48 +00:00
|
|
|
_order = 'sequence'
|
2011-02-09 09:18:48 +00:00
|
|
|
|
2012-11-28 09:29:28 +00:00
|
|
|
def post_action(self, cr, uid, ids, model, precondition_ok=None, context=None):
|
2010-06-24 06:17:55 +00:00
|
|
|
# Searching for action rules
|
2010-07-06 13:48:05 +00:00
|
|
|
cr.execute("SELECT model.model, rule.id FROM base_action_rule rule \
|
2010-07-26 09:20:14 +00:00
|
|
|
LEFT JOIN ir_model model on (model.id = rule.model_id) \
|
2012-10-04 12:43:52 +00:00
|
|
|
WHERE active and model = %s", (model,))
|
2010-06-24 06:17:55 +00:00
|
|
|
res = cr.fetchall()
|
|
|
|
# Check if any rule matching with current object
|
|
|
|
for obj_name, rule_id in res:
|
2012-11-23 10:31:13 +00:00
|
|
|
model_pool = self.pool.get(obj_name)
|
2012-10-04 12:07:19 +00:00
|
|
|
# If the rule doesn't involve a time condition, run it immediately
|
|
|
|
# Otherwise we let the scheduler run the action
|
|
|
|
if self.browse(cr, uid, rule_id, context=context).trg_date_type == 'none':
|
2012-11-28 09:29:28 +00:00
|
|
|
self._action(cr, uid, [rule_id], model_pool.browse(cr, uid, ids, context=context), precondition_ok=precondition_ok, context=context)
|
2010-06-24 06:17:55 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
def _create(self, old_create, model, context=None):
|
2011-11-14 11:39:15 +00:00
|
|
|
"""
|
|
|
|
Return a wrapper around `old_create` calling both `old_create` and
|
|
|
|
`post_action`, in that order.
|
|
|
|
"""
|
|
|
|
def wrapper(cr, uid, vals, context=context):
|
2011-12-22 14:10:18 +00:00
|
|
|
if context is None:
|
|
|
|
context = {}
|
2010-06-24 06:17:55 +00:00
|
|
|
new_id = old_create(cr, uid, vals, context=context)
|
2012-11-28 09:29:28 +00:00
|
|
|
#As it is a new record, we can assume that the precondition is true for every filter.
|
|
|
|
#(There is nothing before the create so no condition)
|
|
|
|
precondition_ok = {}
|
|
|
|
precondition_ok[new_id] = {}
|
|
|
|
for action in self.browse(cr, uid, self.search(cr, uid, [], context=context), context=context):
|
2012-11-28 12:01:00 +00:00
|
|
|
if action.filter_pre_id:
|
2012-11-28 09:29:28 +00:00
|
|
|
precondition_ok[new_id][action.id] = False
|
|
|
|
else:
|
|
|
|
precondition_ok[new_id][action.id] = True
|
2010-06-24 06:17:55 +00:00
|
|
|
if not context.get('action'):
|
2012-11-28 09:29:28 +00:00
|
|
|
self.post_action(cr, uid, [new_id], model, precondition_ok=precondition_ok, context=context)
|
2010-06-24 06:17:55 +00:00
|
|
|
return new_id
|
2011-11-14 11:39:15 +00:00
|
|
|
return wrapper
|
2012-08-06 16:28:17 +00:00
|
|
|
|
2010-06-24 06:17:55 +00:00
|
|
|
def _write(self, old_write, model, context=None):
|
2011-11-14 11:39:15 +00:00
|
|
|
"""
|
|
|
|
Return a wrapper around `old_write` calling both `old_write` and
|
|
|
|
`post_action`, in that order.
|
|
|
|
"""
|
|
|
|
def wrapper(cr, uid, ids, vals, context=context):
|
2012-11-23 11:00:56 +00:00
|
|
|
old_records = {}
|
2011-12-22 14:10:18 +00:00
|
|
|
if context is None:
|
|
|
|
context = {}
|
2010-06-24 06:17:55 +00:00
|
|
|
if isinstance(ids, (str, int, long)):
|
|
|
|
ids = [ids]
|
2012-11-23 10:31:13 +00:00
|
|
|
model_pool = self.pool.get(model)
|
2012-11-28 09:29:28 +00:00
|
|
|
# We check for the pre-filter. We must apply it before the write
|
|
|
|
precondition_ok = {}
|
|
|
|
for id in ids:
|
|
|
|
precondition_ok[id] = {}
|
|
|
|
for action in self.browse(cr, uid, self.search(cr, uid, [], context=context), context=context):
|
|
|
|
precondition_ok[id][action.id] = True
|
2012-11-28 12:01:00 +00:00
|
|
|
if action.filter_pre_id and action.model_id.model == action.filter_pre_id.model_id:
|
2012-11-28 09:29:28 +00:00
|
|
|
ctx = dict(context)
|
2012-11-28 12:01:00 +00:00
|
|
|
ctx.update(eval(action.filter_pre_id.context))
|
2012-11-28 09:29:28 +00:00
|
|
|
obj_ids = []
|
|
|
|
if self.pool.get(action.model_id.model)!=None:
|
2012-11-28 12:01:00 +00:00
|
|
|
obj_ids = self.pool.get(action.model_id.model).search(cr, uid, eval(action.filter_pre_id.domain), context=ctx)
|
2012-11-28 09:29:28 +00:00
|
|
|
precondition_ok[id][action.id] = id in obj_ids
|
2011-11-14 11:39:15 +00:00
|
|
|
old_write(cr, uid, ids, vals, context=context)
|
2010-06-24 06:17:55 +00:00
|
|
|
if not context.get('action'):
|
2012-11-28 09:29:28 +00:00
|
|
|
self.post_action(cr, uid, ids, model, precondition_ok=precondition_ok, context=context)
|
2011-11-14 11:39:15 +00:00
|
|
|
return True
|
|
|
|
return wrapper
|
2010-06-24 06:17:55 +00:00
|
|
|
|
2012-11-26 11:22:48 +00:00
|
|
|
def _register_hook(self, cr):
|
2011-11-14 11:39:15 +00:00
|
|
|
"""
|
|
|
|
Wrap every `create` and `write` methods of the models specified by
|
|
|
|
the rules (given by `ids`).
|
|
|
|
"""
|
2012-11-26 11:22:48 +00:00
|
|
|
ids = self.search(cr,SUPERUSER_ID,[])
|
2012-11-26 13:10:17 +00:00
|
|
|
return self._register_hook_(cr,SUPERUSER_ID,ids,context=None)
|
|
|
|
|
|
|
|
def _register_hook_(self, cr, uid, ids, context=None):
|
|
|
|
"""
|
|
|
|
Wrap every `create` and `write` methods of the models specified by
|
|
|
|
the rules (given by `ids`).
|
|
|
|
"""
|
2012-11-26 13:32:57 +00:00
|
|
|
reg_ids = []
|
|
|
|
if not isinstance(ids, list):
|
|
|
|
reg_ids.append(ids)
|
|
|
|
else:
|
|
|
|
reg_ids.extend(ids)
|
|
|
|
for action_rule in self.browse(cr, uid, reg_ids, context=context):
|
2010-07-26 09:20:14 +00:00
|
|
|
model = action_rule.model_id.model
|
2010-07-06 11:46:25 +00:00
|
|
|
obj_pool = self.pool.get(model)
|
2010-08-26 14:20:22 +00:00
|
|
|
if not hasattr(obj_pool, 'base_action_ruled'):
|
2012-11-26 11:22:48 +00:00
|
|
|
obj_pool.create = self._create(obj_pool.create, model, context=None)
|
|
|
|
obj_pool.write = self._write(obj_pool.write, model, context=None)
|
2010-08-26 14:20:22 +00:00
|
|
|
obj_pool.base_action_ruled = True
|
|
|
|
return True
|
2011-11-14 11:39:15 +00:00
|
|
|
|
2010-06-24 06:17:55 +00:00
|
|
|
def create(self, cr, uid, vals, context=None):
|
2010-11-19 13:48:01 +00:00
|
|
|
res_id = super(base_action_rule, self).create(cr, uid, vals, context=context)
|
2012-11-26 13:10:17 +00:00
|
|
|
self._register_hook_(cr, uid, res_id,context=context)
|
2010-06-24 06:17:55 +00:00
|
|
|
return res_id
|
2011-02-09 09:18:48 +00:00
|
|
|
|
2010-06-24 06:17:55 +00:00
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
2011-11-14 11:39:15 +00:00
|
|
|
super(base_action_rule, self).write(cr, uid, ids, vals, context=context)
|
2012-11-26 13:10:17 +00:00
|
|
|
self._register_hook_(cr, uid, ids, context=context)
|
2011-11-14 11:39:15 +00:00
|
|
|
return True
|
2010-06-24 06:17:55 +00:00
|
|
|
|
|
|
|
def _check(self, cr, uid, automatic=False, use_new_cursor=False, \
|
|
|
|
context=None):
|
|
|
|
"""
|
|
|
|
This Function is call by scheduler.
|
|
|
|
"""
|
2012-10-09 10:43:14 +00:00
|
|
|
rule_ids = self.search(cr, uid, [], context=context)
|
2012-11-26 13:10:17 +00:00
|
|
|
self._register_hook_(cr, uid, rule_ids, context=context)
|
2012-10-09 10:43:14 +00:00
|
|
|
if context is None:
|
|
|
|
context = {}
|
|
|
|
for rule in self.browse(cr, uid, rule_ids, context=context):
|
2010-09-09 13:17:50 +00:00
|
|
|
model = rule.model_id.model
|
|
|
|
model_pool = self.pool.get(model)
|
|
|
|
last_run = False
|
|
|
|
if rule.last_run:
|
2010-09-09 14:13:28 +00:00
|
|
|
last_run = get_datetime(rule.last_run)
|
2010-09-09 13:17:50 +00:00
|
|
|
now = datetime.now()
|
2012-10-09 10:43:14 +00:00
|
|
|
ctx = dict(context)
|
|
|
|
if rule.filter_id and rule.model_id.model == rule.filter_id.model_id:
|
|
|
|
ctx.update(eval(rule.filter_id.context))
|
|
|
|
obj_ids = model_pool.search(cr, uid, eval(rule.filter_id.domain), context=ctx)
|
|
|
|
else:
|
|
|
|
obj_ids = model_pool.search(cr, uid, [], context=ctx)
|
|
|
|
for obj in model_pool.browse(cr, uid, obj_ids, context=ctx):
|
2010-09-09 13:26:50 +00:00
|
|
|
# Calculate when this action should next occur for this object
|
2010-09-09 13:17:50 +00:00
|
|
|
base = False
|
|
|
|
if rule.trg_date_type=='create' and hasattr(obj, 'create_date'):
|
2010-09-09 14:25:49 +00:00
|
|
|
base = obj.create_date
|
2012-10-09 07:53:40 +00:00
|
|
|
elif rule.trg_date_type=='write' and hasattr(obj, 'write_date'):
|
|
|
|
base = obj.write_date
|
2010-09-09 14:27:08 +00:00
|
|
|
elif (rule.trg_date_type=='action_last'
|
|
|
|
and hasattr(obj, 'create_date')):
|
2010-09-09 13:17:50 +00:00
|
|
|
if hasattr(obj, 'date_action_last') and obj.date_action_last:
|
2010-09-09 14:25:49 +00:00
|
|
|
base = obj.date_action_last
|
2010-09-09 13:17:50 +00:00
|
|
|
else:
|
2010-09-09 14:25:49 +00:00
|
|
|
base = obj.create_date
|
2010-09-09 14:27:08 +00:00
|
|
|
elif (rule.trg_date_type=='deadline'
|
|
|
|
and hasattr(obj, 'date_deadline')
|
|
|
|
and obj.date_deadline):
|
2010-09-09 14:25:49 +00:00
|
|
|
base = obj.date_deadline
|
2010-09-09 14:27:08 +00:00
|
|
|
elif (rule.trg_date_type=='date'
|
|
|
|
and hasattr(obj, 'date')
|
|
|
|
and obj.date):
|
2010-09-09 14:25:49 +00:00
|
|
|
base = obj.date
|
2010-09-09 13:17:50 +00:00
|
|
|
if base:
|
|
|
|
fnct = {
|
2010-09-09 14:27:08 +00:00
|
|
|
'minutes': lambda interval: timedelta(minutes=interval),
|
|
|
|
'day': lambda interval: timedelta(days=interval),
|
|
|
|
'hour': lambda interval: timedelta(hours=interval),
|
|
|
|
'month': lambda interval: timedelta(months=interval),
|
2010-09-09 13:17:50 +00:00
|
|
|
}
|
2010-09-09 14:25:49 +00:00
|
|
|
base = get_datetime(base)
|
2010-09-09 14:28:09 +00:00
|
|
|
delay = fnct[rule.trg_date_range_type](rule.trg_date_range)
|
|
|
|
action_date = base + delay
|
2010-09-09 14:28:41 +00:00
|
|
|
if (not last_run or (last_run <= action_date < now)):
|
2012-10-09 10:43:14 +00:00
|
|
|
try:
|
2012-10-09 11:12:21 +00:00
|
|
|
self._action(cr, uid, [rule.id], obj, context=ctx)
|
2012-10-09 10:43:14 +00:00
|
|
|
self.write(cr, uid, [rule.id], {'last_run': now}, context=context)
|
|
|
|
except Exception, e:
|
|
|
|
import traceback
|
|
|
|
print traceback.format_exc()
|
|
|
|
|
|
|
|
|
2010-06-24 06:17:55 +00:00
|
|
|
|
2012-11-28 09:29:28 +00:00
|
|
|
def do_check(self, cr, uid, action, obj, precondition_ok=True, context=None):
|
2012-10-04 12:07:19 +00:00
|
|
|
""" check Action """
|
2010-08-24 11:20:57 +00:00
|
|
|
if context is None:
|
|
|
|
context = {}
|
2012-11-28 09:29:28 +00:00
|
|
|
ok = precondition_ok
|
2012-11-28 12:01:00 +00:00
|
|
|
if action.filter_id and action.model_id.model == action.filter_id.model_id:
|
2012-10-09 12:17:12 +00:00
|
|
|
ctx = dict(context)
|
2012-11-28 12:01:00 +00:00
|
|
|
ctx.update(eval(action.filter_id.context))
|
|
|
|
obj_ids = self.pool.get(action.model_id.model).search(cr, uid, eval(action.filter_id.domain), context=ctx)
|
2012-10-09 12:17:12 +00:00
|
|
|
ok = ok and obj.id in obj_ids
|
2010-02-15 14:42:24 +00:00
|
|
|
return ok
|
|
|
|
|
2012-10-09 10:43:14 +00:00
|
|
|
def do_action(self, cr, uid, action, obj, context=None):
|
2012-10-04 12:07:19 +00:00
|
|
|
""" Do Action """
|
2010-08-24 11:20:57 +00:00
|
|
|
if context is None:
|
|
|
|
context = {}
|
2012-10-05 07:12:29 +00:00
|
|
|
ctx = dict(context)
|
2012-10-09 10:43:14 +00:00
|
|
|
model_obj = self.pool.get(action.model_id.model)
|
2012-10-05 07:12:29 +00:00
|
|
|
action_server_obj = self.pool.get('ir.actions.server')
|
|
|
|
if action.server_action_ids:
|
2012-10-09 10:43:14 +00:00
|
|
|
ctx.update({'active_model': action.model_id.model, 'active_id':obj.id, 'active_ids':[obj.id]})
|
2012-10-05 07:12:29 +00:00
|
|
|
action_server_obj.run(cr, uid, [x.id for x in action.server_action_ids], context=ctx)
|
2010-06-24 06:17:55 +00:00
|
|
|
|
2012-10-04 12:07:19 +00:00
|
|
|
write = {}
|
2010-02-15 14:42:24 +00:00
|
|
|
if hasattr(obj, 'user_id') and action.act_user_id:
|
|
|
|
write['user_id'] = action.act_user_id.id
|
2010-03-25 13:43:25 +00:00
|
|
|
if hasattr(obj, 'date_action_last'):
|
2010-02-15 14:42:24 +00:00
|
|
|
write['date_action_last'] = time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
if hasattr(obj, 'state') and action.act_state:
|
|
|
|
write['state'] = action.act_state
|
|
|
|
|
|
|
|
model_obj.write(cr, uid, [obj.id], write, context)
|
2012-10-04 12:07:19 +00:00
|
|
|
if hasattr(obj, 'state') and hasattr(obj, 'message_post') and action.act_state:
|
|
|
|
model_obj.message_post(cr, uid, [obj], _(action.act_state), context=context)
|
|
|
|
|
|
|
|
if hasattr(obj, 'message_subscribe') and action.act_followers:
|
2012-10-05 07:20:01 +00:00
|
|
|
exits_followers = [x.id for x in obj.message_follower_ids]
|
|
|
|
new_followers = [x.id for x in action.act_followers if x.id not in exits_followers]
|
|
|
|
if new_followers:
|
|
|
|
model_obj.message_subscribe(cr, uid, [obj.id], new_followers, context=context)
|
2010-02-08 10:34:14 +00:00
|
|
|
return True
|
2010-02-15 14:42:24 +00:00
|
|
|
|
2012-11-28 09:29:28 +00:00
|
|
|
def _action(self, cr, uid, ids, objects, scrit=None, precondition_ok=None, context=None):
|
2012-10-04 12:07:19 +00:00
|
|
|
""" Do Action """
|
2010-08-24 11:20:57 +00:00
|
|
|
if context is None:
|
|
|
|
context = {}
|
2010-06-24 06:17:55 +00:00
|
|
|
context.update({'action': True})
|
2012-10-09 11:12:21 +00:00
|
|
|
if not isinstance(objects, list):
|
|
|
|
objects = [objects]
|
|
|
|
for action in self.browse(cr, uid, ids, context=context):
|
|
|
|
for obj in objects:
|
2012-11-28 09:29:28 +00:00
|
|
|
ok = True
|
|
|
|
if precondition_ok!=None:
|
|
|
|
ok = precondition_ok[obj.id][action.id]
|
|
|
|
if self.do_check(cr, uid, action, obj, precondition_ok=ok, context=context):
|
2012-10-09 11:12:21 +00:00
|
|
|
self.do_action(cr, uid, action, obj, context=context)
|
2010-06-24 06:17:55 +00:00
|
|
|
context.update({'action': False})
|
2010-02-02 13:47:02 +00:00
|
|
|
return True
|
2010-03-25 13:43:25 +00:00
|
|
|
|
2012-10-05 08:03:25 +00:00
|
|
|
class actions_server(osv.osv):
|
|
|
|
_inherit = 'ir.actions.server'
|
|
|
|
_columns = {
|
|
|
|
'action_rule_id': fields.many2one("base.action.rule", string="Action Rule")
|
|
|
|
}
|
2010-06-24 06:17:55 +00:00
|
|
|
|
2010-02-02 13:47:02 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|