improved_actions

bzr revid: fp@tinyerp.com-20081126235220-jkgzn4ih87ko3xmp
This commit is contained in:
Fabien Pinckaers 2008-11-27 00:52:20 +01:00
parent 784867992a
commit b8fe8289c0
3 changed files with 16 additions and 23 deletions

View File

@ -1160,7 +1160,7 @@
<field name="sms" colspan="4" attrs="{'readonly':[('state','=','python'), ('state','=','email'), ('state','=','dummy'),('state','=','trigger'), ('state','=','object_create'), ('state','=','object_write'), ('state','=','client_action'), ('state','=','other')]}"/>
<field name="message" select="2" colspan="4" attrs="{'readonly':[('state','=','python'), ('state','=','dummy'),('state','=','trigger'), ('state','=','object_create'), ('state','=','object_write'), ('state','=','sms'), ('state','=','client_action'), ('state','=','other')]}" />
<newline/>
<label colspan="4" string="Access all the fields related to the current object easily just by defining name of the attribute, i.e. [[partner_id.name]] for Invoice Object"/>
<label colspan="4" string="Access all the fields related to the current object using expression in double brackets, i.e. [[ object.partner_id.name ]]" align="0.0"/>
</page>
<page string="Create / Write" attrs="{'invisible':[('state','=','python'),('state','=','dummy'),('state','=','trigger'), ('state','=','sms'), ('state','=','email'), ('state','=','client_action'), ('state','=','other')]}">
@ -1179,6 +1179,7 @@
<field name="value" colsapan="4"/>
</form>
</field>
<label colspan="4" string="If you use a formula type, use a python expression using the variable 'object'." align="0.0"/>
</page>
<page string="Other Actions" attrs="{'invisible':[('state','!=','other')]}">

View File

@ -438,26 +438,12 @@ class actions_server(osv.osv):
def merge_message(self, cr, uid, keystr, action, context):
logger = netsvc.Logger()
def merge(match):
obj_pool = self.pool.get(action.model_id.model)
id = context.get('active_id')
obj = obj_pool.browse(cr, uid, id)
return eval(match[2:-2], {'object':obj, 'context': context,'time':time})
field = match.group()
field = field.replace('[','')
field = field.replace(']','')
field = field.strip()
fields = field.split('.')
for field in fields:
try:
obj = getattr(obj, field)
except Exception,e :
logger.notifyChannel('Workflow', netsvc.LOG_ERROR, 'Failed to parse : %s' % (match.group()))
return str(obj)
com = re.compile('\[\[(.+?)\]\]')
com = re.compile('(\[\[.+?\]\])')
message = com.sub(merge, keystr)
return message
@ -490,9 +476,7 @@ class actions_server(osv.osv):
address = self.get_field_value(cr, uid, action, context)
if not address:
raise osv.except_osv(_('Error'), _("Please specify the Partner Email address !"))
body = self.merge_message(cr, uid, str(action.message), action, context)
if tools.email_send_attach(user, address, subject, body, debug=False) == True:
logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (address))
else:
@ -537,8 +521,9 @@ class actions_server(osv.osv):
for exp in action.fields_lines:
euq = exp.value
if exp.type == 'equation':
expr = self.merge_message(cr, uid, euq, action, context)
expr = eval(expr)
obj_pool = self.pool.get(action.model_id.model)
obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
expr = eval(euq, {'context':context, 'object': obj})
else:
expr = exp.value
res[exp.col1.name] = expr
@ -550,8 +535,9 @@ class actions_server(osv.osv):
for exp in action.fields_lines:
euq = exp.value
if exp.type == 'equation':
expr = self.merge_message(cr, uid, euq, action, context)
expr = eval(expr)
obj_pool = self.pool.get(action.model_id.model)
obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
expr = eval(euq, {'context':context, 'object': obj})
else:
expr = exp.value
res[exp.col1.name] = expr

View File

@ -96,6 +96,12 @@ def _execute(cr, workitem, activity, ident, stack):
if activity['kind']=='dummy':
if workitem['state']=='active':
_state_set(cr, workitem, activity, 'complete', ident)
if activity['action_id']:
print 'ICI'
res2 = wkf_expr.execute_action(cr, ident, workitem, activity)
if res2:
stack.append(res2)
result=res2
elif activity['kind']=='function':
if workitem['state']=='active':
_state_set(cr, workitem, activity, 'running', ident)