* change view for the server action
* change the selecte method for the email / sms address bzr revid: mga@tinyerp.com-20080819112303-4xphj3m3mfya9k7l
This commit is contained in:
parent
a6012ca9b1
commit
8612ed6da6
|
@ -1039,23 +1039,34 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Server Action">
|
||||
<field name="name" select="1"/>
|
||||
<field name="name" select="1"/>
|
||||
<field name="state" select="1"/>
|
||||
<field name="model_id" select="1"/>
|
||||
<field name="sequence" select="2"/>
|
||||
<separator colspan="4" string="Python code"/>
|
||||
<field name="code" colspan="4" attrs="{'readonly':[('state','!=','python')]}"/>
|
||||
|
||||
<separator colspan="4" string="Trigger Configuration"/>
|
||||
<field name="trigger_obj_id" select="2" colspan="4" attrs="{'readonly':[('state','!=','trigger')]}"/>
|
||||
<field name="trigger_name" select="2" attrs="{'readonly':[('state','!=','trigger')]}"/>
|
||||
<!-- <field name="trigger_object_id" attrs="{'readonly':[('state','!=','trigger')]}"/>-->
|
||||
<separator colspan="4" string="Email Configuration"/>
|
||||
<field name="address" select="2" attrs="{'readonly':[('state','=','python'),('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','=','client_action'), ('state','=','other')]}"/>
|
||||
|
||||
<separator colspan="4" string="Other Actions Configuration"/>
|
||||
<field name="child_ids" colspan="4" attrs="{'readonly':[('state','!=','other')]}"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Python Code" attrs="{'invisible':[('state','!=','python')]}">
|
||||
<separator colspan="4" string="Python code"/>
|
||||
<field name="code" colspan="4" nolabel="1" />
|
||||
</page>
|
||||
|
||||
<page string="Trigger" attrs="{'invisible':[('state','!=','trigger')]}">
|
||||
<separator colspan="4" string="Trigger Configuration"/>
|
||||
<field name="trigger_obj_id" select="2" colspan="4"/>
|
||||
<field name="trigger_name" select="2"/>
|
||||
</page>
|
||||
|
||||
<page string="Email" attrs="{'invisible':[('state','=','python'),('state','=','dummy'),('state','=','trigger'), ('state','=','object_create'), ('state','=','object_write'), ('state','=','client_action'), ('state','=','other')]}">
|
||||
<separator colspan="4" string="Email Configuration"/>
|
||||
<field name="address" domain="[('model_id','=',model_id)]"/>
|
||||
<field name="message" select="2" colspan="4"/>
|
||||
</page>
|
||||
|
||||
<page string="Other Actions" attrs="{'invisible':[('state','!=','other')]}">
|
||||
<separator colspan="4" string="Other Actions Configuration"/>
|
||||
<field name="child_ids" nolabel="1" colspan="4" />
|
||||
</page>
|
||||
|
||||
</notebook>
|
||||
<field name="usage"/>
|
||||
<field name="type"/>
|
||||
</form>
|
||||
|
@ -1080,8 +1091,22 @@
|
|||
<field name="res_model">ir.actions.server</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="view_server_action_tree"/>
|
||||
<field name="context">{'key':'myval'}</field>
|
||||
</record>
|
||||
<menuitem action="action_server_action" id="menu_server_action" parent="base.next_id_6"/>
|
||||
|
||||
|
||||
<record id="view_model_fields_tree" model="ir.ui.view">
|
||||
<field name="name">ir.model.fields.tree</field>
|
||||
<field name="model">ir.model.fields</field>
|
||||
<field name="type">tree</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Fields">
|
||||
<field name="complete_name"/>
|
||||
<field name="model_id"/>
|
||||
<field name="name"/>
|
||||
<field name="field_description"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</terp>
|
||||
|
|
|
@ -255,10 +255,6 @@ class act_url(osv.osv):
|
|||
}
|
||||
act_url()
|
||||
|
||||
def _get_fields(self, cr, uid, context={}):
|
||||
|
||||
return [('key','Email Value')]
|
||||
|
||||
def model_get(self, cr, uid, context={}):
|
||||
wkf_pool = self.pool.get('workflow')
|
||||
ids = wkf_pool.search(cr, uid, [])
|
||||
|
@ -273,7 +269,62 @@ def model_get(self, cr, uid, context={}):
|
|||
res.append((model, name))
|
||||
|
||||
return res
|
||||
|
||||
|
||||
class ir_model_fields(osv.osv):
|
||||
_inherit = 'ir.model.fields'
|
||||
_rec_name = 'complete_name'
|
||||
_columns = {
|
||||
'complete_name': fields.char('Complete Name', required=True, size=64, select=1),
|
||||
}
|
||||
|
||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
|
||||
|
||||
print name, args, operator, context
|
||||
|
||||
def get_fields(cr, uid, field, rel):
|
||||
result = []
|
||||
mobj = self.pool.get('ir.model')
|
||||
id = mobj.search(cr, uid, [('model','=',rel)])
|
||||
|
||||
obj = self.pool.get('ir.model.fields')
|
||||
ids = obj.search(cr, uid, [('model_id','in',id)])
|
||||
records = obj.read(cr, uid, ids)
|
||||
for record in records:
|
||||
id = record['id']
|
||||
fld = field + '/' + record['name']
|
||||
|
||||
result.append((id, fld))
|
||||
return result
|
||||
|
||||
if not args:
|
||||
args=[]
|
||||
if not context:
|
||||
context={}
|
||||
return super(ir_model_fields, self).name_search(cr, uid, name, args, operator, context, limit)
|
||||
|
||||
result = []
|
||||
obj = self.pool.get('ir.model.fields')
|
||||
ids = obj.search(cr, uid, args)
|
||||
records = obj.read(cr, uid, ids)
|
||||
for record in records:
|
||||
id = record['id']
|
||||
field = record['name']
|
||||
|
||||
if record['ttype'] == 'many2one':
|
||||
rel = record['relation']
|
||||
res = get_fields(cr, uid, field, record['relation'])
|
||||
for rs in res:
|
||||
result.append(rs)
|
||||
|
||||
result.append((id, field))
|
||||
|
||||
for rs in result:
|
||||
obj.write(cr, uid, [rs[0]], {'complete_name':rs[1]})
|
||||
|
||||
#result = super(ir_model_fields, self).name_search(cr, uid, name, [['complete_name','ilike',name]], operator, context, limit)
|
||||
return result
|
||||
|
||||
ir_model_fields()
|
||||
#
|
||||
# Actions that are run on the server side
|
||||
#
|
||||
|
@ -302,7 +353,8 @@ class actions_server(osv.osv):
|
|||
#'trigger_object': fields.char('Trigger Object', size=128),
|
||||
#'trigger_object_id': fields.char('Trigger Object ID', size=128),
|
||||
'message': fields.text('Message', translate=True),
|
||||
'address': fields.selection(_get_fields ,'Email / SMS', size=128),
|
||||
'address': fields.many2one('ir.model.fields', 'Email From / SMS'),
|
||||
#selection(_get_fields ,'Email / SMS', size=128),
|
||||
'child_ids': fields.one2many('ir.actions.actions', 'parent_id', 'Others Actions'),
|
||||
'usage': fields.char('Action Usage', size=32),
|
||||
'type': fields.char('Report Type', size=32, required=True),
|
||||
|
@ -322,6 +374,11 @@ class actions_server(osv.osv):
|
|||
"""
|
||||
}
|
||||
|
||||
# def on_change_model(self, cr, uid, ids, model_id):
|
||||
# print '**************** : method called'
|
||||
# res = {'value' : {'address': [('key1','Email Value One')]} }
|
||||
# return res
|
||||
|
||||
#
|
||||
# Context should contains:
|
||||
# ids : original ids
|
||||
|
@ -344,9 +401,14 @@ class actions_server(osv.osv):
|
|||
exec action.code in localdict
|
||||
if 'action' in localdict:
|
||||
return localdict['action']
|
||||
|
||||
if action.state == 'email':
|
||||
user = config['email_from']
|
||||
subject = action.name
|
||||
|
||||
#TODO : Apply Mail merge in to the Content of the Email
|
||||
print '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ',context
|
||||
|
||||
body = action.message
|
||||
if tools.email_send_attach(user, action.address, subject, body, debug=False) == True:
|
||||
logger.notifyChannel('email', netsvc.LOG_INFO, 'Email successfully send to : %s' % (action.address))
|
||||
|
@ -361,10 +423,12 @@ class actions_server(osv.osv):
|
|||
wf_service.trg_validate(uid, model, int(id), action.trigger_name, cr)
|
||||
|
||||
if action.state == 'sms':
|
||||
#TODO: Apply mearge with the field
|
||||
if tools.sms_send(user, password, api_id, text, to) == True:
|
||||
logger.notifyChannel('sms', netsvc.LOG_INFO, 'SMS successfully send to : %s' % (action.address))
|
||||
else:
|
||||
logger.notifyChannel('sms', netsvc.LOG_ERROR, 'Failed to send SMS to : %s' % (action.address))
|
||||
|
||||
if action.state == 'other':
|
||||
localdict = {
|
||||
'self': self.pool.get(action.model_id.model),
|
||||
|
@ -376,15 +440,10 @@ class actions_server(osv.osv):
|
|||
}
|
||||
|
||||
for act in action.child_ids:
|
||||
code = """
|
||||
action = {
|
||||
'res_model': %s,
|
||||
'type': %s,
|
||||
'name': %s,
|
||||
'usage': %s,
|
||||
}
|
||||
""" % (action.model_id.model, act.type, act.name, act.usage)
|
||||
exec action.code in localdict
|
||||
code = """action = {'model':'%s','type':'%s', %s}""" % (action.model_id.model, act.type, act.usage)
|
||||
exec code in localdict
|
||||
if 'action' in localdict:
|
||||
return localdict['action']
|
||||
|
||||
return False
|
||||
actions_server()
|
||||
|
|
Loading…
Reference in New Issue