improvements in to the server action

bzr revid: mga@tinyerp.com-20081216192608-vpjbzrcigqe94qau
This commit is contained in:
Mantavya Gajjar 2008-12-17 00:56:08 +05:30
parent 746373320e
commit 914593fe8a
2 changed files with 37 additions and 9 deletions

View File

@ -1154,6 +1154,7 @@
<field name="state" select="1"/>
<field name="model_id" select="1"/>
<field name="sequence" select="2"/>
<field name="condition" colspan="4"/>
<notebook colspan="4">
<page string="Python Code" attrs="{'invisible':[('state','!=','code')]}">
@ -1175,6 +1176,7 @@
<page string="Email Configuration" attrs="{'invisible':[('state','!=','email')]}">
<separator colspan="4" string="Email Configuration"/>
<field name="email" domain="[('model_id','=',model_id)]"/>
<field name="subject" colspan="4"/>
<field name="message" select="2" colspan="4"/>
<newline/>
<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"/>
@ -1190,7 +1192,7 @@
<page string="Create / Write" attrs="{'invisible':[('state','!=','object_create'),('state','!=','object_write')]}">
<separator colspan="4" string="Fields Mapping"/>
<field name="srcmodel_id" select="2"/>
<field name="srcmodel_id" select="2" attrs="{'required':[('state','!=','sms'), ('state','!=','code'), ('state','!=','trigger'), ('state','!=','client_action'), ('state','!=','email'), ('state','!=','sms'), ('state','!=','other')]}"/>
<field name="fields_lines" nolabel="1" select="2" colspan="4">
<tree string="Field Mappings" editable="top">
<field name="col1" domain="[('model_id','=',parent.srcmodel_id or parent.model_id)]"/>

View File

@ -387,6 +387,7 @@ class actions_server(osv.osv):
_sequence = 'ir_actions_id_seq'
_columns = {
'name': fields.char('Action Name', required=True, size=64),
'condition' : fields.char('Condition', size=256),
'state': fields.selection([
('client_action','Client Action'),
('dummy','Dummy'),
@ -406,6 +407,7 @@ class actions_server(osv.osv):
'wkf_model_id': fields.many2one('ir.model', 'Workflow on'),
'trigger_obj_id': fields.many2one('ir.model.fields','Trigger On'),
'email': fields.many2one('ir.model.fields', 'Contact'),
'subject': fields.char('Subject', size=1024, translate=True),
'message': fields.text('Message', translate=True),
'mobile': fields.many2one('ir.model.fields', 'Contact'),
'sms': fields.char('SMS', size=160, translate=True),
@ -418,6 +420,7 @@ class actions_server(osv.osv):
}
_defaults = {
'state': lambda *a: 'dummy',
'condition': lambda *a: 'True',
'type': lambda *a: 'ir.actions.server',
'sequence': lambda *a: 5,
'code': lambda *a: """# You can use the following variables
@ -500,13 +503,28 @@ class actions_server(osv.osv):
# ACTION_ID : Action to launch
def run(self, cr, uid, ids, context={}):
logger = netsvc.Logger()
for action in self.browse(cr, uid, ids, context):
obj_pool = self.pool.get(action.model_id.model)
obj = obj_pool.browse(cr, uid, context['active_id'], context=context)
cxt = {
'context':context,
'object': obj,
'time':time,
'cr': cr,
'pool' : self.pool,
'uid' : uid
}
expr = eval(str(action.condition), cxt)
if not expr:
continue
if action.state=='client_action':
if not action.action_id:
raise osv.except_osv(_('Error'), _("Please specify an action to launch !"))
return self.pool.get(action.action_id.type).read(cr, uid, action.action_id.id, context=context)
raise osv.except_osv(_('Error'), _("Please specify an action to launch !"))
result = self.pool.get(action.action_id.type).read(cr, uid, action.action_id.id, context=context)
return result
if action.state=='python':
localdict = {
'self': self.pool.get(action.model_id.model),
@ -522,14 +540,15 @@ class actions_server(osv.osv):
if action.state == 'email':
user = config['email_from']
subject = action.name
address = self.get_email(cr, uid, action, context)
if not address:
raise osv.except_osv(_('Error'), _("Please specify the Partner Email address !"))
if not user:
raise osv.except_osv(_('Error'), _("Please specify server option --smtp-from !"))
subject = self.merge_message(cr, uid, str(action.subject), action, context)
body = self.merge_message(cr, uid, str(action.message), action, context)
if tools.email_send(user, [address], subject, body, debug=False, subtype='html') == True:
logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (address))
else:
@ -556,11 +575,11 @@ class actions_server(osv.osv):
logger.notifyChannel('sms', netsvc.LOG_ERROR, 'Failed to send SMS to : %s' % (action.address))
if action.state == 'other':
res = None
res = []
for act in action.child_ids:
result = self.run(cr, uid, [act.id], context)
if result:
res = result
res.append(result)
return res
if action.state == 'object_write':
@ -585,7 +604,13 @@ class actions_server(osv.osv):
else:
obj_pool = self.pool.get(action.srcmodel_id.model)
id = self.pool.get(action.model_id.model).read(cr, uid, [context.get('active_id')], [action.record_id.name])
obj_pool.write(cr, uid, [int(id[0][action.record_id.name])], res)
write_id = False
if action.record_id.ttype in ('char', 'int', 'float'):
write_id = int(id[0][action.record_id.name])
elif action.record_id.ttype in ('many2one'):
write_id = int(id[0][action.record_id.name][0])
obj_pool.write(cr, uid, [write_id], res)
if action.state == 'object_create':
res = {}
@ -603,7 +628,8 @@ class actions_server(osv.osv):
res_id = False
obj_pool = self.pool.get(action.srcmodel_id.model)
res_id = obj_pool.create(cr, uid, res)
self.pool.get(action.model_id.model).write(cr, uid, [context.get('active_id')], {action.record_id.name:res_id})
if action.record_id:
self.pool.get(action.model_id.model).write(cr, uid, [context.get('active_id')], {action.record_id.name:res_id})
return False
actions_server()