Implement Create / Write Object
* implement view, object * process the normal values bzr revid: mga@tinyerp.com-20080825121946-gojfoe093cr7xjdg
This commit is contained in:
commit
ab64629077
|
@ -1055,12 +1055,29 @@
|
|||
<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')]}">
|
||||
<page string="Email / SMS" 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"/>
|
||||
<field name="message" select="2" colspan="4" widget="html_tag"/>
|
||||
<newline/>
|
||||
<label colspan="4" string="Use o to access the current object, you can use the any attributes which is belongs to current selected obect with o, i.e. o.partner_id.name for Invoice Object"/>
|
||||
<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"/>
|
||||
</page>
|
||||
|
||||
<page string="Create / Write" attrs="{'invisible':[('state','=','python'),('state','=','dummy'),('state','=','trigger'), ('state','=','sms'), ('state','=','email'), ('state','=','client_action'), ('state','=','other')]}">
|
||||
<separator colspan="4" string="Fields Mapping"/>
|
||||
<field name="srcmodel_id" select="2"/>
|
||||
<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)]"/>
|
||||
<field name="type"/>
|
||||
<field name="value"/>
|
||||
</tree>
|
||||
<form string="Field Mapping">
|
||||
<field name="col1" domain="[('model_id','=',parent.srcmodel_id)]"/>
|
||||
<field name="type"/>
|
||||
<field name="value" colapsn="4"/>
|
||||
</form>
|
||||
</field>
|
||||
</page>
|
||||
|
||||
<page string="Other Actions" attrs="{'invisible':[('state','!=','other')]}">
|
||||
|
|
|
@ -33,6 +33,7 @@ import tools
|
|||
import time
|
||||
from tools.config import config
|
||||
import netsvc
|
||||
import re
|
||||
|
||||
class actions(osv.osv):
|
||||
_name = 'ir.actions.actions'
|
||||
|
@ -278,6 +279,7 @@ class ir_model_fields(osv.osv):
|
|||
}
|
||||
|
||||
def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=80):
|
||||
|
||||
def get_fields(cr, uid, field, rel):
|
||||
result = []
|
||||
mobj = self.pool.get('ir.model')
|
||||
|
@ -331,6 +333,23 @@ class ir_model_fields(osv.osv):
|
|||
|
||||
ir_model_fields()
|
||||
|
||||
class server_object_lines(osv.osv):
|
||||
_name = 'ir.server.object.lines'
|
||||
_sequence = 'ir_actions_id_seq'
|
||||
_columns = {
|
||||
'server_id': fields.many2one('ir.actions.server', 'Object Mapping'),
|
||||
'col1': fields.many2one('ir.model.fields', 'Destination', required=True),
|
||||
'value': fields.text('Value', required=True),
|
||||
'type': fields.selection([
|
||||
('value','Value'),
|
||||
('equation','Formula')
|
||||
], 'Type', required=True, size=32, change_default=True),
|
||||
}
|
||||
_defaults = {
|
||||
'type': lambda *a: 'equation',
|
||||
}
|
||||
server_object_lines()
|
||||
|
||||
##
|
||||
# Actions that are run on the server side
|
||||
#
|
||||
|
@ -356,14 +375,13 @@ class actions_server(osv.osv):
|
|||
'model_id': fields.many2one('ir.model', 'Object', required=True),
|
||||
'trigger_name': fields.char('Trigger Name', size=128),
|
||||
'trigger_obj_id': fields.reference('Trigger On', selection=model_get, size=128),
|
||||
#'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.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),
|
||||
'srcmodel_id': fields.many2one('ir.model', 'Model', required=True),
|
||||
'fields_lines': fields.one2many('ir.server.object.lines', 'server_id', 'Fields Mapping'),
|
||||
}
|
||||
_defaults = {
|
||||
'state': lambda *a: 'dummy',
|
||||
|
@ -379,7 +397,53 @@ class actions_server(osv.osv):
|
|||
# If you plan to return an action, assign: action = {...}
|
||||
"""
|
||||
}
|
||||
|
||||
def get_field_value(self, cr, uid, action, context):
|
||||
obj_pool = self.pool.get(action.model_id.model)
|
||||
id = context.get('active_id')
|
||||
obj = obj_pool.browse(cr, uid, id)
|
||||
|
||||
fields = None
|
||||
|
||||
if '/' in action.address.complete_name:
|
||||
fields = action.address.complete_name.split('/')
|
||||
elif '.' in action.address.complete_name:
|
||||
fields = action.address.complete_name.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 obj
|
||||
|
||||
def merge_message(self, cr, uid, 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)
|
||||
|
||||
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('\[\[(.+?)\]\]')
|
||||
message = com.sub(merge, str(action.message))
|
||||
return message
|
||||
|
||||
#
|
||||
# Context should contains:
|
||||
# ids : original ids
|
||||
|
@ -407,18 +471,8 @@ class actions_server(osv.osv):
|
|||
user = config['email_from']
|
||||
subject = action.name
|
||||
|
||||
obj_pool = self.pool.get(action.model_id.model)
|
||||
id = context.get('active_id')
|
||||
obj = obj_pool.browse(cr, uid, id)
|
||||
|
||||
fields = action.address.complete_name.split('/')
|
||||
for field in fields:
|
||||
obj = getattr(obj, field)
|
||||
|
||||
address = obj
|
||||
|
||||
body = action.message
|
||||
#TODO : Apply Mail merge in to the Content of the Email
|
||||
address = self.get_field_value(cr, uid, action, context)
|
||||
body = self.merge_message(cr, uid, 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))
|
||||
|
|
|
@ -80,7 +80,7 @@ class view(osv.osv):
|
|||
(_check_xml, 'Invalid XML for View Architecture!', ['arch'])
|
||||
]
|
||||
|
||||
def read(self,cr, uid, ids, fields=None, context={}, load='_classic_read'):
|
||||
def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'):
|
||||
|
||||
if not isinstance(ids, (list, tuple)):
|
||||
ids = [ids]
|
||||
|
@ -94,6 +94,7 @@ class view(osv.osv):
|
|||
if oview:
|
||||
rs['arch'] = oview[0]['arch']
|
||||
|
||||
|
||||
return result
|
||||
|
||||
def write(self, cr, uid, ids, vals, context={}):
|
||||
|
@ -107,7 +108,7 @@ class view(osv.osv):
|
|||
vals2 = {'user_id': uid, 'ref_id': ids[0], 'arch': vals.pop('arch')}
|
||||
|
||||
# write fields except arch to the `ir.ui.view`
|
||||
result = super(view, self).write(cr, uid, vids, vals, context)
|
||||
result = super(view, self).write(cr, uid, ids, vals, context)
|
||||
|
||||
if not vids:
|
||||
self.pool.get('ir.ui.view.custom').create(cr, uid, vals2)
|
||||
|
|
|
@ -394,7 +394,7 @@ def email_send_attach(email_from, email_to, subject, body, email_cc=None, email_
|
|||
if tinycrm:
|
||||
msg['Message-Id'] = '<'+str(time.time())+'-tinycrm-'+str(tinycrm)+'@'+socket.gethostname()+'>'
|
||||
msg['Date'] = formatdate(localtime=True)
|
||||
msg.attach( MIMEText(body or '', _charset='utf-8') )
|
||||
msg.attach( MIMEText(body or '', _charset='utf-8', _subtype="html"))
|
||||
for (fname,fcontent) in attach:
|
||||
part = MIMEBase('application', "octet-stream")
|
||||
part.set_payload( fcontent )
|
||||
|
|
Loading…
Reference in New Issue