* change content type in to the email send method

* Implement the mail marge method 
* change in to the view to have tiny_mce editor in e-tiny

bzr revid: mga@tinyerp.com-20080821103617-wrct24u6imwv9cnb
This commit is contained in:
mga@tinyerp.com 2008-08-21 16:06:17 +05:30
parent 92e1cd64c4
commit c1d400209f
3 changed files with 43 additions and 10 deletions

View File

@ -1055,12 +1055,12 @@
<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"/>
<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="Other Actions" attrs="{'invisible':[('state','!=','other')]}">

View File

@ -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'
@ -377,19 +378,51 @@ class actions_server(osv.osv):
"""
}
def get_address(self, cr, uid, 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 = action.address.complete_name.split('/')
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:
obj = getattr(obj, field)
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):
return action.message
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:
@ -418,8 +451,8 @@ class actions_server(osv.osv):
user = config['email_from']
subject = action.name
address = self.get_address(cr, uid, action)
body = self.merge_message(cr, uid, action)
address = self.get_field_value(cr, uid, action, context)
body = self.merge_message(cr, uid, action, context)
#TODO : Apply Mail merge in to the Content of the Email
if tools.email_send_attach(user, address, subject, body, debug=False) == True:

View File

@ -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 )